Guest User

Nagios Check: Multiple HTTP port check

a guest
Mar 21st, 2012
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.89 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ### Start
  4. iPorts=$1
  5. cTimeout=$2
  6.  
  7. if [ $# != 2 ]; then
  8.   echo "Usage: $0 ports timeout"
  9.   exit 1
  10. fi
  11.  
  12. wget=$(which wget)
  13.  
  14. cCheckName="Merb Ports"
  15. tMessage="Fail ports: "
  16. countFails=0
  17. exitStatus=0
  18.  
  19. if [ -x /usr/share/boo-box/plugins/utils.sh ]; then
  20.   . /usr/share/boo-box/plugins/utils.sh
  21. fi
  22.  
  23. for port in $(seq 0 $iPorts)
  24.   do
  25.     port=$((4000 + $port))
  26.     $wget -q -T $cTimeout --tries=2 http://localhost:$port -O /dev/null
  27.     if [ $? != 0 ]; then
  28.       countFails=$((countFails + 1))
  29.       tMessage="${tMessage}$port "
  30.     fi
  31.   done
  32.  
  33. if [ $countFails -eq 0 ]; then
  34.   tMessage="Everything OK"
  35. elif [ $countFails -le 1 ]; then
  36.   tMessage="OK ${tMessage}"
  37. elif [ $countFails -gt 1 ] || [ $countFails -le 5 ]; then
  38.   exitStatus=1
  39. elif [ $countFails -gt 5 ]; then
  40.   exitStatus=2
  41. fi
  42.  
  43.  
  44. alert_nagios "$cCheckName" "$exitStatus" "$tMessage"
  45.  
  46. exit 0
  47. ### End
Advertisement
Add Comment
Please, Sign In to add comment