« misty | Main | high street mid range low life »

airport express and snmp (and cricket)

Ok, it's time to nerd out for a moment. So you've got an Apple Airport Express (or an Airport Extreme) base station, you're not scared of a Terminal window and you've got a bit of an itch to find out stuff like, say, how many wireless clients are connecting to your base setation?

First off, grab AIRPORT-BASESTATION-3-MIB. This'll provide useful labels for the data you're going to be poking at. Put it somewhere useful, like in $HOME/share/mibs or /usr/local/share/mibs. I'll assume it's in $HOME/share/mibs for the following examples.

Secondly, find out the name of your base station - if you called it "MyAirportExpress", you should be able to ping MyAirportExpress.local from your Mac.

You can now try running this nice long command:

snmpwalk -v 2c -c PASSWORD -M /usr/share/snmp/mibs:$HOME/share/mibs \
 -m+AIRPORT-BASESTATION-3-MIB MyAirportExpress.local

(PASSWORD should be the admin password for your base station. You can remove the \ and put it all on a single line, if you like.)

Assuming it worked, you should see something like this in your terminal:

AIRPORT-BASESTATION-3-MIB::sysConfName.0 = STRING: MyAirportExpress
AIRPORT-BASESTATION-3-MIB::sysConfUptime.0 = INTEGER: 617622
AIRPORT-BASESTATION-3-MIB::sysConfFirmwareVersion.0 = STRING: 6.1.1
AIRPORT-BASESTATION-3-MIB::wirelessPhysAddress."". = Hex-STRING: 00 03 93 AA AA AA 
AIRPORT-BASESTATION-3-MIB::wirelessType."". = INTEGER: sta(1)
AIRPORT-BASESTATION-3-MIB::wirelessDataRates."". = STRING:  [ 1 2 5.5 11 18 24 36 48 54 ]
AIRPORT-BASESTATION-3-MIB::wirelessTimeAssociated."". = INTEGER: 6455
AIRPORT-BASESTATION-3-MIB::wirelessLastRefreshTime."". = INTEGER: 0
AIRPORT-BASESTATION-3-MIB::wirelessStrength."". = INTEGER: -40
AIRPORT-BASESTATION-3-MIB::wirelessNoise."". = INTEGER: -83
AIRPORT-BASESTATION-3-MIB::wirelessNumRX."". = INTEGER: 172380
AIRPORT-BASESTATION-3-MIB::physicalInterfaceCount.0 = INTEGER: 2
AIRPORT-BASESTATION-3-MIB::physicalInterfaceIndex.1 = INTEGER: 1
AIRPORT-BASESTATION-3-MIB::physicalInterfaceIndex.2 = INTEGER: 2
AIRPORT-BASESTATION-3-MIB::physicalInterfaceName.1 = STRING: "wl"
AIRPORT-BASESTATION-3-MIB::physicalInterfaceName.2 = STRING: "et"
AIRPORT-BASESTATION-3-MIB::physicalInterfaceUnit.1 = INTEGER: 0
AIRPORT-BASESTATION-3-MIB::physicalInterfaceUnit.2 = INTEGER: 0
AIRPORT-BASESTATION-3-MIB::physicalInterfaceSpeed.1 = INTEGER: 54000000
AIRPORT-BASESTATION-3-MIB::physicalInterfaceSpeed.2 = INTEGER: 100000000
AIRPORT-BASESTATION-3-MIB::physicalInterfaceState.1 = INTEGER: linkUp(1)
AIRPORT-BASESTATION-3-MIB::physicalInterfaceState.2 = INTEGER: linkUp(1)
AIRPORT-BASESTATION-3-MIB::physicalInterfaceDuplex.1 = INTEGER: half(0)
AIRPORT-BASESTATION-3-MIB::physicalInterfaceDuplex.2 = INTEGER: full(1)
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumTX.1 = INTEGER: 3996793
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumTX.2 = INTEGER: 2331863
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumRX.1 = INTEGER: 12672032
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumRX.2 = INTEGER: 3868042
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumTXError.1 = INTEGER: 734
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumTXError.2 = INTEGER: 0
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumRXError.1 = INTEGER: 0
AIRPORT-BASESTATION-3-MIB::physicalInterfaceNumRXError.2 = INTEGER: 16

Notice all those nice labels - that's thanks to the AIRPORT-BASESTATION-3-MIB - without it, you'd just see stuff like:

SNMPv2-SMI::enterprises.63.501. = STRING: "GothamCity"
SNMPv2-SMI::enterprises.63.501. = ""
SNMPv2-SMI::enterprises.63.501. = ""
SNMPv2-SMI::enterprises.63.501. = INTEGER: 617996
SNMPv2-SMI::enterprises.63.501. = STRING: "6.1.1"
SNMPv2-SMI::enterprises.63.501. = INTEGER: 1

which isn't quite as useful unless you're able to guess what they mean (which is possible in some cases, but y'know...).

You might just want to check one value, with:

snmpget -v 2c -c PASSWORD -M /usr/share/snmp/mibs:$HOME/share/mibs \
 -m+AIRPORT-BASESTATION-3-MIB MyAirportExpress.local AIRPORT-BASESTATION-3-MIB::wirelessNumber.0

So what if you want to feed it to some kind of graphing tool like, say, cricket? You'll need to know the OID, since cricket doesn't use MIB files. You find it out by adding -On to ask snmpget to print a numerical OID instead of the label:

snmpget -On -v 2c -c PASSWORD -M /usr/share/snmp/mibs:$HOME/share/mibs \
 -m+AIRPORT-BASESTATION-3-MIB MyAirportExpress.local AIRPORT-BASESTATION-3-MIB::wirelessNumber.0

...which oughta give you this:

. = INTEGER: 1

...giving you . for yer OID to go and graph.

If you've been trying out genDevConfig to autogenerate a cricket config, you're in luck! I've hacked up a very simple module for Airport base stations (based on one of the other modules that comes with genDevConfig) - here's AppleAirport.pm (put it in the plugins/genConfig directory), and Defaults.apple (put it in your config tree above where you'll be putting your Airport configs). Eventually, you'll get something like this (and hopefully a bit more exciting) :

example cricket graph of wireless devices over time

I hope that's useful. You might notice I haven't mentioned anything about DHCP, which would be because I don't use it on my own Airport Express - if you are, you oughta see a few extra things in the snmpwalk output, which you can go forth and graph (or not).

Have fun!

* 22:41 * geek · comments (0)

Leave a comment