Hello Everyone today we will blabber for a short time about SNMP.
I don't now if any you are familiar with snmp configuration directives but what is very interesting for me at least is extend, and one of the most interesting thing about that directive that you can define your own script to be executed and assign the output to your variable name in nsExtendOutput1Line which we can use later on to create more convenient graphs using MRTG or RRD related to our needs :)
maybe my words sounded cryptic but let me show you how this thing is being done
lets create a script to get Packet sent/recieve and both per second from one interface such as eth0 every five minutes: below is the script
#!/bin/bash
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 } ';;
sent) echo $stats | awk ' { print $7 } ';;
both) echo $stats | awk ' { print $6 + $7 } ';;
esac
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/myscript.sh both
extend networktrafficrcvd /etc/snmp/myscript.sh received
extend networktrafficsent /etc/snmp/myscript.sh sent
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 by red
HOST-RESOURCES-MIB::hrSWRunParameters.12938 = STRING: "networktraffic"
NET-SNMP-EXTEND-MIB::nsExtendCommand."networktraffic" = STRING: /etc/snmp/myscript.sh
NET-SNMP-EXTEND-MIB::nsExtendCommand."networktrafficrcvd" = STRING: /etc/snmp//myscript.sh
NET-SNMP-EXTEND-MIB::nsExtendCommand."networktrafficsent" = STRING: /etc/snmp//myscript.sh
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
No comments:
Post a Comment