28
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SNMPTRAPの発報方法(v1~v3)

Last updated at Posted at 2017-05-07

snmptrapの発報用方法

監視サーバ(zabbix等)で、SNMPTRAP受信をテスト(Trigger試験)することがありました。
その際、SNMPTRAPを容易に発報できる仕組みがあればと思い手順をまとめました。
特に、version1はトラップ送信元IPアドレス(AgentAddress)を指定できるので便利です。

今回取り上げるトラップの種類

今回実施したサンプルの設定値

皆さんの環境に合わせて置き換えてください

Version コミュニティ名
1 publicv1
2c publicv2
3 publicv3
  • (共通)トラップ宛先IP = 192.168.10.189(snmptrapd稼働IP)
  • (共通)トラップするOID = netSnmpExperimental.1=hogehoge1,netSnmpExperimental.2=hogehoge2
  • version1用設定内容
    • GenericTrapType = EnterpriseSpecific(6)
    • SpecificTrapType = 99
    • AgentAddressを指定して、送信元IP=10.0.0.1に詐称
  • version3用設定内容
    • EngineID = 0x80001F88803C41A86E8BCE0D59
    • 認証/暗号化有無 = Auth/NoPriv
    • ユーザ名 = publicv3
    • 認証用パスワード(SHA) = hogehoge123

snmptrap受信側設定

snmptrapのversion1,2c,3を受信できるように設定

/etc/snmp/snmptrapd.conf
authCommunity log,execute,net publicv1
authCommunity log,execute,net publicv2
authUser log,execute,net publicv3
createUser -e 0x80001F88803C41A86E8BCE0D59 publicv3 SHA hogehoge123

snmptrap v1 送信設定コマンドと実行結果

version1は、agent addressが引数にあるので、任意のアドレスをSNMPTRAP送信元に定義することができるのでテストが簡単になります。ここでは、10.0.0.1を送信元アドレスとして定義してみます。

snmptrap(v1)
snmptrap -v 1 -c publicv1 192.168.10.189 '' 10.0.0.1 6 99 '' netSnmpExperimental.1 s "hogehoge1" netSnmpExperimental.2 s "hogehoge2"
log(v1)
May  6 20:22:47 localhost snmptrapd[2107]: 2017-05-06 20:22:47 10.0.0.1(via UDP: [192.168.10.189]:35025->[192.168.10.189]:162) TRAP, SNMP v1, community publicv1#012#011SNMPv2-SMI::enterprises.3.1.1 Enterprise Specific Trap (99) Uptime: 1:24:44.66#012#011NET-SNMP-MIB::netSnmpExperimental.1 = STRING: "hogehoge1"#011NET-SNMP-MIB::netSnmpExperimental.2 = STRING: "hogehoge2"
wiresharkのログ(v1)
Simple Network Management Protocol
    version: version-1 (0)
    community: publicv1
    data: trap (4)
        trap
            enterprise: 1.3.6.1.4.1.3.1.1 (iso.3.6.1.4.1.3.1.1)
            agent-addr: 10.0.0.1 (10.0.0.1)    送信元アドレス詐称できてます
            generic-trap: enterpriseSpecific (6)
            specific-trap: 99
            time-stamp: 508466
            variable-bindings: 2 items
                1.3.6.1.4.1.8072.9999.1: 686f6765686f676531
                    Object Name: 1.3.6.1.4.1.8072.9999.1 (iso.3.6.1.4.1.8072.9999.1)
                    Value (OctetString): 686f6765686f676531
                1.3.6.1.4.1.8072.9999.2: 686f6765686f676532
                    Object Name: 1.3.6.1.4.1.8072.9999.2 (iso.3.6.1.4.1.8072.9999.2)
                    Value (OctetString): 686f6765686f676532

snmptrap v2c 送信設定コマンドと実行結果

snmptrap(v2c)
snmptrap -v 2c -c publicv2 192.168.10.189 '' netSnmpExperimental netSnmpExperimental.1 s "hogehoge1" netSnmpExperimental.2 s "hogehoge2"
log(v2c)
May  6 19:16:48 localhost snmptrapd[2107]: 2017-05-06 19:16:48 localhost.localdomain [UDP: [192.168.10.189]:53862->[192.168.10.189]:162]:#012DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (112564) 0:18:45.64#011SNMPv2-MIB::snmpTrapOID.0 = OID: NET-SNMP-MIB::netSnmpExperimental#011NET-SNMP-MIB::netSnmpExperimental.1 = STRING: "hogehoge1"#011NET-SNMP-MIB::netSnmpExperimental.2 = STRING: "hogehoge2"
wiresharkのログ(v2c)
Simple Network Management Protocol
    version: v2c (1)
    community: publicv2
    data: snmpV2-trap (7)
        snmpV2-trap
            request-id: 203283761
            error-status: noError (0)
            error-index: 0
            variable-bindings: 4 items
                1.3.6.1.2.1.1.3.0: 112564 <- sysUpTime(共通)
                    Object Name: 1.3.6.1.2.1.1.3.0 (iso.3.6.1.2.1.1.3.0)
                    Value (Timeticks): 112564
                1.3.6.1.6.3.1.1.4.1.0: 1.3.6.1.4.1.8072.9999 (iso.3.6.1.4.1.8072.9999) <-snmpTrapOID(共通)
                    Object Name: 1.3.6.1.6.3.1.1.4.1.0 (iso.3.6.1.6.3.1.1.4.1.0)
                    Value (OID): 1.3.6.1.4.1.8072.9999 (iso.3.6.1.4.1.8072.9999)
                1.3.6.1.4.1.8072.9999.1: 686f6765686f676531
                    Object Name: 1.3.6.1.4.1.8072.9999.1 (iso.3.6.1.4.1.8072.9999.1)
                    Value (OctetString): 686f6765686f676531
                1.3.6.1.4.1.8072.9999.2: 686f6765686f676532
                    Object Name: 1.3.6.1.4.1.8072.9999.2 (iso.3.6.1.4.1.8072.9999.2)
                    Value (OctetString): 686f6765686f676532

snmptrap v3 送信設定コマンドと実行結果

snmptrap(v3)
snmptrap -e 0x80001F88803C41A86E8BCE0D59 -v 3 -l authNoPriv -u publicv3 -a SHA -A hogehoge123 192.168.10.189 '' netSnmpExperimental netSnmpExperimental.1 s 'hogehoge1' netSnmpExperimental.2 s 'hogehoge2'
log(v3)
May  6 19:19:00 localhost snmptrapd[2107]: 2017-05-06 19:19:00 localhost.localdomain [UDP: [192.168.10.189]:46755->[192.168.10.189]:162]:#012DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (125758) 0:20:57.58#011SNMPv2-MIB::snmpTrapOID.0 = OID: NET-SNMP-MIB::netSnmpExperimental#011NET-SNMP-MIB::netSnmpExperimental.1 = STRING: "hogehoge1"#011NET-SNMP-MIB::netSnmpExperimental.2 = STRING: "hogehoge2"
wiresharkのログ(v3)
Simple Network Management Protocol
    msgVersion: snmpv3 (3)
    msgGlobalData
        msgID: 453410534
        msgMaxSize: 65507
        msgFlags: 01
            .... .0.. = Reportable: Not set
            .... ..0. = Encrypted: Not set
            .... ...1 = Authenticated: Set
        msgSecurityModel: USM (3)
    msgAuthoritativeEngineID: 80001f88803c41a86e8bce0d59
        1... .... = Engine ID Conformance: RFC3411 (SNMPv3)
        Engine Enterprise ID: net-snmp (8072)
        Engine ID Format: Reserved/Enterprise-specific (128): Net-SNMP Random
        Engine ID Data: 3c41a86e
        Engine ID Data: Creation Time: May  6, 2017 09:24:27 EDT
    msgAuthoritativeEngineBoots: 0
    msgAuthoritativeEngineTime: 0
    msgUserName: publicv3
    msgAuthenticationParameters: c097fbc636a1334c5bcf37f3
    msgPrivacyParameters: <MISSING>
    msgData: plaintext (0)
        plaintext
            contextEngineID: 80001f88803c41a86e8bce0d5900000000
                1... .... = Engine ID Conformance: RFC3411 (SNMPv3)
                Engine Enterprise ID: net-snmp (8072)
                Engine ID Format: Reserved/Enterprise-specific (128): Net-SNMP Random
                <Data not conforming to RFC3411>
            contextName:
            data: snmpV2-trap (7)
                snmpV2-trap
                    request-id: 1409056236
                    error-status: noError (0)
                    error-index: 0
                    variable-bindings: 4 items
                        1.3.6.1.2.1.1.3.0: 125758 <- sysUpTime
                            Object Name: 1.3.6.1.2.1.1.3.0 (iso.3.6.1.2.1.1.3.0)(共通)
                            Value (Timeticks): 125758
                        1.3.6.1.6.3.1.1.4.1.0: 1.3.6.1.4.1.8072.9999 (iso.3.6.1.4.1.8072.9999) <-snmpTrapOID(共通)
                            Object Name: 1.3.6.1.6.3.1.1.4.1.0 (iso.3.6.1.6.3.1.1.4.1.0)
                            Value (OID): 1.3.6.1.4.1.8072.9999 (iso.3.6.1.4.1.8072.9999)
                        1.3.6.1.4.1.8072.9999.1: 686f6765686f676531
                            Object Name: 1.3.6.1.4.1.8072.9999.1 (iso.3.6.1.4.1.8072.9999.1)
                            Value (OctetString): 686f6765686f676531
                        1.3.6.1.4.1.8072.9999.2: 686f6765686f676532
                            Object Name: 1.3.6.1.4.1.8072.9999.2 (iso.3.6.1.4.1.8072.9999.2)
                            Value (OctetString): 686f6765686f676532
28
30
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?