Guest User

Untitled

a guest
Apr 29th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #!/bin/bash
  2. APPNAME=$(basename $0)
  3.  
  4. ###############################
  5. # Check binaries before start #
  6. ###############################
  7.  
  8.  
  9. binaries=$(cat<<all_required_binaries
  10. snmpwalk
  11. all_required_binaries)
  12.  
  13. for required_binary in $binaries; do
  14. which $required_binary > /dev/null
  15. if [ "$?" != '0' ];then
  16. printf "UNKNOWN: $APPNAME: No usable '$required_binary' binary in '$PATH'\n"
  17. exit 3
  18. fi
  19. done
  20.  
  21.  
  22.  
  23. ######################
  24. # print Help Message #
  25. ######################
  26.  
  27. usage () {
  28.  
  29. cat<<EOU
  30.  
  31. Usage of $APPNAME
  32. ---------------------------------------------------------------------
  33.  
  34. Usable Options:
  35. -H fileserver
  36. The Hostname variable, set your hostname instead of fileserver
  37. (Required option)
  38.  
  39. -C public
  40. The SNMP Community variable, set your SNMP read community here
  41. (Required Option)
  42. -h
  43. This help message
  44.  
  45. Examples:
  46. $APPNAME -H fileserver -C public
  47.  
  48. ---------------------------------------------------------------------
  49.  
  50. EOU
  51. exit 3
  52. }
  53.  
  54.  
  55.  
  56. ################################
  57. # Get Options from commandline #
  58. ################################
  59.  
  60. while getopts "C:H:h" option
  61. do
  62. case $option in
  63. C ) COMMUNITY=$OPTARG ;;
  64. H ) HOST=$OPTARG ;;
  65. h ) usage ;;
  66. esac
  67. done
  68.  
  69.  
  70.  
  71. ###########################################
  72. # Exit Unknown if not all arguments given #
  73. ###########################################
  74.  
  75. if [ -z "$COMMUNITY" ] || [ -z "$HOST" ];then
  76. printf "UNKNOWN: No hostname and/or community set!"
  77. exit 3
  78. fi
  79.  
  80.  
  81.  
  82. ###########################
  83. # Main part of the script #
  84. ###########################
  85.  
  86. # Execute snmpwalk - Ouput is "FanNumer: Statuscode" #
  87. WALK=$(snmpwalk -v 2c -c $COMMUNITY $HOST .1.3.6.1.4.1.232.6.2.6.7.1.9 | cut -f4 -d ':')
  88. FANSTATUS=$(echo "$WALK" | grep -n [134])
  89.  
  90. if [ -z "$WALK" ];then
  91. printf "No proper SNMP response or SNMP timeout. Check host or community string\n"
  92. exit 3
  93. fi
  94.  
  95. # Get amount of failed fans #
  96. AMOUNT=$(echo "$FANSTATUS" | grep -o ' ' | wc -l)
  97.  
  98. # Exit OK if no fan failed
  99. if [ $AMOUNT -eq "0" ];then
  100. printf "OK: All Fans running"
  101. exit 0
  102.  
  103. # General failure if more than one fan failed
  104. elif [ "$AMOUNT" -gt "1" ];then
  105. printf "CRIT: $AMOUNT fans failed! Check HP Management Homepage"
  106. exit 2
  107. else
  108.  
  109. # Get failed fans index number
  110. NUMBER=$(echo $FANSTATUS | cut -f1 -d ':')
  111.  
  112. # Get Errorcode of failed fan
  113. CODE=$(echo $FANSTATUS | cut -f2 -d ':')
  114.  
  115. # Translate Errorcode
  116. # Error 1
  117. if [ $CODE = 2 ];then
  118. printf "UNKNOWN: 1 (Fan check not supported for this system)"
  119. exit 3
  120. fi
  121.  
  122. # Error 2
  123. if [ $CODE = 2 ];then
  124. DESCR="2 (Fan OK)"
  125. fi
  126.  
  127. # Error 3
  128. if [ $CODE = 3 ];then
  129. DESCR="3 (Fan degraded)"
  130. fi
  131.  
  132. # Error 4
  133. if [ $CODE = 4 ];then
  134. DESCR="4 (Fan failed)"
  135. fi
  136.  
  137. printf "WARN: Fan Number $NUMBER failed with status $DESCR"
  138. exit 1
  139. fi
Advertisement
Add Comment
Please, Sign In to add comment