SNMPtoUnixCommandMapping

Webs: Faemalia -:- Greatprawn -:- Playground -:- Technical -:- Tweak
Technical Web Sections: Register -:- Users -:- Changes -:- Index -:- Search -:- Statistics

SNMP is Annoying...

I'm sure something like this exists out there on the vast interwebbe, but I couldn't find it. Suppose you have a Unix command you know how to run, and you want to know how to do that in SNMP. Here's something that'll get you started, at least.

Getting Information

The snmpwalk command is for getting information you can query. The following command prints out every MIB, which is Quite a Lot of Output:

snmpwalk -v 2c -c community -O fQ ipAddr

Common Unix-->SNMP Mappings

ps: snmpwalk -v 2c -c community -m UCD-SNMP-MIB -O fQ ipAddr .iso.org.dod.internet.mgmt.mib-2.25.4.2.1

load avg: snmpwalk -v 2c -c community -m UCD-SNMP-MIB -O fQ ipAddr laTable

hostname -s: snmpwalk -v 2c -c community -O fQ ipAddr .iso.org.dod.internet.mgmt.mib-2.system.sysName.0

ifconfig: snmpwalk -v 2c -c community -O fQ ipAddr .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable

route -n: snmpwalk -v 2c -c community -O fQ ipAddr .iso.org.dod.internet.mgmt.mib-2.ip.ipRouteTable

arp: snmpwalk -v 2c -c community -O fQ ipAddr .iso.org.dod.internet.mgmt.mib-2.ip.ipNetToMediaTable

uptime, date, kernel params, numUsers numProcesses: snmpwalk -v 2c -c community -O fQ ipAddr .iso.org.dod.internet.mgmt.mib-2.host.hrSystem

df: snmpwalk -v 2c -c community -O fQ ipAddr .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable

Perl Script

I created a Perl script that uses these concepts.

Here's an example of using it:

# unixToSnmp.pl --hostname=192.168.0.10 --command=df-m FixedDisk
                        /mnt/xtrad       FixedDisk  used/total: 44390.28/68091.77  pct: 65.19  
                                 /       FixedDisk  used/total: 34863.28/67999.65  pct: 51.27  
                             /boot       FixedDisk  used/total: 25.02/88.18  pct: 28.37  
    /var/www/samp.com/html/usrimgs       FixedDisk  used/total: 2398.67/68091.80  pct: 3.52  
     /var/www/samp.com/html/images       FixedDisk  used/total: 2398.66/68091.81  pct: 3.52  
# unixToSnmp.pl --hostname=192.168.0.10 --command=df-m 'Swap Space'
                        Swap Space   VirtualMemory  used/total: 1.19/1913.95  pct: 0.06  
# unixToSnmp.pl --hostname=192.168.0.10 --command=miscinfo             
hrSystemUptime.0 = 130:8:11:02.90
hrSystemDate.0 = 2005-12-17,21:19:56.0,-8:0
hrSystemInitialLoadDevice.0 = 2309
hrSystemInitialLoadParameters.0 = "root=/dev/hda1 ro console=tty0 "
hrSystemNumUsers.0 = 12
hrSystemProcesses.0 = 252
hrSystemMaxProcesses.0 = 0

How you might use the above script

Suppose you use Nagios, and you want to create an alert on SNMP information on a host. Here's a script that calls the above script.

And here's an example of using it (note that Nagios plugins return 0=OK, 1=WARNING, 2=CRITICAL (3=UNKNOWN?)).

# /usr/lib/nagios/plugins/nagiosCheckSNMP.pl --hostname=192.168.0.10 --command=df-m FixedDisk --threshold=45,55
CRITICAL: [crit: /mnt/xtrad at 65.23%] [warn: / at 51.27%]
# echo $?
2
# /usr/lib/nagios/plugins/nagiosCheckSNMP.pl --hostname=192.168.0.10 --command=df-m FixedDisk --threshold=45,75
WARNING: [warn: /mnt/xtrad at 65.29%] [warn: / at 51.27%]
# echo $?
1

Right now the only supported threshold is Disk Usage by Partition (which SNMP lumps together with Swap Space and physical RAM usage as well), but I think if you look at the source, you'll find it's pretty easy to add in things like total processes, load average, and such. Please feel free to add those things and email me back the updated script, and I'll put it here.


Edit -:- Attach -:- Ref-By -:- Printable -:- More