TUT:snmpget

From Net-SNMP Wiki
Revision as of 19:29, 23 January 2007 by Wes (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

snmpget

The snmpget command can be used to retrieve data from a remote host given its host name, authentication information and an OID. As a simple example:

 % snmpget -c demopublic -v 2c test.net-snmp.org system.sysUpTime.0
 system.sysUpTime.0 = Timeticks: (586731977) 67 days, 21:48:39.77


In the above example, test.net-snmp.org is the host name we wanted to talk to, using the SNMP community string demopublic and we requested the value of the OID system.sysUpTime.0. Earlier versions of the ucd-snmp utilities used SNMPv1 by default and expected the community name to follow the host name. The net-snmp versions of these tools now typically use SNMPv3 by default, and require both the version and the community string to be given as command line options (as illustrated in these examples). SNMPv2c, which is similar in nature to SNMPv1 with small modifications, still used clear-text community names as "passwords" to authenticate the issuer of the command. The result from a command using the SNMPv2c version would have been the same:

 % snmpget -v 2c -c demopublic test.net-snmp.org system.sysUpTime.0
 system.sysUpTime.0 = Timeticks: (586752671) 67 days, 21:52:06.71


All of the utilities allow abbreviation of the OIDs and do random searches by default, and hence you can only specify a small portion of the oid if you would prefer:

 % snmpget -v 2c -c demopublic test.net-snmp.org sysUpTime.0
 system.sysUpTime.0 = Timeticks: (586752671) 67 days, 21:52:06.71


A common mistake when using the snmpget command is to leave off the index into the data you're looking for. In the above commands, the variable requested by the OID is a scalar and the index to scalars is always a simple '0' (zero), hence the trailing '.0' in all the oids above. If you had left it off, you would have gotten an error. Note that the errrors differ slightly between SNMPv1 and SNMPv2c:

 % snmpget -v 1 -c demopublic test.net-snmp.org sysUpTime
 Error in packet
 Reason: (noSuchName) There is no such variable name in this MIB.
 This name doesn't exist: system.sysUpTime
 % snmpget -v 2c -c demopublic test.net-snmp.org sysUpTime
 system.sysUpTime = No Such Instance currently exists


Multiple variables can be retrieved in one transaction as well:

 % snmpget -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0
 system.sysUpTime.0 = Timeticks: (586903243) 67 days, 22:17:12.43
 enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser"