PYSNMP自定义陷阱发送器,哪些是额外的OID?

2024-09-30 06:27:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我不是snmp专家;几周前,我在闲暇时间刚开始在公司的一个系统中实现一项新功能

我复制粘贴了我在这里找到的答案

from pysnmp.hlapi import *
from pysnmp import debug

debug.setLogger(debug.Debug('msgproc'))

next(sendNotification(SnmpEngine(),
                      CommunityData('public'),
                      UdpTransportTarget(('192.168.1.92',162)),
                      ContextData(),
                      'trap',
                      [ObjectType(ObjectIdentity('1.3.6.1.2.7.8'), Integer32(5)),
                       ObjectType(ObjectIdentity('1.3.6.6.7'),Integer32(45))]
                      )
     )

我的receiver catch 4变量绑定不仅仅是我指定的2,调试显示了下一个变量

2017-03-24 09:07:53,015 pysnmp: running pysnmp version 4.3.4
2017-03-24 09:07:53,016 pysnmp: debug category 'msgproc' enabled
2017-03-24 09:07:54,115 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.AccessAllowed object at 0x762eb170>}
2017-03-24 09:07:54,116 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.AccessAllowed object at 0x762eb170>}
2017-03-24 09:07:54,120 pysnmp: prepareOutgoingMessage: using contextEngineId SnmpEngineID() contextName b''
2017-03-24 09:07:54,123 pysnmp: generateRequestMsg: Message:
 version=1
 community=public
 data=PDUs:
  snmpV2-trap=SNMPv2TrapPDU:
   request-id=10292983
   error-status='noError'
   error-index=0
   variable-bindings=VarBindList:
    VarBind:
     name=1.3.6.1.2.1.1.3.0
     =_BindValue:
      value=ObjectSyntax:
       application-wide=ApplicationSyntax:
        timeticks-value=0



    VarBind:
     name=1.3.6.1.6.3.1.1.4.1.0
     =_BindValue:
      value=ObjectSyntax:
       simple=SimpleSyntax:
        objectID-value=1.3.6.1.6.3.1.1.5.1

    VarBind:
     name=1.3.6.1.2.7.8
     =_BindValue:
      value=ObjectSyntax:
       simple=SimpleSyntax:
        integer-value=5

    VarBind:
     name=1.3.6.6.7
     =_BindValue:
      value=ObjectSyntax:
       simple=SimpleSyntax:
        integer-value=45

我的问题是,我真的不知道前两个OID是什么意思

**1.3.6.1.2.1.1.3.0 = 0
1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1**
1.3.6.1.2.7.8 = 5
1.3.6.6.7 = 45

从snmpv2 mib看,他们似乎是个老家伙,但我不确定


Tags: namefromdebugimportvaluepublicsimplepysnmp
1条回答
网友
1楼 · 发布于 2024-09-30 06:27:10

因此,您正在发送一个SNMPv2陷阱(CommunityData(mpModel=1)暗示)。根据RFC1905第4.2.6章:

The first two variable bindings in the variable binding list of an SNMPv2-Trap-PDU are sysUpTime.0 and snmpTrapOID.0 respectively.

由于您自己还没有提供这些,pysnmp会自动添加它们以生成格式良好的PDU

请注意,根据您发送的陷阱的ID,pysnmp可能会尝试查找更多OID值对,并将其作为RFC命令附加到var绑定:

If the OBJECTS clause is present in the invocation of the corresponding NOTIFICATION-TYPE macro, then each corresponding variable, as instantiated by this notification, is copied, in order, to the variable-bindings field.

您可以传递一个查找映射("objects" parameter)来初始化这些对象。否则,pysnmp将在其本地MIB中搜索它们

最后,您显式传递的OID属于RFC的这一部分:

If any additional variables are being included (at the option of the generating SNMPv2 entity), then each is copied to the variable-bindings field.

相关问题 更多 >

    热门问题