Mini-HOWTO: mini_snmpd, a small snmpd for embedded systems like OpenWrt

mini_snmpd is a GPL snmpd by Robert Ernst. http://members.aon.at/linuxfreak/linux/mini_snmpd.html.

It doesn't include docs, so here are some starter docs. The OpenWrt version can be installed from the package manager, but it doesn't seem to include a startup script for init.d, so I'll try to whip one up here, as well.

First, you'll need command line access to the device, so if it's an OpenWrt router, install the dropbear ssh server, and log in via ssh. SSH in as root.

To see the help for mini_snmpd, use the -h option:

mini_snmpd -h

You should see:

usage: mini_snmpd [options]

-p, --udp-port nnn     set the UDP port to bind to (161)
-P, --tcp-port nnn     set the TCP port to bind to (161)
-c, --community nnn    set the community string (public)
-D, --description nnn  set the system description (empty)
-V, --vendor nnn       set the system vendor (empty)
-L, --location nnn     set the system location (empty)
-C, --contact nnn      set the system contact (empty)
-d, --disks nnn        set the disks to monitor (/)
-i, --interfaces nnn   set the network interfaces to monitor (lo)
-t, --timeout nnn      set the timeout for MIB updates (1 second)
-a, --auth             require authentication (thus SNMP version 2c)
-v, --verbose          verbose syslog messages 
-l, --licensing        print licensing info and exit
-h, --help             print this help and exit

The default values are in parens.

On a router, you usually want to see the traffic going through the network interfaces. Here's a run of mini_snmpd that exposed those values:

mini_snmpd -i eth0.1,wl0,br-lan

Your command line may differ, depending on your router and network configuration. Mine was OpenWrt on a Linksys WRT54g or gl.

Back on your desktop (or whatever computer will be querying for snmp stats), use the net-snmp tools to poll for data. I learned how in this tutorial, Simple SNMP with Linux, by Jason Philbrook.

Run this:

snmpwalk -v 1 -c public 192.168.111.1

That IP address is my router. -v means version, and -c means community name: version 1, community "public". mini_snmpd seems to ignore the community name, but it must be supplied. The output I got was:

iso.3.6.1.2.1.1.1.0 = ""
iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1
iso.3.6.1.2.1.1.3.0 = Timeticks: (412) 0:00:04.12
iso.3.6.1.2.1.1.4.0 = ""
iso.3.6.1.2.1.1.5.0 = STRING: "OpenWrt"
iso.3.6.1.2.1.1.6.0 = ""
iso.3.6.1.2.1.2.1.0 = INTEGER: 3
iso.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
iso.3.6.1.2.1.2.2.1.1.2 = INTEGER: 2
iso.3.6.1.2.1.2.2.1.1.3 = INTEGER: 3
iso.3.6.1.2.1.2.2.1.2.1 = STRING: "eth0.1"
iso.3.6.1.2.1.2.2.1.2.2 = STRING: "wl0"
iso.3.6.1.2.1.2.2.1.2.3 = STRING: "br-lan"
iso.3.6.1.2.1.2.2.1.8.1 = INTEGER: 1
iso.3.6.1.2.1.2.2.1.8.2 = INTEGER: 1
iso.3.6.1.2.1.2.2.1.8.3 = INTEGER: 1
iso.3.6.1.2.1.2.2.1.10.1 = Counter32: 1758591601
iso.3.6.1.2.1.2.2.1.10.2 = Counter32: 3436817368
iso.3.6.1.2.1.2.2.1.10.3 = Counter32: 1913312114
iso.3.6.1.2.1.2.2.1.11.1 = Counter32: 122466684
iso.3.6.1.2.1.2.2.1.11.2 = Counter32: 6121670
iso.3.6.1.2.1.2.2.1.11.3 = Counter32: 110670073
iso.3.6.1.2.1.2.2.1.13.1 = Counter32: 0
iso.3.6.1.2.1.2.2.1.13.2 = Counter32: 0
iso.3.6.1.2.1.2.2.1.13.3 = Counter32: 0
iso.3.6.1.2.1.2.2.1.14.1 = Counter32: 0
iso.3.6.1.2.1.2.2.1.14.2 = Counter32: 85
iso.3.6.1.2.1.2.2.1.14.3 = Counter32: 0
iso.3.6.1.2.1.2.2.1.16.1 = Counter32: 4073775119
iso.3.6.1.2.1.2.2.1.16.2 = Counter32: 980016090
iso.3.6.1.2.1.2.2.1.16.3 = Counter32: 2726650206
iso.3.6.1.2.1.2.2.1.17.1 = Counter32: 112229579
iso.3.6.1.2.1.2.2.1.17.2 = Counter32: 6270244
iso.3.6.1.2.1.2.2.1.17.3 = Counter32: 120445972
iso.3.6.1.2.1.2.2.1.19.1 = Counter32: 0
iso.3.6.1.2.1.2.2.1.19.2 = Counter32: 0
iso.3.6.1.2.1.2.2.1.19.3 = Counter32: 0
iso.3.6.1.2.1.2.2.1.20.1 = Counter32: 0
iso.3.6.1.2.1.2.2.1.20.2 = Counter32: 11015
iso.3.6.1.2.1.2.2.1.20.3 = Counter32: 0
iso.3.6.1.2.1.25.1.1.0 = Timeticks: (748634215) 86 days, 15:32:22.15

The first part is the object ID (OID), the second part is the data type, and the third part (after the colon) is the value. The OID is like a path to a value. What are these values? There's a database for them, and this page will show you the names for the network counters at iso.3.6.1.2.1.2.2.1 http://www.alvestrand.no/objecti...

That site has a ton of OIDs in it.

Armed with this knowledge, you should be able to program Cacti or MRTG to extract data from your router and graph it.

An init.d for OpenWrt

The old version of OpenWrt I'm using didn't create a script in init.d for me. So here's an init.d script, /etc/init.d/mini_snmpd:

#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=50

start () {
	mini_snmpd -i eth0.1,wl0,br-lan &
}

stop() {
	killall -9 mini_snmpd
}

It's based on init.d/cron

You also need to run this:

cd /etc/rc.d/
ln -s /etc/init.d/mini_snmpd S50mini_snmpd
/etc/init.d/mini_snmp start

That creates a symlink to cause mini_snmpd to start on boot. Then it starts the daemon. You can now log out of the router.