« more | Main | remote luxuries »

zsh completion for SNMP MIB names

It's been, ooh, probably almost 10 years since I last swam about in the sea of fun you could have with zsh - since then, I just stuck with what I'd already got working and concentrated on other things. I recently had a minor urge to write something to complete SNMP MIB names in the shell for me, since it's something I'd been doing a lot lately and by George you get bored of going to another terminal window, ls'ing your tree of MIBs and copying and pasting it over.

So here it is. zsh's completion system completely changed since I last understood it, so most of my time was spent simply learning the new completion system from scratch. I haven't yet worked out why the autoloading doesn't pick up the initialization part (where it works out where your MIBs are, depending on whether you'd set MIBDIRS or put it in ~/.snmp/snmp.conf). As such, until I sort that out, the best way to use it is to stick it in a place like ~/lib/zsh/_snmpcmd and put a

. ~/lib/zsh/_snmpcmd

in your .zshrc.

...I'll report back when I have an answer to this

Anyway, you should now find that you can type "snmpwalk -m ", hit Tab and get told there's about 1700-odd MIBs to complete (if you've got all the Cisco MIBs handy - see below for a mirroring script). The completer handles a + in front of MIB names, and you can colon-separate them and still have completion. Having solved that, I typed in some basic completion guff for the rest of the options to snmpwalk, as you'll see in the file - most of them are generic options, and should work with other stuff like snmptranslate and such.

_snmpcmd

size: 4 KB.
last modified: 2006-07-16.

If you want your own mirror of the Cisco MIBs, here's what I use to get 'em. You don't need a CCO account for this, they're publically available.

mirror-cisco-mibs

size: 239 B.
last modified: 2006-07-16.

Technorati Tags: , , , ,

* 12:07 * geek · comments (0)

Comments


Comments have been closed for this post. If you've got something to say, please contact me by other means. Thanks!