/mili

Create Custom SNMP Tree With Bash

In some case you need to monitor your service, and SNMP is ROCKs in reporting.
But if you don’t like to read bunch of document about SNMP protocol and creating server flow this instructions.

snmpd helps you so much with pass config, it run your command when request comes for a exact MIB.
Just open /etc/snmpd.conf and add this line to end of config file :
pass .1.3.6.1.4.1.2021.256 /bin/sh /usr/local/snmp_script/snmp_asterisk

With this config when you request snmp walk on .1.3.6.1.4.1.2021.256 returns this result :
$ snmpwalk -v 1 pbx -c public .1.3.6.1.4.1.2021.256
UCD-SNMP-MIB::ucdavis.256.1 = Gauge32: 3
UCD-SNMP-MIB::ucdavis.256.2 = Gauge32: 10
UCD-SNMP-MIB::ucdavis.256.3 = Gauge32: 1
UCD-SNMP-MIB::ucdavis.256.4 = Gauge32: 3
UCD-SNMP-MIB::ucdavis.256.5 = Gauge32: 3

Yes ! I monitored my asterisk’s important status.
Now what’s line of that bash script ? you can locate passtest and create your file from that sample but I put my file for more sample !
#!/bin/sh -f
PATH=$path:/bin:/usr/bin:/usr/ucb:/usr/local/snmp_script/
PLACE=".1.3.6.1.4.1.2021.256"
REQ="$2"

if [ "$1" = "-s" ]; then
echo $* >> /tmp/passtest.log
exit 0
fi

if [ "$1" = "-n" ]; then
case "$REQ" in
$PLACE) RET=$PLACE.1 ;;
$PLACE.1) RET=$PLACE.2 ;;
$PLACE.2) RET=$PLACE.3 ;;
$PLACE.3) RET=$PLACE.4 ;;
$PLACE.4) RET=$PLACE.5 ;;
*) exit 0 ;;
esac
else
case "$REQ" in
$PLACE) exit 0 ;;
*) RET=$REQ ;;
esac
fi

echo "$RET"
case "$RET" in
$PLACE.1) echo "gauge"; echo `member_in_queue` ; exit 0 ;;
$PLACE.2) echo "gauge"; echo `number_of_answerd_call` ; exit 0 ;;
$PLACE.3) echo "gauge"; echo `number_of_missed_call`; exit 0 ;;
$PLACE.4) echo "gauge"; echo `rate_answerd_call` ;;
$PLACE.5) echo "gauge"; echo `rate_missed_call` ; exit 0 ;;
*) echo "string"; echo "ack... $RET $REQ"; exit 0 ;;
esac


You can use this MIBS in Monitoring System like Zenoss and …