本文整理汇总了Python中pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher.registerRoutingCbFun方法的典型用法代码示例。如果您正苦于以下问题:Python AsyncoreDispatcher.registerRoutingCbFun方法的具体用法?Python AsyncoreDispatcher.registerRoutingCbFun怎么用?Python AsyncoreDispatcher.registerRoutingCbFun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher
的用法示例。
在下文中一共展示了AsyncoreDispatcher.registerRoutingCbFun方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AsyncoreDispatcher
# 需要导入模块: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 别名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import registerRoutingCbFun [as 别名]
from pysnmp.entity.rfc3413 import cmdrsp, context
from pysnmp.proto import rfc1902
from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher
from pysnmp.carrier.asyncore.dgram import udp
# Configuration parameters for each of SNMP Engines
snmpEngineInfo = (
('0102030405060708', udp.domainName + (0,), ('127.0.0.1', 161)),
('0807060504030201', udp.domainName + (1,), ('127.0.0.2', 161))
)
# Instantiate the single transport dispatcher object
transportDispatcher = AsyncoreDispatcher()
# Setup a custom data routing function to select snmpEngine by transportDomain
transportDispatcher.registerRoutingCbFun(lambda td, t, d: td)
# Instantiate and configure SNMP Engines
for snmpEngineId, transportDomain, transportAddress in snmpEngineInfo:
# Create SNMP engine with specific engineID
snmpEngine = engine.SnmpEngine(rfc1902.OctetString(hexValue=snmpEngineId))
# Register SNMP Engine object with transport dispatcher. Request incoming
# data from specific transport endpoint to be funneled to this SNMP Engine.
snmpEngine.registerTransportDispatcher(transportDispatcher, transportDomain)
# Transport setup
# UDP over IPv4
config.addTransport(
snmpEngine,
示例2: print
# 需要导入模块: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 别名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import registerRoutingCbFun [as 别名]
errorStatus, errorIndex))
else:
print('Notification %s for SNMP Engine %s delivered: ' % (
sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint()))
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
# Instantiate the single transport dispatcher object
transportDispatcher = AsyncoreDispatcher()
# Setup a custom data routing function to select snmpEngine by transportDomain
transportDispatcher.registerRoutingCbFun(
lambda td, ta, d: ta[1] % 3 and 'A' or 'B'
)
snmpEngineA = SnmpEngine()
snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A')
snmpEngineB = SnmpEngine()
snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B')
for authData, transportTarget, contextData in TARGETS:
# Pick one of the two SNMP engines
snmpEngine = (transportTarget.getTransportInfo()[1][1] % 3 and
snmpEngineA or snmpEngineB)
sendPduHandle = sendNotification(