SNMP MIBs Extentions and how to use it in Linux


Pinoy Techie
Hello Everyone. today we are going to blabber for a short time about SNMP.

I don't now if any one are familiar with snmp configuration directives, but what is very interesting for me at least is the extend directive, and one of the most interesting thing about that directive is that you can define your own script to be executed and assign the output to your variable name in nsExtendOutput which we can use later on to create more convenient graphs using MRTG or RRD related to our needs :) . So lets start

1. Create a script to get Packet sent/recieve and both per second from one interface such as eth0 every five minutes:

stats=$(sar -n DEV -s $(date --date='5 mins ago' +%T) | grep eth0 | tail -n2 |head -n1)

case $1 in
received ) echo $stats | awk '{ print $6 }'

echo $stats | awk '{ print $7 }'

echo $stats | awk '{ print $6 + $7 }'


2. Save it any where and make it executable . then lets go to update snmp.conf a little by add the following :

extend networktraffic /etc/snmp/ both
extend networktrafficrcvd /etc/snmp/ received
extend networktrafficsent /etc/snmp/ sent

3. now lets do snmpwalk and check the output by executing below command if you are

using snmp v3
snmpwalk -v3 -u testuser2 -l authNoPriv -a MD5 -A "pass" localhost .1|grep networktraffic
or by excuting below command if you'r configuration is :
snmpwalk -v 2c -c public localhost .1|grep networktraffic

and the output will look something like this: note the ones which is marked as bold

HOST-RESOURCES-MIB::hrSWRunParameters.12938 = STRING: "networktraffic" NET-SNMP-EXTEND-MIB::nsExtendCommand."networktraffic" = STRING: /etc/snmp/ NET-SNMP-EXTEND-MIB::nsExtendCommand."networktrafficrcvd" = STRING: /etc/snmp// NET-SNMP-EXTEND-MIB::nsExtendCommand."networktrafficsent" = STRING: /etc/snmp// NET-SNMP-EXTEND-MIB::nsExtendArgs."networktraffic" = STRING: both NET-SNMP-EXTEND-MIB::nsExtendArgs."networktrafficrcvd" = STRING: received NET-SNMP-EXTEND-MIB::nsExtendArgs."networktrafficsent" = STRING: sent NET-SNMP-EXTEND-MIB::nsExtendInput."networktraffic" = STRING: NET-SNMP-EXTEND-MIB::nsExtendInput."networktrafficrcvd" = STRING: NET-SNMP-EXTEND-MIB::nsExtendInput."networktrafficsent" = STRING: NET-SNMP-EXTEND-MIB::nsExtendCacheTime."networktraffic" = INTEGER: 5 NET-SNMP-EXTEND-MIB::nsExtendCacheTime."networktrafficrcvd" = INTEGER: 5 NET-SNMP-EXTEND-MIB::nsExtendCacheTime."networktrafficsent" = INTEGER: 5 NET-SNMP-EXTEND-MIB::nsExtendExecType."networktraffic" = INTEGER: exec(1) NET-SNMP-EXTEND-MIB::nsExtendExecType."networktrafficrcvd" = INTEGER: exec(1) NET-SNMP-EXTEND-MIB::nsExtendExecType."networktrafficsent" = INTEGER: exec(1) NET-SNMP-EXTEND-MIB::nsExtendRunType."networktraffic" = INTEGER: run-on-read(1) NET-SNMP-EXTEND-MIB::nsExtendRunType."networktrafficrcvd" = INTEGER: run-on-read(1) NET-SNMP-EXTEND-MIB::nsExtendRunType."networktrafficsent" = INTEGER: run-on-read(1) NET-SNMP-EXTEND-MIB::nsExtendStorage."networktraffic" = INTEGER: permanent(4) NET-SNMP-EXTEND-MIB::nsExtendStorage."networktrafficrcvd" = INTEGER: permanent(4) NET-SNMP-EXTEND-MIB::nsExtendStorage."networktrafficsent" = INTEGER: permanent(4) NET-SNMP-EXTEND-MIB::nsExtendStatus."networktraffic" = INTEGER: active(1) NET-SNMP-EXTEND-MIB::nsExtendStatus."networktrafficrcvd" = INTEGER: active(1) NET-SNMP-EXTEND-MIB::nsExtendStatus."networktrafficsent" = INTEGER: active(1) NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."networktraffic" = STRING: 12145.6 NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."networktrafficrcvd" = STRING: 6309.75 NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."networktrafficsent" = STRING: 5835.86 NET-SNMP-EXTEND-MIB::nsExtendOutputFull."networktraffic" = STRING: 12145.6 NET-SNMP-EXTEND-MIB::nsExtendOutputFull."networktrafficrcvd" = STRING: 6309.75 NET-SNMP-EXTEND-MIB::nsExtendOutputFull."networktrafficsent" = STRING: 5835.86 NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."networktraffic" = INTEGER: 1 NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."networktrafficrcvd" = INTEGER: 1 NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."networktrafficsent" = INTEGER: 1 NET-SNMP-EXTEND-MIB::nsExtendResult."networktraffic" = INTEGER: 0 NET-SNMP-EXTEND-MIB::nsExtendResult."networktrafficrcvd" = INTEGER: 0 NET-SNMP-EXTEND-MIB::nsExtendResult."networktrafficsent" = INTEGER: 0 NET-SNMP-EXTEND-MIB::nsExtendOutLine."networktraffic".1 = STRING: 12145.6 NET-SNMP-EXTEND-MIB::nsExtendOutLine."networktrafficrcvd".1 = STRING: 6309.75 NET-SNMP-EXTEND-MIB::nsExtendOutLine."networktrafficsent".1 = STRING: 5835.86
Top Bottom