Sample Configuration(logstash snmp input module)
AWS EC2インスタンスにが持つMIB情報(OID=1.3.6.1.2.1.25.3.3.1.2)を取得するように、以下のコンフィグファイルでは設定している。SNMP Input Pluginを確認して、SNMPv2で使用するパラメータ情報をすべて追記した。利用する上で不要な場合は適宜削除すればよい。
個々にOIDを指定したい場合は、getに対してOIDを羅列すればよいが、 walkを活用すれば、指定OID配下(その階層)の値をまるごと取得してくれる。
input {
snmp {
###get[array]
#Use the get option to query for scalar values for the given OID(s).
get => ["1.3.6.1.2.1.25.3.3.1.2"]
###hosts[array]
# The hosts option specifies the list of hosts to query the configured get and walk options.
# format {tcp|udp}:{ip address}/{port}
# community the community string, default is public
# version 1, 2c or 3, default is 2c.
# retries is the number of retries in case of failure, default is 2.
# timeout is the timeout in milliseconds with a default value of 1000.
hosts => [{host => "udp:127.0.0.1/161" community => "public" version => "2c" retries => 2 timeout => 1000}]
###interval[number]
#The interval option specifies the polling interval in seconds.
#Default value is 30
interval => 5
###mib_paths[path]
#The mib_paths option specifies the location of one or more imported MIB files.
#mib_paths => ["etc/mibfiles/mibfile.dic"]
###oid_root_skip[number]
#The oid_root_skip option specifies the number of OID root digits to ignore in the event field name.
#oid_root_skip => 0
###oid_path_length[number]
#The oid_path_length option specifies the number of OID root digits to retain in the event field name.
#oid_path_length => 0
###walk[array]
#Use the walk option to retrieve the subtree of information for the given OID(s)
#walk => ["1.3.6.1.2.1"]
# example OID
# .1.3.6.1.2.1.25.3.3.1.2:HOST-RESOURCES-MIB::hrProcessorLoad
# .1.3.6.1.4.1.2021.4.6:UCD-SNMP-MIB::memTotalReal
# .1.3.6.1.2.1.25.4.2.1.4:HOST-RESOURCES-MIB::hrSWRunName
}
}
Linux上でMIB情報を検索する方法
上記で設定できるのはわかったが、どのMIB情報をとってこればよいかわからない場合、対象サーバに対してMIBの情報を調査してから設定する必要がある。私が取得した対象(SNMP Agent)はAWS上のEC2インスタンスであるため、以下のようにコマンドで逐次確認しながら対象となるOIDを設定した。
(1)特定のOIDの情報を確認したい場合
nmpwalk -v 2c -c public localhost 1.3.6.1.2.1.25.3.3.1.2
(2)特定のOIDの詳細情報を確認したい場合
[root@ip-172-31-13-174 ~]# snmptranslate -Td 1.3.6.1.2.1.25.4.2.1.4
HOST-RESOURCES-MIB::hrSWRunPath
hrSWRunPath OBJECT-TYPE
-- FROM HOST-RESOURCES-MIB
-- TEXTUAL CONVENTION InternationalDisplayString
SYNTAX OCTET STRING (0..128)
MAX-ACCESS read-only
STATUS current
DESCRIPTION "A description of the location on long-term storage
(e.g. a disk drive) from which this software was
loaded."
::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) host(25) hrSWRun(4) hrSWRunTable(2) hrSWRunEntry(1) 4 }