Wednesday, June 19, 2013

Configuring snmp on debian server

Configuring Debian Server to respond to snmp query

#dpkg --list |grep snmp
ii  libnet-snmp-perl                     5.2.0-4                        Script SNMP connections
ii  libsnmp-base                         5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) MIBs and documentation
ii  libsnmp15                            5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) library
ii  snmp                                 5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) applications
ii  snmpd                                5.4.3~dfsg-2                   SNMP (Simple Network Management Protocol) agents

Setting public as community string.

rocommunity public
##       sec.name     source           community
##       ========     ======           =========
com2sec  local       localhost        craz33guy
com2sec  network_1   172.22.6.0/24    craz33guy
#com2sec  network_2   192.168.2.0/24   craz33guy

##       Access.group.name   sec.model        sec.name
##       =================  =========         ========
group    MyROGroup_1        v1                local
group    MyROGroup_1        v1                network_1
group    MyROGroup_2        v2c               network_2

##   MIB.view.name     incl/excl  MIB.subtree  mask
##   ==============   =========  ===========  ====
view all-mibs         included   .1           80

##      MIB
##      group.name   context sec.model sec.level prefix read     write  notif
##      ==========   ======= ========= ========= ====== ====     =====  =====
access  MyROGroup_1  ""       v1       noauth    exact  all-mibs none   none
access  MyROGroup_2  ""       v2c      noauth    exact  all-mibs none   none

############################################################################

Adding custom scripts to be monitored using SNMP

Sample check_keepalived Script
-------------------------------------
#!/bin/bash
count=`ps -ef |grep -c keepalived`
if [ $count -lt 4 ]; then
        echo "1"
else
        echo "0"
fi

------------------------------------



Copy the script to /bin/check_keepalived.sh
#chmod 777 /bin/check_keepalived.sh

Add the following line in snmpd.conf file
exec keepalive /bin/sh /bin/check_keepalived.sh

#service snmpd restart

Test if the script is executable using snmp and showing desired results 
From the SNMP server run this command. This will execute all the Snmp custom scripts and show the output.
snmpwalk -v2c -c craz33guy 172.21.6.64 NET-SNMP-EXTEND-MIB::nsExtendObjects

To execute a specific Script from the bunch of custom scripts.
snmpwalk -v2c -c craz33guy 172.21.6.64 1.3.6.1.4.1.8072.1.3.2.4.1

 More details on the custom OID are explained in the below link
http://www.oidview.com/mibs/8072/NET-SNMP-EXTEND-MIB.html 
http://www.net-snmp.org/wiki/index.php/Tut:Extending_snmpd_using_shell_scripts
 ===========================
rocommunity testcomm
##       sec.name     source           community
##       ========     ======           =========
com2sec  local       localhost          testcomm
com2sec  network_1   172.21.10.33/32    testcomm
#com2sec  network_1   10.0.0.207/32      testcomm

##       Access.group.name   sec.model        sec.name
##       =================  =========         ========
group    MyROGroup_1        v1                local
group    MyROGroup_2        v2c               network_1

##   MIB.view.name     incl/excl  MIB.subtree  mask
##   ==============   =========  ===========  ====
view all-mibs         included   .1           80

##      MIB
##      group.name   context sec.model sec.level prefix read     write  notif
##      ==========   ======= ========= ========= ====== ====     =====  =====
access  MyROGroup_1  ""       v1       noauth    exact  all-mibs none   none
access  MyROGroup_2  ""       v2c       noauth    exact  all-mibs none   none
=================================


No comments: