本文整理匯總了Python中pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher.runDispatcher方法的典型用法代碼示例。如果您正苦於以下問題:Python AsyncoreDispatcher.runDispatcher方法的具體用法?Python AsyncoreDispatcher.runDispatcher怎麽用?Python AsyncoreDispatcher.runDispatcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher
的用法示例。
在下文中一共展示了AsyncoreDispatcher.runDispatcher方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
def __init__(self, data, timeout_func=None, receive_func=None, error_func=None):
self.__dict__.update(data)
self.timeout_func = timeout_func
self.receive_func = receive_func
self.error_func = error_func
self.pMod = pMod = api.protoModules[api.protoVersion2c]
self.reqPDU = reqPDU = pMod.SetRequestPDU()
pMod.apiPDU.setDefaults(reqPDU)
pMod.apiPDU.setVarBinds(reqPDU,
map(lambda a: (a[0], pMod.OctetString(str(a[2]))) if a[1] == 'str'
else (a[0], pMod.Integer(int(a[2]))), self.oid_keys_enc_val))
reqMsg = pMod.Message()
pMod.apiMessage.setDefaults(reqMsg)
pMod.apiMessage.setCommunity(reqMsg, self.community)
pMod.apiMessage.setPDU(reqMsg, reqPDU)
self.startedAt = time()
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
# UDP/IPv4
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openClientMode())
transportDispatcher.sendMessage(encoder.encode(reqMsg), udp.domainName, (self.network_address, self.port))
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例2: __init__
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
def __init__(self, data, timeout_func=None, receive_func=None, error_func=None):
self.__dict__.update(data)
self.timeout_func = timeout_func
self.receive_func = receive_func
self.error_func = error_func
headVars = [v2c.ObjectIdentifier(oid) for oid in
map(lambda oid: (int(i) for i in oid.split('.')), self.oid_keys)]
self.reqPDU = reqPDU = v2c.GetBulkRequestPDU()
v2c.apiBulkPDU.setDefaults(reqPDU)
v2c.apiBulkPDU.setNonRepeaters(reqPDU, self.non_repeaters)
v2c.apiBulkPDU.setMaxRepetitions(reqPDU, self.max_repetitions)
v2c.apiBulkPDU.setVarBinds(reqPDU, [(x, v2c.null) for x in headVars])
reqMsg = v2c.Message()
v2c.apiMessage.setDefaults(reqMsg)
v2c.apiMessage.setCommunity(reqMsg, self.community)
v2c.apiMessage.setPDU(reqMsg, reqPDU)
self.startedAt = time()
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openClientMode())
transportDispatcher.sendMessage(encoder.encode(reqMsg), udp.domainName, (self.network_address, self.port))
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例3: __init__
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
def __init__(self, data, timeout_func=None, receive_func=None, error_func=None):
self.__dict__.update(data)
self.timeout_func = timeout_func
self.receive_func = receive_func
self.error_func = error_func
self.pMod = pMod = api.protoModules[api.protoVersion2c]
self.reqPDU = reqPDU = pMod.GetRequestPDU()
pMod.apiPDU.setDefaults(reqPDU)
pMod.apiPDU.setVarBinds(reqPDU, ((oid, pMod.Null('')) for oid in self.oid_keys))
reqMsg = pMod.Message()
pMod.apiMessage.setDefaults(reqMsg)
pMod.apiMessage.setCommunity(reqMsg, self.community)
pMod.apiMessage.setPDU(reqMsg, reqPDU)
self.startedAt = time()
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
# UDP/IPv4
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openClientMode())
transportDispatcher.sendMessage(encoder.encode(reqMsg), udp.domainName, (self.network_address, self.port))
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例4: __init__
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
def __init__(self):
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbFun)
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openServerMode(('192.168.1.111', 162))) #RASPBERRY / PC IP ADRESS
transportDispatcher.jobStarted(1)
try:
transportDispatcher.runDispatcher()
except:
transportDispatcher.closeDispatcher()
raise
示例5: SNMPPDUHarness
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
class SNMPPDUHarness(threading.Thread):
def __init__(self, pdu, listen_address, listen_port, community="public"):
super(SNMPPDUHarness, self).__init__()
self.logger = logging.getLogger(__name__)
self.pdu = pdu
self.snmp_handler = SNMPPDUHandler(self.pdu, community=community)
self.listen_address = listen_address
self.listen_port = listen_port
self.transportDispatcher = AsyncoreDispatcher()
self._lock = threading.Lock()
self._stop_requested = False
def run(self):
with self._lock:
if self._stop_requested:
return
self.logger.info("Starting PDU '{}' on {}:{}".format(
self.pdu.name, self.listen_address, self.listen_port)
)
self.transportDispatcher.registerRecvCbFun(
self.snmp_handler.message_handler)
# UDP/IPv4
self.transportDispatcher.registerTransport(
udp.domainName,
udp.UdpSocketTransport().openServerMode(
(self.listen_address, self.listen_port))
)
self.transportDispatcher.jobStarted(1)
try:
# Dispatcher will never finish as job#1 never reaches zero
self.transportDispatcher.runDispatcher()
except Exception:
self.transportDispatcher.closeDispatcher()
def stop(self):
with self._lock:
self._stop_requested = True
try:
self.transportDispatcher.jobFinished(1)
except KeyError:
pass # The job is not started yet and will not start
示例6: run_dispatcher
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
def run_dispatcher(conf):
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(callback)
for num, cfg_string in enumerate(conf.alerts_interfaces):
parsed = cfg_string.split(':')
address = (parsed[0], int(parsed[1]) if len(parsed) == 2 else 162)
transportDispatcher.registerTransport(
udp.domainName + (num + 1,),
udp.UdpSocketTransport().openServerMode(address))
transportDispatcher.jobStarted(1)
try:
# Dispatcher will never finish as job#1 never reaches zero
transportDispatcher.runDispatcher()
except:
transportDispatcher.closeDispatcher()
raise
示例7: openServer
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
def openServer():
print "In Open server mode"
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(newFn)
# UDP/IPv4
transportDispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openServerMode(('localhost', 1171))
)
# UDP/IPv6
transportDispatcher.registerTransport(
udp6.domainName, udp6.Udp6SocketTransport().openServerMode(('::1', 1171))
)
transportDispatcher.jobStarted(1)
print "job started"
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例8:
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
# SNMPv3/USM setup
# user: usr-md5-des, auth: MD5, priv DES
config.addV3User(
snmpEngine, 'usr-md5-des',
config.usmHMACMD5AuthProtocol, 'authkey1',
config.usmDESPrivProtocol, 'privkey1'
)
# Allow full MIB access for this user / securityModels at VACM
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6), (1, 3, 6, 1, 2, 1))
# Get default SNMP context this SNMP engine serves
snmpContext = context.SnmpContext(snmpEngine)
# Register SNMP Applications at the SNMP engine for particular SNMP context
cmdrsp.GetCommandResponder(snmpEngine, snmpContext)
cmdrsp.SetCommandResponder(snmpEngine, snmpContext)
cmdrsp.NextCommandResponder(snmpEngine, snmpContext)
cmdrsp.BulkCommandResponder(snmpEngine, snmpContext)
# Register an imaginary never-ending job to keep I/O dispatcher running forever
transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
transportDispatcher.runDispatcher()
except:
transportDispatcher.closeDispatcher()
raise
示例9: symbol
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import runDispatcher [as 別名]
key='.'.join([str(i) for i in v._value])
value=b.getComponent('simple')._value
parsed=ObjectType(ObjectIdentity(key), value)
try: parsed.resolveWithMib(viewController)
except Exception as e:
logger.warning("TRAP\tERROR | Failed to resolve symbol ({}={})".format(key,value))
continue
key,value=parsed.prettyPrint().split(" = ")
logger.info("TRAP\t{} | {}".format(key,value))
if key=="PowerNet-MIB::mtrapargsString.0":
message=value
for contact in contacts['contacts']:
phoneNumber=contact['phoneNumber']
_redis.publish('sms', json.dumps(dict(phoneNumber=phoneNumber, message=message)))
return msg
dispatcher=AsyncoreDispatcher()
dispatcher.registerRecvCbFun(snmpRecvCallback)
dispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openServerMode((TRAP_IP_ADDRESS, TRAP_PORT))
)
dispatcher.jobStarted(1)
print("Starting...")
try: dispatcher.runDispatcher()
except:
dispatcher.closeDispatcher()
raise