Skip to content

Monitor SNMPD for all cacti host

This script will test SNMPD against all host in cacti database.

#!/bin/bash
# Powered by k2patel :)
# please send suggestion to [email protected]

#################################################
###                       ###
### MySQL Information used on Cacti           ###
#################################################
sqlu=<mysql_user>
sqlp=<mysql_pass>
sqld=<mysql_database>

#################################################
###                       ###
### List of person / group notified on faliur ###
#################################################

export receipients="[email protected] [email protected]"

#####################################################
###                                               ###
###  Folloving variable defines the skipped Host  ###
#####################################################

hstskip=(test.dummy.com test.dummy.net)


###################################################
###                     ###
### Variables Used in System            ###
###################################################

timeout=5
isskip=0

export prefix=/usr/lib64/nagios
export PATH=$PATH:/usr/lib64/nagios/plugins:/usr/local/bin:/bin


#$$$$$$$$$$$$$$$ END Of Customization  $$$$$$$$$$$$$$$$$$$$


notify(){
   for n in $receipients; do
      echo $1 | /bin/mail -s "[SNMPD] on $i Failed" $n
   done
}

for i in `mysql -N -u $sqlu -p$sqlp -e "select hostname from $sqld.host"`; do
    for k in ${hstskip[@]}; do
        if [ $i == $k ]; then
            isskip=1
        fi
    done
        if [ $isskip -eq 1 ]; then
            echo "Skipped $i"
            isskip=0
        else
            echo Running check_snmp -C public -H $i -P 2c -o system -t $timeout
            check_snmp -C public -H $i -P 2c -o system -t $timeout
            status=$?
            echo
            if [ $status -ne 0 ]; then
                notify "SNMPD failure, Please login to box and try to start SNMPD "
            else
                echo "Status OK"
            fi
        fi
done