# This script written with haste by Benjamin Rose, July 8th 2009 @ 11:45:42 AM # It was written because the check_snmp plugin provided by the nagios package does not # support range matching. It can check if the snmp value is greater than a given number # but not less than, nor a range consisting of either a high value or a low value. # Hence, this script, given a mode of 1 and a good range with which to work, will report # back appropriately. # # Modes: # 1 = Number comparison, reports on a given range. Argument order given in the usage statement. # 2 = String comparison, which for now is just "Open" or otherwise. This is probably IAS specific. # # TODO: 1) Change the order of the arguments, putting mode in front of the variables, and then # change the usage based on the given mode. # 2) Allow the user to configure which strings are "good" and which are "bad". #!/bin/sh . /usr/lib64/nagios/plugins/utils.sh if [ $# -ne 8 ]; then echo "Usage: ./check_snmp_wrapper community_string hostname mib low_critical_range low_warning_range high_warning_range high_critical_range mode"; exit ${STATE_UNKNOWN}; fi if [ $8 -eq 1 ]; then VALUE=`snmpget -v1 -c $1 $2 $3 | awk '{print $4}'` if [ "${VALUE}" == "" ]; then echo "NO RESPONSE!"; exit ${STATE_UNKNOWN}; elif [ ${VALUE} -lt $4 -o ${VALUE} -gt $7 ]; then echo "CRITICAL: ${VALUE}"; exit ${STATE_CRITICAL} elif [ ${VALUE} -lt $5 -o ${VALUE} -gt $6 ]; then echo "WARNING: ${VALUE}"; exit ${STATE_WARNING}; fi elif [ $8 -eq 2 ]; then VALUE=`snmpget -v1 -c $1 $2 $3 | awk '{print $4}' | sed s/\"// | sed s/\"//` if [ "${VALUE}" == "" ]; then echo "NO RESPONSE!"; exit ${STATE_UNKNOWN}; elif [ "${VALUE}" == "Open" ]; then echo "OK: ${VALUE}"; exit ${STATE_OK}; else echo "CRITICAL: Sensor ${VALUE}"; exit ${STATE_CRITICAL}; fi else echo "mode should be 1 for number comparison, 2 for open/close comparison."; exit ${STATE_UNKNOWN}; fi echo "OK: ${VALUE}"; exit ${STATE_OK};