#!/bin/bash # # debupdates.sh # Nagios SNMP debian updates monitoring plugin. # # Created by CoolCold < coolcold@coolcold.org > on 2007-09-17. # # parameters: # # # example: ./debupdates.sh rainbow.local public # # ------------------------------------------------------------------- # Constants SNMP_GET="/usr/bin/snmpget" OID_FAIL=".1.3.6.1.4.1.2021.71.100.1" OID_MESG=".1.3.6.1.4.1.2021.71.101.1" NAGIOS_OK=0 NAGIOS_WARN=1 NAGIOS_CRIT=2 NAGIOS_UNKN=3 E_NOOID="Object" # ------------------------------------------------------------------- # default values infoline="OK" extcode="$NAGIOS_OK" errmsg="" # ------------------------------------------------------------------- # checking arguments... ARGS=2 E_BADARGS="$NAGIOS_UNKN" if [[ $# -lt "$ARGS" ]] then echo "usage: `basename $0` " echo "`basename $0` rainbow.local public" exit $E_BADARGS fi # ------------------------------------------------------------------- COMMUNITY=$2 HOST=$1 #if # SNMP query. STATUS_INFO=`$SNMP_GET -v2c -c $COMMUNITY -Ovq $HOST $OID_FAIL 2>&1` RETVAL_INFO="$?" STATUS_EXTD=`$SNMP_GET -v2c -c $COMMUNITY -Ovq $HOST $OID_MESG 2>&1` RETVAL_EXTD="$?" if [[ "$RETVAL_INFO" != "0" ]] then # Status SNMP query failed. infoline="UNKNOWN" errmsg="$STATUS_INFO" extcode="$NAGIOS_UNKN" echo "debian updates check on $HOST is $infoline: $errmsg" exit $extcode fi if [[ "$RETVAL_EXTD" != "0" || "x$STATUS_INFO" == "x1" ]] then # Extended status SNMP query failed. infoline="UNKNOWN" errmsg="$STATUS_EXTD" extcode="$NAGIOS_UNKN" echo "debian updates check on $HOST is $infoline: $errmsg" exit $extcode fi #echo "$STATUS_INFO and $STATUS_EXTD" UPDATES_STATUS=`echo $STATUS_EXTD|awk '{ print $3 }'` #echo "updates status: $UPDATES_STATUS" extcode=`echo $STATUS_EXTD|awk '{ print $1 }'|sed 's/"//'` #echo "exit code:" #echo `echo $STATUS_EXTD|awk '{print $1}'|sed 's/"//'` # Check if we got 'No Such Instance currently exists at this OID'. if [[ "$UPDATES_STATUS" = "$E_NOOID" ]] then infoline="UNKNOWN" errmsg="$STATUS_EXTD" extcode="$NAGIOS_UNKN" echo "debian updates check on $HOST is $infoline: $errmsg" exit $extcode fi #fi # If we have some updates, mark them as warning/critical # let's return what remote script provided... # Output and we're done. infoline=`echo $STATUS_EXTD|awk '{ORS=" "; for(i = 2 ; i <= NF ; i++) print $i}'|sed 's/"//'` #echo "$STATUS_EXTD" #infoline="$STATUS_EXTD" echo "debian updates check on $HOST is $infoline" exit $extcode