简体   繁体   中英

snmp-server trap-source using pysnmp

I'm relatively new to pysnmp. My current requirement is to support trap source for snmp traps. I am trying to understand how I can support this with pysnmp ntforg.NotificationOriginator construct.

My current code snippet for sending out traps is as follows:

varBinds = rfc1902.ObjectIdentity('SNMPv2-MIB', 'coldStart')
    trapVarBinds = trapAgent.VarBinds(varBinds,'','')
    trapPdu = rfc1902.NotificationType(
                varBinds
            ).resolveWithMib(self.mibViewController)        
    SendTrap(trapAgent.TrapData(trapPdu,trapVarBinds))

 def SendTrap(self,trapData):
    for server in trapServer:  #list of trapServer config info
        data = trapServer[server]
        print 'Trap server:%s'%(data,)
        sendRequestHandle = ntforg.NotificationOriginator(snmpContext).sendVarBinds(
        snmpEngine,
        data.Name,
        #None,'',
        snmpContext.contextEngineId,'',
        trapData.trapPdu
        )

Any insights/advice on how to support for trap source here would be very helpful. Thanks!

refer Notification Originator

you can specify source IP and port like below

from pysnmp.entity import config
from pysnmp.carrier.asynsock.dgram import udp

config.addSocketTransport(
snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openClientMode(iface=('127.0.0.1', 1024))
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM