本文整理汇总了Python中pysnmp.proto.api.decodeMessageVersion方法的典型用法代码示例。如果您正苦于以下问题:Python api.decodeMessageVersion方法的具体用法?Python api.decodeMessageVersion怎么用?Python api.decodeMessageVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysnmp.proto.api
的用法示例。
在下文中一共展示了api.decodeMessageVersion方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cbFun
# 需要导入模块: from pysnmp.proto import api [as 别名]
# 或者: from pysnmp.proto.api import decodeMessageVersion [as 别名]
def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):
while wholeMsg:
msgVer = int(api.decodeMessageVersion(wholeMsg))
if msgVer in api.protoModules:
pMod = api.protoModules[msgVer]
else:
print('Unsupported SNMP version %s' % msgVer)
return
reqMsg, wholeMsg = decoder.decode(
wholeMsg, asn1Spec=pMod.Message(),
)
print('Notification message from %s:%s: ' % (
transportDomain, transportAddress
)
)
reqPDU = pMod.apiMessage.getPDU(reqMsg)
if reqPDU.isSameTypeWith(pMod.TrapPDU()):
if msgVer == api.protoVersion1:
print('Enterprise: %s' % (pMod.apiTrapPDU.getEnterprise(reqPDU).prettyPrint()))
print('Agent Address: %s' % (pMod.apiTrapPDU.getAgentAddr(reqPDU).prettyPrint()))
print('Generic Trap: %s' % (pMod.apiTrapPDU.getGenericTrap(reqPDU).prettyPrint()))
print('Specific Trap: %s' % (pMod.apiTrapPDU.getSpecificTrap(reqPDU).prettyPrint()))
print('Uptime: %s' % (pMod.apiTrapPDU.getTimeStamp(reqPDU).prettyPrint()))
varBinds = pMod.apiTrapPDU.getVarBinds(reqPDU)
else:
varBinds = pMod.apiPDU.getVarBinds(reqPDU)
print('Var-binds:')
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
return wholeMsg
示例2: cbFun
# 需要导入模块: from pysnmp.proto import api [as 别名]
# 或者: from pysnmp.proto.api import decodeMessageVersion [as 别名]
def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):
while wholeMsg:
msgVer = api.decodeMessageVersion(wholeMsg)
if msgVer in api.protoModules:
pMod = api.protoModules[msgVer]
else:
print('Unsupported SNMP version %s' % msgVer)
return
reqMsg, wholeMsg = decoder.decode(
wholeMsg, asn1Spec=pMod.Message(),
)
rspMsg = pMod.apiMessage.getResponse(reqMsg)
rspPDU = pMod.apiMessage.getPDU(rspMsg)
reqPDU = pMod.apiMessage.getPDU(reqMsg)
varBinds = []
pendingErrors = []
errorIndex = 0
# GETNEXT PDU
if reqPDU.isSameTypeWith(pMod.GetNextRequestPDU()):
# Produce response var-binds
for oid, val in pMod.apiPDU.getVarBinds(reqPDU):
errorIndex = errorIndex + 1
# Search next OID to report
nextIdx = bisect.bisect(mibInstr, oid)
if nextIdx == len(mibInstr):
# Out of MIB
varBinds.append((oid, val))
pendingErrors.append(
(pMod.apiPDU.setEndOfMibError, errorIndex)
)
else:
# Report value if OID is found
varBinds.append(
(mibInstr[nextIdx].name, mibInstr[nextIdx](msgVer))
)
elif reqPDU.isSameTypeWith(pMod.GetRequestPDU()):
for oid, val in pMod.apiPDU.getVarBinds(reqPDU):
if oid in mibInstrIdx:
varBinds.append((oid, mibInstrIdx[oid](msgVer)))
else:
# No such instance
varBinds.append((oid, val))
pendingErrors.append(
(pMod.apiPDU.setNoSuchInstanceError, errorIndex)
)
break
else:
# Report unsupported request type
pMod.apiPDU.setErrorStatus(rspPDU, 'genErr')
pMod.apiPDU.setVarBinds(rspPDU, varBinds)
# Commit possible error indices to response PDU
for f, i in pendingErrors:
f(rspPDU, i)
transportDispatcher.sendMessage(
encoder.encode(rspMsg), transportDomain, transportAddress
)
return wholeMsg
示例3: handleSnmpMessage
# 需要导入模块: from pysnmp.proto import api [as 别名]
# 或者: from pysnmp.proto.api import decodeMessageVersion [as 别名]
def handleSnmpMessage(d, t, private={}):
msgVer = api.decodeMessageVersion(d['data'])
if msgVer in api.protoModules:
pMod = api.protoModules[msgVer]
else:
stats['bad packets'] += 1
return
try:
rspMsg, wholeMsg = decoder.decode(
d['data'], asn1Spec=pMod.Message(),
)
except PyAsn1Error:
stats['bad packets'] += 1
return
if rspMsg['data'].getName() == 'response':
rspPDU = pMod.apiMessage.getPDU(rspMsg)
errorStatus = pMod.apiPDU.getErrorStatus(rspPDU)
if errorStatus:
stats['SNMP errors'] += 1
else:
endpoint = d['source_address'], d['source_port']
if endpoint not in endpoints:
endpoints[endpoint] = udp.domainName + (transportIdOffset + len(endpoints),)
stats['agents seen'] += 1
context = '%s/%s' % (pMod.ObjectIdentifier(endpoints[endpoint]),
pMod.apiMessage.getCommunity(rspMsg))
if context not in contexts:
contexts[context] = {}
stats['contexts seen'] += 1
context = '%s/%s' % (pMod.ObjectIdentifier(endpoints[endpoint]),
pMod.apiMessage.getCommunity(rspMsg))
stats['Response PDUs seen'] += 1
if 'basetime' not in private:
private['basetime'] = t
for oid, value in pMod.apiPDU.getVarBinds(rspPDU):
if oid < startOID:
continue
if stopOID and oid >= stopOID:
continue
if oid in contexts[context]:
if value != contexts[context][oid]:
stats['snapshots taken'] += 1
else:
contexts[context][oid] = [], []
contexts[context][oid][0].append(t - private['basetime'])
contexts[context][oid][1].append(value)
stats['OIDs seen'] += 1
示例4: cbFun
# 需要导入模块: from pysnmp.proto import api [as 别名]
# 或者: from pysnmp.proto.api import decodeMessageVersion [as 别名]
def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):
while wholeMsg:
msgVer = int(api.decodeMessageVersion(wholeMsg))
if msgVer in api.protoModules:
pMod = api.protoModules[msgVer]
else:
print('Unsupported SNMP version %s' % msgVer)
return
reqMsg, wholeMsg = decoder.decode(
wholeMsg, asn1Spec=pMod.Message(),
)
print('Notification message from %s:%s: ' % (
transportDomain, transportAddress
)
)
reqPDU = pMod.apiMessage.getPDU(reqMsg)
if reqPDU.isSameTypeWith(pMod.TrapPDU()):
if msgVer == api.protoVersion1:
print('Enterprise: %s' % (
pMod.apiTrapPDU.getEnterprise(reqPDU).prettyPrint()
)
)
print('Agent Address: %s' % (
pMod.apiTrapPDU.getAgentAddr(reqPDU).prettyPrint()
)
)
print('Generic Trap: %s' % (
pMod.apiTrapPDU.getGenericTrap(reqPDU).prettyPrint()
)
)
print('Specific Trap: %s' % (
pMod.apiTrapPDU.getSpecificTrap(reqPDU).prettyPrint()
)
)
print('Uptime: %s' % (
pMod.apiTrapPDU.getTimeStamp(reqPDU).prettyPrint()
)
)
varBinds = pMod.apiTrapPDU.getVarBindList(reqPDU)
else:
varBinds = pMod.apiPDU.getVarBindList(reqPDU)
print('Var-binds:')
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
return wholeMsg
示例5: cbFun
# 需要导入模块: from pysnmp.proto import api [as 别名]
# 或者: from pysnmp.proto.api import decodeMessageVersion [as 别名]
def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):#??Trap?????
while wholeMsg:
msgVer = int(api.decodeMessageVersion(wholeMsg))#??????
if msgVer in api.protoModules:#??????
pMod = api.protoModules[msgVer]
else:#?????????????
print('Unsupported SNMP version %s' % msgVer)
return
reqMsg, wholeMsg = decoder.decode(
wholeMsg, asn1Spec=pMod.Message(),#???????
)
print('Notification message from %s:%s: ' % (
transportDomain, transportAddress#????TRAP????
)
)
reqPDU = pMod.apiMessage.getPDU(reqMsg)
if reqPDU.isSameTypeWith(pMod.TrapPDU()):
if msgVer == api.protoVersion1:
print('Enterprise: %s' % (
pMod.apiTrapPDU.getEnterprise(reqPDU).prettyPrint()
)
)
print('Agent Address: %s' % (
pMod.apiTrapPDU.getAgentAddr(reqPDU).prettyPrint()
)
)
print('Generic Trap: %s' % (
pMod.apiTrapPDU.getGenericTrap(reqPDU).prettyPrint()
)
)
print('Specific Trap: %s' % (
pMod.apiTrapPDU.getSpecificTrap(reqPDU).prettyPrint()
)
)
print('Uptime: %s' % (
pMod.apiTrapPDU.getTimeStamp(reqPDU).prettyPrint()
)
)
varBinds = pMod.apiTrapPDU.getVarBindList(reqPDU)
else:
varBinds = pMod.apiPDU.getVarBindList(reqPDU)
print('Var-binds:')
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))#?????Trap????
return wholeMsg