Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 37 ยท Monitoring Concepts

SNMP Monitoring: OIDs, MIBs, Communities, Walks and Traps

Learn SNMP for network monitoring: versions v1, v2c and v3, OIDs and MIBs, snmpget and snmpwalk, counters and interface rates, traps, and how Zabbix and Nagios use SNMP.

Switches, routers, firewalls, printers, UPS units and storage arrays usually cannot run an agent. Almost all of them speak SNMP (Simple Network Management Protocol), which makes SNMP the most important agentless protocol in monitoring. Both Zabbix and Nagios use it. This lesson explains how SNMP data is organized and how to read it.

SNMP devices are not available on this site. The command examples are read-only and the TryIt blocks are Python stand-ins that parse OIDs and compute rates.

How SNMP works

A device runs an SNMP agent (UDP port 161) that exposes a tree of values. A manager (Zabbix, Nagios, or a command-line tool) sends requests:

  • GET reads one value by its OID.
  • GETNEXT / WALK reads a whole subtree, one entry after another.
  • GETBULK (v2c and v3) reads many entries per request, much faster than GETNEXT.
  • SET writes a value (rarely used in monitoring).
  • TRAP / INFORM: the device sends a message to the manager (UDP 162) when something happens.

Versions

Version Security Notes
v1 community string in clear text 32-bit counters only, legacy
v2c community string in clear text 64-bit counters, GETBULK, still very common
v3 usernames, authentication (SHA), encryption (AES) use it across untrusted networks

A community string is like a shared password: public (read) and private (write) are the dangerous defaults. Always change them, and limit by source IP on the device.

OIDs and MIBs

Every value has an OID (object identifier): a dotted number path through a global tree. Example:

1.3.6.1.2.1.1.5.0 is sysName.0, the device's name.

  • 1.3.6.1.2.1 = mib-2, the standard management tree.
  • .1 = system group; .5 = sysName; the trailing .0 marks a scalar (a single value).
  • 1.3.6.1.2.1.2.2.1 = ifTable, the interface table; .10 = ifInOctets; .16 = ifOutOctets. For a table the last number is the index (the interface number): ifInOctets.3 is 1.3.6.1.2.1.2.2.1.10.3.
  • 1.3.6.1.4.1 = enterprises; vendors have a number below it (Cisco 9, HP 11, Net-SNMP 8072).

A MIB (management information base) is a text file that maps names to numbers and describes types and meanings. With MIBs installed, tools show IF-MIB::ifInOctets.3; without them you see raw numbers. Numeric OIDs always work, and Zabbix item keys use them (1.3.6.1.2.1.1.5.0) or names resolved by the server's MIB database.

Useful standard OIDs:

OID Name Meaning
1.3.6.1.2.1.1.1.0 sysDescr Description of the device
1.3.6.1.2.1.1.3.0 sysUpTime Uptime in hundredths of a second
1.3.6.1.2.1.1.5.0 sysName Host name
1.3.6.1.2.1.2.2.1.8.N ifOperStatus 1=up, 2=down for interface N
1.3.6.1.2.1.31.1.1.1.6.N ifHCInOctets 64-bit inbound byte counter
1.3.6.1.2.1.31.1.1.1.10.N ifHCOutOctets 64-bit outbound byte counter

Command-line tools (Net-SNMP)

Terminal
snmpget  -v2c -c public 192.0.2.50 1.3.6.1.2.1.1.5.0
snmpwalk -v2c -c public 192.0.2.50 1.3.6.1.2.1.2.2.1.2     # ifDescr, all interfaces
snmpbulkwalk -v2c -c public 192.0.2.50 IF-MIB::ifXTable
snmpget -v3 -l authPriv -u monitor -a SHA -A 'authpass' -x AES -X 'privpass' 192.0.2.50 sysName.0

Add -On to force numeric OIDs. These commands are the first thing to run when a Zabbix SNMP item does not work: if snmpget from the Zabbix server fails, Zabbix will fail too (wrong community, firewall, ACL on the device).

Counters and rates

Interface byte counters are counters: they only increase (until they wrap around at 2^32 for 32-bit counters, or 2^64). A counter value itself is useless; you want the rate: (new - old) / seconds. Zabbix does this with the preprocessing step Change per second, which also handles wrap-around by discarding the odd sample. Multiply by 8 to convert bytes to bits for bps.

Python Stand-in: counter to bits per second

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last pair shows a 32-bit wrap: the counter dropped from near 2^32 to a small number. A 64-bit counter (ifHCInOctets) practically never wraps, which is why you should prefer the HC counters on fast links.

Parsing an OID

Python Stand-in: split a table OID

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

SNMP in Zabbix

An SNMP host needs an SNMP interface (IP, port 161, version, community or v3 credentials, "Use combined requests"). Items use type SNMP agent with a key such as sysUpTime and the SNMP OID field (1.3.6.1.2.1.1.3.0). Zabbix also supports SNMP walk[...] items (7.0) that fetch a subtree once, with dependent items extracting values, which greatly reduces load. Templates such as Network Generic Device by SNMP already do interface discovery: low-level discovery walks ifDescr and creates an item set per interface (see the discovery chapter). SNMP traps need snmptrapd and a script (zabbix_trap_receiver.pl) or the built-in SNMP trap handling via an item with key snmptrap[regex].

SNMP in Nagios

Nagios uses the plugin check_snmp:

Terminal
check_snmp -H 192.0.2.50 -C public -o 1.3.6.1.2.1.1.3.0 -w 0: -c 0: --rate

It prints the value and returns OK, WARNING or CRITICAL according to the thresholds. See Nagios objects and plugins for the threshold range format.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the trailing .N mean in an OID like ifHCInOctets.3?

    In a table column OID the last number is the row index.
  2. 2. Why prefer 64-bit counters (ifHCInOctets) on fast links?

    At 1 Gbit/s a 32-bit byte counter wraps in about 34 seconds.
  3. 3. Which SNMP version should you use across untrusted networks?

    Only v3 offers authentication and encryption.
  4. 4. Which Zabbix preprocessing step turns a counter into a rate?

    Change per second divides the difference by the time between samples.

Summary

  • SNMP exposes a tree of OIDs on UDP 161; MIBs give them names.
  • Use v2c for convenience in trusted networks and v3 elsewhere; change default communities.
  • Interface byte counters need a rate calculation; prefer 64-bit HC counters.
  • Test with snmpget and snmpwalk from the monitoring server first.
  • Zabbix has SNMP items, walks and discovery; Nagios uses check_snmp.

Next: Nagios objects and plugins