snmpwalk, snmptranslateの便利コマンド
仕事でSNMPのセットアップをする必要があり、その過程で不便だった点の解決策を改めて調べました。
実行環境
root@HANAE:/home/hanae# uname -a
Linux HANAE 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
詳細なログを出力する
Debugging
-d dump input/output packets in hexadecimal
-D[TOKEN[,...]] turn on debugging output for the specified TOKENs
(ALL gives extremely verbose debugging output)
-D[TOKEN]
オプション
snmpwalk
等のコマンドに -D[TOKEN]
オプションをつけると、デバッグ用の詳しいログが得られる。( -Dall
オプションですべて出力。多すぎて見づらいため非推奨)
- 通常出力例
root@HANAE:/etc/snmp# snmpwalk -v2c -c public localhost UCD-SNMP-MIB::prNames.1
UCD-SNMP-MIB::prNames.1 = STRING: cron
- デバッグ出力例
root@HANAE:/etc/snmp# snmpwalk -Dnetsnmp_udp -v2c -c public localhost UCD-SNMP-MIB::prNames.1
registered debug token netsnmp_udp, 1
netsnmp_udpbase: open remote UDP: [127.0.0.1]:161->[0.0.0.0]:0
netsnmp_udpbase: binding socket: 3 to UDP: [0.0.0.0]:0->[0.0.0.0]:0
netsnmp_udpbase: socket 3 bound to UDP: [127.0.0.1]:161->[0.0.0.0]:42076
netsnmp_udp: send 46 bytes from 0x55dfe80ed176 to UDP: [127.0.0.1]:161->[0.0.0.0]:42076 on fd 3
netsnmp_udp: recvfrom fd 3 got 47 bytes (from UDP: [127.0.0.1]:161->[0.0.0.0]:42076)
netsnmp_udp: send 46 bytes from 0x55dfe80ed176 to UDP: [127.0.0.1]:161->[0.0.0.0]:42076 on fd 3
netsnmp_udp: recvfrom fd 3 got 50 bytes (from UDP: [127.0.0.1]:161->[0.0.0.0]:42076)
UCD-SNMP-MIB::prNames.1 = STRING: cron
snmpwalk -Dall -v2c -c public localhost UCD-SNMP-MIB::prNames.1 2>&1 | awk -F':' '/:/{ print $1 }' | sort -u
で、適用できるトークンが(ざっくり)わかる。
利用できるトークン例
- UDPBase
- callback
- cert
- container
- container_registry
- daemonize
- defaults
- dns
- dumph_recv
- dumph_send
- dumpv_recv
- dumpv_send
- dumpx_recv
- dumpx_send
- fixup_mib_directory
- get_mib_directory
- init_mib
- init_usm
- lcd_set_enginetime
- netsnmp_ds_set_boolean
- netsnmp_ds_set_string
- netsnmp_sockaddr_in
- netsnmp_udp
- netsnmp_udpbase
- parse-file
- parse-mibs
- read_config
- sess_async_send
- sess_process_packet
- sess_select
- snmp_alarm
- snmp_api
- snmp_parse_args
- snmp_pdu_realloc_rbuild
- snmp_send
- snmp_sess
- snmp_sess_add
- snmp_synch
- socket
- tdomain
- trace
- transport
- tsm
- udpbase
- verbose
-d
オプション
-d
オプションをつけると、16進数形式のデータダンプが得られる。
- 通常出力例
root@HANAE:/etc/snmp# snmpwalk -v2c -c public localhost HOST-RESOURCES-MIB::hrSystemProcesses
HOST-RESOURCES-MIB::hrSystemProcesses.0 = Gauge32: 33
- デバッグ出力例
root@HANAE:/etc/snmp# snmpwalk -d -v2c -c public localhost HOST-RESOURCES-MIB::hrSystemProcesses
Sending 43 bytes to UDP: [127.0.0.1]:161->[0.0.0.0]:43255
0000: 30 29 02 01 01 04 06 70 75 62 6C 69 63 A1 1C 02 0).....public...
0016: 04 1D 3D EB 2F 02 01 00 02 01 00 30 0E 30 0C 06 ..=./......0.0..
0032: 08 2B 06 01 02 01 19 01 06 05 00 .+.........
Received 45 byte packet from UDP: [127.0.0.1]:161->[0.0.0.0]:43255
0000: 30 2B 02 01 01 04 06 70 75 62 6C 69 63 A2 1E 02 0+.....public...
0016: 04 1D 3D EB 2F 02 01 00 02 01 00 30 10 30 0E 06 ..=./......0.0..
0032: 09 2B 06 01 02 01 19 01 06 00 42 01 21 .+........B.!
HOST-RESOURCES-MIB::hrSystemProcesses.0 = Gauge32: 33
Sending 44 bytes to UDP: [127.0.0.1]:161->[0.0.0.0]:43255
0000: 30 2A 02 01 01 04 06 70 75 62 6C 69 63 A1 1D 02 0*.....public...
0016: 04 1D 3D EB 30 02 01 00 02 01 00 30 0F 30 0D 06 ..=.0......0.0..
0032: 09 2B 06 01 02 01 19 01 06 00 05 00 .+..........
Received 45 byte packet from UDP: [127.0.0.1]:161->[0.0.0.0]:43255
0000: 30 2B 02 01 01 04 06 70 75 62 6C 69 63 A2 1E 02 0+.....public...
0016: 04 1D 3D EB 30 02 01 00 02 01 00 30 10 30 0E 06 ..=.0......0.0..
0032: 09 2B 06 01 02 01 19 01 07 00 02 01 00 .+...........
指定したMIBファイルの構造を表示する
標準MIBや有名メーカーのプライベートMIBはネットで情報を調べられるが、snmptranslate
コマンドで確認することも可能。
-m
オプション(読み込むMIBファイルを指定)と-T
オプション(translate結果の表示形式などのオプション)を組み合わせて実行する。
-T TRANSOPTS
Provides control over the translation of the OID values. The following TRANSOPTS are available:
-TB Print all matching objects for a regex search.
-Td Print full details of the specified OID.
-Tp Print a graphical tree, rooted at the specified OID.
-Ta Dump the loaded MIB in a trivial form.
-Tl Dump a labeled form of all objects.
-To Dump a numeric form of all objects.
-Ts Dump a symbolic form of all objects.
-Tt Dump a tree form of the loaded MIBs (mostly useful for debugging).
-Tz Dump a numeric and labeled form of all objects (compatible with MIB2SCHEMA format).
特に、-To
オプションをさらにsnmptranslate
(| grep XXX
)すると、使用できるオブジェクトがモジュール名+オブジェクト名形式で取得できる。
snmptranslate -m HOST-RESOURCES-MIB -To | xargs -n1 snmptranslate | grep HOST-RESOURCES-MIB
root@HANAE:/etc/snmp# snmptranslate -m HOST-RESOURCES-MIB -To | xargs -n1 snmptranslate | grep HOST-RESOURCES-MIB
HOST-RESOURCES-MIB::host
HOST-RESOURCES-MIB::hrSystem
HOST-RESOURCES-MIB::hrSystemUptime
HOST-RESOURCES-MIB::hrSystemDate
HOST-RESOURCES-MIB::hrSystemInitialLoadDevice
HOST-RESOURCES-MIB::hrSystemInitialLoadParameters
HOST-RESOURCES-MIB::hrSystemNumUsers
...
その他のTオプション出力例
snmptranslate -m UUID-TC-MIB -Tp
root@HANAE:/etc/snmp# snmptranslate -m UUID-TC-MIB -Tp
+--iso(1)
|
+--org(3)
|
+--dod(6)
|
+--internet(1)
|
+--directory(1)
|
+--mgmt(2)
| |
| +--mib-2(1)
| |
| +--transmission(10)
| |
...
snmptranslate -m UUID-TC-MIB -Tl
root@HANAE:/etc/snmp# snmptranslate -m UUID-TC-MIB -Tl
.iso(1).org(3)
.iso(1).org(3).dod(6)
.iso(1).org(3).dod(6).internet(1)
.iso(1).org(3).dod(6).internet(1).directory(1)
.iso(1).org(3).dod(6).internet(1).mgmt(2)
.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1)
.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).transmission(10)
.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).uuidTCMIB(217)
...
snmptranslate -m UUID-TC-MIB -To
root@HANAE:/etc/snmp# snmptranslate -m UUID-TC-MIB -To
.1.3
.1.3.6
.1.3.6.1
.1.3.6.1.1
.1.3.6.1.2
.1.3.6.1.2.1
.1.3.6.1.2.1.10
.1.3.6.1.2.1.217
.1.3.6.1.3
...
snmptranslate -m UUID-TC-MIB -Tt
root@HANAE:/etc/snmp# snmptranslate -m UUID-TC-MIB -Tt
org(3) type=0
dod(6) type=0
internet(1) type=0
directory(1) type=0
mgmt(2) type=0
mib-2(1) type=0
transmission(10) type=0
uuidTCMIB(217) type=24
...
snmptranslate -m UUID-TC-MIB -Tz
root@HANAE:/etc/snmp# snmptranslate -m UUID-TC-MIB -Tz
"org" "1.3"
"dod" "1.3.6"
"internet" "1.3.6.1"
"directory" "1.3.6.1.1"
"mgmt" "1.3.6.1.2"
"mib-2" "1.3.6.1.2.1"
"transmission" "1.3.6.1.2.1.10"
"uuidTCMIB" "1.3.6.1.2.1.217"
"experimental" "1.3.6.1.3"
"private" "1.3.6.1.4"
"enterprises" "1.3.6.1.4.1"
...
参考
Discussion