pysnmp:AttributeError:';模块';对象没有属性';通知发起人';

pysnmp:AttributeError:';模块';对象没有属性';通知发起人';,snmp,net-snmp,pysnmp,Snmp,Net Snmp,Pysnmp,我正在使用pysnmp,其中我的脚本充当SNMP侦听器和转发器。我能够接收SNMP陷阱,并且可以看到MIB。我在ntforg.NotificationOriginator()的sendPdu函数中遇到错误。我正在centos上使用python 2 以下是错误片段: 版本详情: 我遗漏了什么吗?我不知道确切的“原因”,但是如果您想从hlapi导入某些内容,请尝试导入您想要使用的特定模块。因此,避免从pysnmp.hlapi导入*执行。因此,如果您删除这段代码,您的系统可能会正常工作 Traceba

我正在使用pysnmp,其中我的脚本充当SNMP侦听器和转发器。我能够接收SNMP陷阱,并且可以看到MIB。我在ntforg.NotificationOriginator()的sendPdu函数中遇到错误。我正在centos上使用python 2

以下是错误片段:

版本详情:


我遗漏了什么吗?

我不知道确切的“原因”,但是如果您想从
hlapi
导入某些内容,请尝试导入您想要使用的特定模块。因此,避免从pysnmp.hlapi导入*执行
。因此,如果您删除这段代码,您的系统可能会正常工作

Traceback (most recent call last):
File "/tmp/akhil.py", line 65, in <module>
snmp_engine.transportDispatcher.runDispatcher()
File "build/bdist.linux-x86_64/egg/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher
pysnmp.error.PySnmpError: poll error: Traceback (most recent call last):
;  File "build/bdist.linux-x86_64/egg/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher
    use_poll=True, map=self.__sockMap, count=1)
;  File "/usr/lib64/python2.7/asyncore.py", line 220, in loop
    poll_fun(timeout, map)
;  File "/usr/lib64/python2.7/asyncore.py", line 201, in poll2
    readwrite(obj, flags)
;  File "/usr/lib64/python2.7/asyncore.py", line 123, in readwrite
    obj.handle_error()
;  File "/usr/lib64/python2.7/asyncore.py", line 108, in readwrite
    obj.handle_read_event()
;  File "/usr/lib64/python2.7/asyncore.py", line 449, in handle_read_event
    self.handle_read()
;  File "build/bdist.linux-x86_64/egg/pysnmp/carrier/asyncore/dgram/base.py", line 170, in handle_read
    self._cbFun(self, transportAddress, incomingMessage)
;  File "build/bdist.linux-x86_64/egg/pysnmp/carrier/base.py", line 70, in _cbFun
    self, transportDomain, transportAddress, incomingMessage
;  File "build/bdist.linux-x86_64/egg/pysnmp/entity/engine.py", line 152, in __receiveMessageCbFun
    self, transportDomain, transportAddress, wholeMsg
;  File "build/bdist.linux-x86_64/egg/pysnmp/proto/rfc3412.py", line 433, in receiveMessage
    PDU, maxSizeResponseScopedPDU, stateReference)
;  File "build/bdist.linux-x86_64/egg/pysnmp/entity/rfc3413/ntfrcv.py", line 115, in processPdu
    contextName, varBinds, self.__cbCtx)
;  File "/tmp/akhil.py", line 54, in cbFun
    ntf_org = ntforg.NotificationOriginator()
;AttributeError: 'module' object has no attribute 'NotificationOriginator'
caused by <type 'exceptions.AttributeError'>: 'module' object has no attribute 'NotificationOriginator'
e here
from pysmi.codegen import PySnmpCodeGen
from pysmi.parser import SmiStarParser
from pysmi.reader import FileReader
from pysmi.searcher import PyFileSearcher, PyPackageSearcher, StubSearcher
from pysmi.writer import PyFileWriter
from pysnmp.carrier.asyncore.dgram import udp
from pysnmp.carrier.error import CarrierError
from pysnmp.entity import config, engine
from pysnmp.entity.rfc3413 import ntforg, ntfrcv
from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.hlapi import *
from pysnmp.proto.api import v2c
from pysnmp.smi import builder, compiler, view
from pysnmp.smi.error import MibNotFoundError
from pysnmp.smi.rfc1902 import ObjectIdentity, ObjectType

# snmpTrapAddress, SCALAR, not-accessible, IpAddress, 1.3.6.1.6.3.18.1.3.0

# Create SNMP engine with autogenernated engineID and pre-bound
# to socket transport dispatcher
snmp_engine = engine.SnmpEngine()


# UDP over IPv4
config.addTransport(
    snmp_engine,
    udp.domainName,
    udp.UdpTransport().openServerMode(("0.0.0.0", 162))
)

config.addTransport(
        snmp_engine,
        udp.domainName + (2,),
        udp.UdpTransport().openClientMode()
)

# SNMPv1/2c setup
config.addV1System(snmp_engine, "my-area", "public")

config.addTargetParams(snmp_engine, "distant_agent_auth", "public", "noAuthNoPriv", 1)

config.addTargetAddr(snmp_engine, "distant_agent", udp.domainName + (2,),("100.80.97.21", 162), "distant_agent_auth", retryCount=0)

def cbFun(snmp_engine, state_reference, context_engine_id, context_name, var_binds, cb_ctx):
    execContext = snmp_engine.observer.getExecutionContext("rfc3412.receiveMessage:request")
    trap_pdu = v2c.TrapPDU()
    v2c.apiTrapPDU.setDefaults(trap_pdu)
    v2c.apiTrapPDU.setVarBinds(trap_pdu, var_binds)
    source_ip_address = execContext["transportAddress"][0]
    print "got traps from : {}".format(source_ip_address)
    var_binds_dict = {name.prettyPrint(): None if val.prettyPrint() == "" else val.prettyPrint() for name, val in var_binds}
    print var_binds_dict
    print "sending traps to destination 100.80.97.21"
    ntf_org = ntforg.NotificationOriginator()
    ntf_org.sendPdu(snmp_engine, "distant_agent", None, "", trap_pdu)


# Register SNMP Application at the SNMP engine
ntfrcv.NotificationReceiver(snmp_engine, cbFun)

snmp_engine.transportDispatcher.jobStarted(1)  # this job would never finish

# Run I/O dispatcher which would receive queries and send confirmations
try:
    snmp_engine.transportDispatcher.runDispatcher()
except:
    snmp_engine.transportDispatcher.closeDispatcher()
    raise
finally:
    snmp_engine.transportDispatcher.closeDispatcher()
    snmp_engine.transportDispatcher.jobFinished(1)
>>> pysnmp.__version__
'4.4.9'

>>> pysmi.__version__
'0.3.4'