C.3. Net-SNMP Command-Line Tools
This section
C.3.1.
|
|
Abbreviation |
Type |
|---|---|
a |
IP address |
b |
Bits |
d |
Decimal string |
d |
Double |
F |
Float |
i |
Integer |
i |
Signed int64 |
o |
Object ID |
s |
String |
t |
Time
|
u |
Unsigned integer |
u |
Unsigned int64 |
x |
Hexadecimal string |
To send a trap, use the snmptrap command. The syntax for this command is:
snmptrap options hostname trap parameters...
For Version 1, the following trap parameters are required:
enterprise-oid agent trap-type specific-type uptime objectID type value...
This command is discussed in detail in Chapter 9. Each object ID/type/value
The parameters are simpler for Version 2 traps, largely because traps (now called notifications ) are full-fledged MIB objects in their own right. The following parameters are required:
snmptrap -v2c options hostname uptime trapoid objectID type value...
The snmpdelta command
snmpdelta options hostname objectID...
snmpdelta requires you to specify the OID of an integer-valued scalar objectit can't monitor tables. For example, if you want to watch the octets arriving on an interface, you can't just specify
ifInOctets
; you must specify the interface number in addition to the object name (e.g.,
ifInOctets.3
). By default, snmpdelta
Table C-3 lists some of the snmpdelta-specific options. The documentation for this command has many problems, but if you stick to the options listed here you should be on firm ground.
|
Option |
Description |
|---|---|
|
-Cs |
Display a timestamp with every set of results. |
|
-Cm |
Print the maximum value obtained. |
|
-Cl |
Write the output to a file. The filename is in the form
hostname-OID
. For example, if you want to monitor the
|
|
-Cp |
Specify the polling interval (the default is one second). |
|
-CT |
Print output in tabular format. |
snmpdf works exactly like the Unix df command, except it uses SNMP to query
snmpdf [-Cu] options... hostname
The -Cu option
The snmpgetnext command uses the getnext operation to retrieve the
snmpgetnext options... hostname objectID...
There are no options specific to snmpgetnext.
The snmpstatus command retrieves status information from a host. It prints the following information:
The IP address of the entity
A textual description of the entity ( sysDescr.0 )
The uptime of the entity ( sysUpTime.0 )
The sum of received packets on all interfaces ( ifInUcastPkts.* + ifInNUcastPkts.* )
The sum of transmitted packets on all interfaces ( ifOutUcastPkts.* + ifOutNUcastPkts.* )
The number of IP input packets ( ipInReceives.0 )
The number of IP output packets ( ipOutRequests.0 )
The syntax of snmpstatus is straightforward, and there are no command-specific options:
snmpstatus options... hostname
The snmptable command uses getnext commands to print the contents of a table in tabular form. Its syntax is:
snmptable options... hostname objectID
The objectID must be the ID of a table (e.g., ifTable ), not of an object within a table. Table C-4 lists some of the snmptable-specific options.
|
Option |
Description |
|---|---|
|
-Cf F |
Separate table
|
|
-Cw W |
Set the maximum width of the table to
W
. If the lines are longer than
W
, the table is split into sections. Since tables can have many columns, you almost
|
|
-Ci |
Prepend the index of the entry to all printed lines. |
|
-Cb |
Display a brief heading. |
|
-Ch |
Print only column headers. |
|
-CH |
Suppress column headers. |
The snmpusm command provides simple access to the agent's USM table. This is primarily used for configuring the agent's SNMPv3 features (managing users, setting and changing passphrases, etc.). This command is discussed in Chapter 6.
This command is an interactive Perl script used to create and maintain the Net-SNMP configuration files, snmp.conf and snmpd.conf . Its syntax is:
snmpconf filename
filename must be either snmp.conf or snmpd.conf .
This command can be used to send an SNMPv2 trap. If you send a trap with snmpinform , it will wait for a response from the recipient. Note that you can send an
The Net-SNMP package comes with a handy tool called snmptranslate that
snmptranslate options objectID
snmptranslate does not perform queries against any device, so it doesn't need the hostname or community parameters. Its sole purpose is to read MIB files and produce output about specific objects. Before looking at examples, it's worth noting that snmptranslate's interpretations of the -O options are, to be kind, interesting. To speak more plainly, they're just plain wrong. The following examples show what actually happens when you use these optionswe'll leave the rationalization to you.
Let's say you want to know the enterprise OID for Cisco Systems. The following command does the trick:
$ snmptranslate -m ALL -IR -On cisco .1.3.6.1.4.1.9
This tells us that Cisco's enterprise OID is .1.3.6.1.4.1.9 . Note the use of the -IR option, which tells snmptranslate to do a random-access search for an object named cisco . If you leave this option out, snmptranslate will fail because it will try to locate cisco under the mib-2 tree.
Let's say you want to take .1.3.6.1.4.1.9 and convert it to its full symbolic name. That's easy:
$ snmptranslate -m ALL -Of .1.3.6.1.4.1.9 .iso.org.dod.internet.private.enterprises.cisco
In this case, -IR isn't needed because we're not performing a random-access search. -Of ensures that we print the full object ID, in symbolic (text) form.
Now, let's say you want to know a little more information about a particular object. The -Td option displays the object's definition as it appears in the MIB file:
$
snmptranslate -IR -Td system.sysLocation
SNMPv2-MIB::sysLocation
sysLocation OBJECT-TYPE
-- FROM SNMPv2-MIB, RFC1213-MIB
-- TEXTUAL CONVENTION DisplayString
SYNTAX OCTET STRING (0..255)
DISPLAY-HINT "255a"
MAX-ACCESS read-write
STATUS current
DESCRIPTION "The physical location of this node (e.g., 'telephone
closet, 3rd floor'). If the location is unknown, the
value is the zero-length string."
::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) system(1) 6 }
-Td can save you a lot of work poking through MIB files to find an appropriate definition, particularly when combined with -IR. Furthermore, the last line shows you the entire object ID in both numeric and string forms, not just the object's parent.
The -Tp option prints an entire OID tree. The best way to understand this is to see it:
$
snmptranslate -IR -Tp system
+--system(1)
+-- -R-- String sysDescr(1)
Textual Convention: DisplayString
Size: 0..255
+-- -R-- ObjID sysObjectID(2)
+-- -R-- TimeTicks sysUpTime(3)
+--sysUpTimeInstance(0)
+-- -RW- String sysContact(4)
Textual Convention: DisplayString
Size: 0..255
+-- -RW- String sysName(5)
Textual Convention: DisplayString
Size: 0..255
+-- -RW- String sysLocation(6)
Textual Convention: DisplayString
Size: 0..255
+-- -R-- INTEGER sysServices(7)
Range: 0..127
+-- -R-- TimeTicks sysORLastChange(8)
Textual Convention: TimeStamp
+--sysORTable(9)
+--sysOREntry(1)
Index: sysORIndex
+-- ---- INTEGER sysORIndex(1)
Range: 1..2147483647
+-- -R-- ObjID sysORID(2)
+-- -R-- String sysORDescr(3)
Textual Convention: DisplayString
Size: 0..255
+-- -R-- TimeTicks sysORUpTime(4)
Textual Convention: TimeStamp
We displayed the
system
subtree because it's