Skip to content

Instantly share code, notes, and snippets.

@jonnystorm
Last active March 28, 2017 15:10
Show Gist options
  • Save jonnystorm/7136bff23cca0f84219d6cd4cdaeabfc to your computer and use it in GitHub Desktop.
Save jonnystorm/7136bff23cca0f84219d6cd4cdaeabfc to your computer and use it in GitHub Desktop.
Resolve MIB name to OID in Elixir
# Change MIB extensions from .txt to .mib
copy -r /usr/share/snmp/mibs /home/jstorm/mibs
cd /home/jstorm/mibs
rename '\.txt$' .mib *
# Replace instances of RowStatus with INTEGER in MIBs.
# Otherwise, expect compilation errors.
# Compile dependencies before target MIB (IP-FORWARD-MIB, in this case).
iex> :snmpc.compile('IANAifType-MIB', [i: ['/home/jstorm/mibs']])
{:ok, './IANAifType-MIB.bin'}
iex> :snmpc.compile('IF-MIB', [i: ['/home/jstorm/mibs']])
{:ok, './IF-MIB.bin'}
iex> :snmpc.compile('IP-MIB', [i: ['/home/jstorm/mibs']])
{:ok, './IP-MIB.bin'}
iex> :snmpc.compile('IANA-RTPROTO-MIB', [i: ['/home/jstorm/mibs']])
{:ok, './IANA-RTPROTO-MIB.bin'}
iex> :snmpc.compile('IP-FORWARD-MIB', [i: ['/home/jstorm/mibs']])
{:ok, './IP-FORWARD-MIB.bin'}
# Start :snmpm, load the compiled MIB, and resolve name.
iex> :snmpm.start
:ok
iex> :snmpm.load_mib('IP-FORWARD-MIB')
:ok
iex> :snmpm.name_to_oid(:ipCidrRouteTable)
{:ok, [[1, 3, 6, 1, 2, 1, 4, 24, 4]]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment