#!/bin/bash # script that polls values from the apc ems # var warnstatus=0 critstatus=0 getval () { oid=$1 /usr/bin/snmpget -c public -v 1 -O v $host -m /usr/share/snmp/mibs/powernet361.mib "$oid" | sed "s/.*INTEGER: \(.*\)$/\1/g" } temps () { sensor=$1 temp=`getval PowerNet-MIB::emsProbeStatusProbeTemperature."$sensor"` hum=`getval PowerNet-MIB::emsProbeStatusProbeHumidity."$sensor"` envn=`echo "$OPTARG" | sed "s/\([a-zA-Z0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\)/\1/g"` templ=`echo "$OPTARG" | sed "s/\([a-zA-Z0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\)/\2/g"` temph=`echo "$OPTARG" | sed "s/\([a-zA-Z0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\)/\3/g"` huml=`echo "$OPTARG" | sed "s/\([a-zA-Z0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\)/\4/g"` humh=`echo "$OPTARG" | sed "s/\([a-zA-Z0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\)/\5/g"` tempL=$((templ-5)) tempH=$((temph+5)) humL=$((huml-5)) humH=$((humh+10)) # check values if [ "$temph" -lt "$templ" ] || [ "$humh" -lt "$huml" ] || [ -z "$envn" ] ; then echo "please check your options!" exit 3 fi # do testing if [ "$temp" -gt "$templ" ] && [ "$temp" -lt "$temph" ] && [ "$hum" -gt "$huml" ] && [ "$hum" -lt "$humh" ] ; then okstatus=0 okenv="$okenv $envn $temp"C" $hum"pctH, elif [ "$temp" -gt "$tempL" ] || [ "$temp" -lt "$tempH" ] || [ "$hum" -gt "$humL" ] || [ "$hum" -lt "$humH" ] ; then warnenv="$warnenv $envn $temp"C" $hum"pctH, warnstatus=1 else critenv="$critenv $envn $temp"C" $hum"pctH, critstatus=2 fi } # get other sensors getsens () { sensor=$1 typ=$2 sens=`getval PowerNet-MIB::emsSensorStatusSensorState."$sensor"` if [ "$sens" = 'sensorOKEMS(2)' ] ; then okstatus=0 okenv="$okenv no $typ", elif [ "$sens" = 'sensorNotInstalledEMS(3)' ] ; then warnstatus=1 warnenv="$warnenv $typ Sensor NotInstalled" else critstatus=2 critenv="$critenv $typ Alarm" fi } # get ops while getopts ":z:slva:b:c:d:e:f:g:h:i:j:" opt; do case $opt in z) host="$OPTARG" ;; s) getsens 5 Smoke ;; l) getsens 6 Water ;; v) getsens 3 Quake ;; a) temps 1 ;; b) temps 2 ;; c) temps 3 ;; d) temps 4 ;; e) temps 5 ;; f) temps 6 ;; g) temps 7 ;; h) temps 8 ;; i) temps 9 ;; j) temps 10 ;; \?) echo 'usage -z host -s (check smoke) -l (check leakage) -v (check vibration) -[a-j],lowwarntemp,highwarntemp,lowwarnhum,highwarnhum (Critical is 5 low or higher then warning)' ;; esac done shift $(($OPTIND -1)) # give some help if [ -z "$host" ] ; then echo 'usage -z host -s (check smoke) -l (check leakage) -v (check vibration) -[a-j],lowwarntemp,highwarntemp,lowwarnhum,highwarnhum (Critical is 5 low or higher then warning)' fi # compile results of tests if [ "$critstatus" != 0 ] ; then echo "$critenv | $critenv $warnenv $okenv" exit 2 fi if [ "$warnstatus" != 0 ] ; then echo "$warnenv | $warnenv $okenv" exit 1 fi if [ "$critstatus" == 0 ] && [ "$warnstatus" == 0 ] && [ "$okstatus" == 0 ] ; then echo "$okenv | $okenv" exit 0 fi echo "Error checking device" exit 3