next up previous contents
Next: Polling Applications Up: The Net-SNMP CLI Previous: Polling Individual OIDs: SNMP   Contents

Net-SNMP CLI Tool Options

All the Net-SNMP tools use some similar arguments. A full list can be seen by calling the tool with no options. At a bare minimum, each command should be executed by supplying the version of SNMP that you wish to use (-v1, -v2c, or -v3), the community name of the target agent (-c community_name) and the IP or hostname of the target agent. All other arguments are optional.

Two of the most useful arguments include -m to specify a MIB to be used and -O to modify the output.

The -m argument can either be called with the proper name of the MIB (eg: "-m MY_MIB") when its located in the system MIB directory (typically /usr/local/share/snmp/mibs) or with the filename of the MIB including path (eg: "-m ./MY_MIB.txt").

I'll point out here something that you might have noticed already: the suffix for MIBs is typically .txt not .mib. I can't say why this is done but it is the accepted standard. Furthermore, usually the MIB name is in all caps and is referred without the suffix. Thus when you place MY_MIB.txt in the system MIB directory you will call that MIB as simply MY_MIB.

The -O argument can reorganize the output of a given Net-SNMP command in several different ways depending on how we want it displayed. You can see a list of different formating options in the help information for the individual tool. Lets just look at some examples:

$  snmpget -v1 -c public -m "./APC-POWERNET.txt" \
> 10.10.1.224 PowerNet-MIB::upsAdvInputLineVoltage.0
PowerNet-MIB::upsAdvInputLineVoltage.0 = Gauge32: 119

$  snmpget -v1 -c public -m "./APC-POWERNET.txt" -On \
> 10.10.1.224 PowerNet-MIB::upsAdvInputLineVoltage.0
.1.3.6.1.4.1.318.1.1.1.3.2.1.0 = Gauge32: 119

$  snmpget -v1 -c public -m "./APC-POWERNET.txt" -Ov \
> 10.10.1.224 PowerNet-MIB::upsAdvInputLineVoltage.0
Gauge32: 119

$  snmpget -v1 -c public -m "./APC-POWERNET.txt" -Oq \
> 10.10.1.224 PowerNet-MIB::upsAdvInputLineVoltage.0
PowerNet-MIB::upsAdvInputLineVoltage.0 118

$  snmpget -v1 -c public -m "./APC-POWERNET.txt" -Ovq \
> 10.10.1.224 PowerNet-MIB::upsAdvInputLineVoltage.0
118

Notice that the later two forms output is much nicer and easily parsed. It is not unusual for scripted applications to be implemented solely using the last output form, like this:

#!/usr/local/bin/perl

$SNMP_GET_CMD = "snmpget -v1 -c public -Ovq";
$SNMP_TARGET = "10.10.1.224";

my $voltage = `${SNMP_GET_CMD} ${SNMP_TARGET} .1.3.6.1.4.1.318.1.1.1.3.2.1.0`;
chomp($voltage);

print("${SNMP_TARGET} as an Input Line Reading of ${voltage}VAC\n");

When I run that script I get the following tidy output:

$ ./lineinput.pl 
10.10.1.224 as an Input Line Reading of 118VAC

This is the easiest way to write and prototype SNMP monitoring applications.


next up previous contents
Next: Polling Applications Up: The Net-SNMP CLI Previous: Polling Individual OIDs: SNMP   Contents
2004-11-23