| Home Profile Fun |
#178 Linux 30.03.2009
Examples of SNMP requestsSNMP or simple network management protocol is used to monitor and controle network devices centrally. This article explains some examples of how to use SNMP. On Debian the package snmp contains the client commandline tools (e.g. snmpwalk) which are used to execute requests on devices (SNMP agents). The package snmpd is such an agent, a daemon which runs on devices which shall answer requests (client daemon, port 161/UDP). By using snmpwalk we communicate with the agent and get the desired information from it. In other words on all devices which should be monitored a snmpd must be running. The following examples show requests from the same host on which the snmpd is running (localhost). The community string is 'localro'. Because we use read-only requests the protocol version 2c is used here. This version is basically insecure because the community string is being transferred without encryption. For writing operations the version 3 should be used. Display all OIDs as text. snmptranslate -Of -Tp | less Display all OIDs as text and numeric. snmptranslate -Of -Tl | less Display all OIDs only numeric. snmptranslate -Of -To | less See man snmpcmd and man snmptranslate for parameter details. Request different tables. snmpwalk -v2c -c localro localhost interfaces snmpwalk -v2c -c localro localhost system snmpwalk -v2c -c localro localhost ipAddrTable Request a single value along with the corresponding MIB. snmpget -v2c -c localro localhost SNMPv2-MIB::sysORUpTime.1 The following value is the uptime of the snmpd and not the uptime of the host. snmpget -v2c -c localro localhost sysUpTime.0 For tables it is obvious that you have to put the index at the end (like .1, .2 ). Besides snmpgetnext also for scalar objects you have to use the index (.0) otherwise you will get an error message. snmpget -v2c -c localro localhost sysUpTime.0 sysLocation.0 snmpgetnext returns the content of the same COLUMN of the next row. This works also if the index is not continuous, like 1 3 5 6 and so on. snmpgetnext -v2c -c localro localhost sysLocation.0 Requests with a numeric OID. snmpwalk -v2c -c localro localhost .1.3.6.1.2.1.1.1 The result format of SNMP requests might be a little bit confusing. The reason is that per default the table content is not displayed row by row. Instead the result is presented as blocks of columns. Each line represents one element and has a column name and a row number (columnname.rownumber). You could also say the result is displayed column by column. If you want to examine only one row of the table you have to select all lines of the result output with the same index. For example column sysORID and sysORDescr of row 3: SNMPv2-MIB::sysORID.3 = OID: TCP-MIB::tcpMIB ... SNMPv2-MIB::sysORDescr.3 = STRING: The MIB module for managing TCP implementations But it is also possible to get the result row by row. snmptable -v2c -c localro -Os localhost sysORTable For very wide tables with lots of columns the following command prints the result in a suitable format. snmptable -v2c -c localro -Os -Cw 200 localhost sysORTable Print also the table index. snmptable -v2c -c localro -Os -Cw 200 -Ci localhost sysORTable Print a whole table. snmpwalk -v2c -c localro localhost system Print one column. snmpwalk -v2c -c localro localhost sysORID Print a scalar object. snmpwalk -v2c -c localro localhost sysDescr For faster and efficient requests you can use the commands snmpbulkget and snmpbulkwalk. snmpbulkget -v2c -Cn1 -Cr5 -Os -c localro localhost system ifTable snmpbulkwalk -v2c -Os -c localro localhost system The loaded MIBs can be found in these directories. $HOME/.snmp/mibs /usr/share/snmp/mibs/ Print the load average. snmpwalk -v2c -c localro localhost laload UCD-SNMP-MIB::laLoadFloat.1 = Opaque: Float: 0.000000 UCD-SNMP-MIB::laLoadFloat.2 = Opaque: Float: 0.010000 UCD-SNMP-MIB::laLoadFloat.3 = Opaque: Float: 0.000000 Print result with OIDs. snmpwalk -v2c -On -c localro localhost udp |