pep8 reformatted
parent
9541f201e3
commit
020791a972
|
@ -92,7 +92,7 @@ def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):
|
|||
rspMsg = pMod.apiMessage.getResponse(reqMsg)
|
||||
rspPDU = pMod.apiMessage.getPDU(rspMsg)
|
||||
reqPDU = pMod.apiMessage.getPDU(reqMsg)
|
||||
varBinds = [];
|
||||
varBinds = []
|
||||
pendingErrors = []
|
||||
errorIndex = 0
|
||||
# GETNEXT PDU
|
||||
|
|
|
@ -65,9 +65,9 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -19,7 +19,7 @@ receiver:
|
|||
|
||||
Requires Python 3.4 and later!
|
||||
|
||||
"""#
|
||||
""" #
|
||||
from pysnmp.entity import engine, config
|
||||
from pysnmp.carrier.asyncio.dgram import udp
|
||||
from pysnmp.entity.rfc3413 import ntfrcv
|
||||
|
@ -53,6 +53,7 @@ config.addTransport(
|
|||
# SecurityName <-> CommunityName mapping
|
||||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal
|
||||
def cbFun(snmpEngine,
|
||||
|
@ -61,14 +62,13 @@ def cbFun(snmpEngine,
|
|||
varBinds,
|
||||
cbCtx):
|
||||
transportDomain, transportAddress = snmpEngine.msgAndPduDsp.getTransportInfo(stateReference)
|
||||
print('Notification from %s, SNMP Engine %s, Context %s' % (
|
||||
transportAddress, contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from %s, SNMP Engine %s, Context %s' % (transportAddress,
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Create an SNMP context with ContextEngineId = 8000000001020304
|
||||
snmpContext = context.SnmpContext(
|
||||
|
@ -56,7 +56,7 @@ snmpContext = context.SnmpContext(
|
|||
# Management Instrumentation Controller and register at SNMP Context
|
||||
# under ContextName 'my-context'
|
||||
snmpContext.registerContextName(
|
||||
v2c.OctetString('my-context'), # Context Name
|
||||
v2c.OctetString('my-context'), # Context Name
|
||||
instrum.MibInstrumController(builder.MibBuilder()) # Managed Objects
|
||||
)
|
||||
|
||||
|
|
|
@ -43,23 +43,25 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-none-none', 'noAuthNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-none-none', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Create an SNMP context
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
||||
|
||||
# Very basic Management Instrumentation Controller without
|
||||
# any Managed Objects attached. It supports only GET's and
|
||||
# always echos request var-binds in response.
|
||||
class EchoMibInstrumController(instrum.AbstractMibInstrumController):
|
||||
def readVars(self, vars, acInfo=(None, None)):
|
||||
return [ (ov[0], v2c.OctetString('You queried OID %s' % ov[0])) for ov in vars]
|
||||
return [(ov[0], v2c.OctetString('You queried OID %s' % ov[0])) for ov in vars]
|
||||
|
||||
|
||||
# Create a custom Management Instrumentation Controller and register at
|
||||
# SNMP Context under ContextName 'my-context'
|
||||
snmpContext.registerContextName(
|
||||
v2c.OctetString('my-context'), # Context Name
|
||||
EchoMibInstrumController() # Management Instrumentation
|
||||
v2c.OctetString('my-context'), # Context Name
|
||||
EchoMibInstrumController() # Management Instrumentation
|
||||
)
|
||||
|
||||
# Register GET&SET Applications at the SNMP engine for a custom SNMP context
|
||||
|
|
|
@ -43,7 +43,7 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -40,7 +40,7 @@ config.addTransport(
|
|||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
# Allow read MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1,3,6,5))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1, 3, 6, 5))
|
||||
|
||||
# Create an SNMP context
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
@ -53,6 +53,7 @@ MibScalar, MibScalarInstance = mibBuilder.importSymbols(
|
|||
'SNMPv2-SMI', 'MibScalar', 'MibScalarInstance'
|
||||
)
|
||||
|
||||
|
||||
class MyStaticMibScalarInstance(MibScalarInstance):
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal
|
||||
def getValue(self, name, idx):
|
||||
|
@ -60,9 +61,10 @@ class MyStaticMibScalarInstance(MibScalarInstance):
|
|||
'Python %s running on a %s platform' % (sys.version, sys.platform)
|
||||
)
|
||||
|
||||
|
||||
mibBuilder.exportSymbols(
|
||||
'__MY_MIB', MibScalar((1,3,6,5,1), v2c.OctetString()),
|
||||
MyStaticMibScalarInstance((1,3,6,5,1), (0,), v2c.OctetString())
|
||||
'__MY_MIB', MibScalar((1, 3, 6, 5, 1), v2c.OctetString()),
|
||||
MyStaticMibScalarInstance((1, 3, 6, 5, 1), (0,), v2c.OctetString())
|
||||
)
|
||||
|
||||
# --- end of Managed Object Instance initialization ----
|
||||
|
|
|
@ -47,7 +47,7 @@ config.addTransport(
|
|||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
# Allow read MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1,3,6,6), (1,3,6,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1, 3, 6, 6), (1, 3, 6, 6))
|
||||
|
||||
# Create an SNMP context
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
@ -56,43 +56,43 @@ snmpContext = context.SnmpContext(snmpEngine)
|
|||
|
||||
mibBuilder = snmpContext.getMibInstrum().getMibBuilder()
|
||||
|
||||
( MibTable,
|
||||
MibTableRow,
|
||||
MibTableColumn,
|
||||
MibScalarInstance ) = mibBuilder.importSymbols(
|
||||
'SNMPv2-SMI',
|
||||
(MibTable,
|
||||
MibTableRow,
|
||||
MibTableColumn,
|
||||
MibScalarInstance) = mibBuilder.importSymbols(
|
||||
'SNMPv2-SMI',
|
||||
'MibTable',
|
||||
'MibTableRow',
|
||||
'MibTableColumn',
|
||||
'MibScalarInstance'
|
||||
)
|
||||
)
|
||||
|
||||
RowStatus, = mibBuilder.importSymbols('SNMPv2-TC', 'RowStatus')
|
||||
|
||||
mibBuilder.exportSymbols(
|
||||
'__EXAMPLE-MIB',
|
||||
# table object
|
||||
exampleTable=MibTable((1,3,6,6,1)).setMaxAccess('readcreate'),
|
||||
# table row object, also carries references to table indices
|
||||
exampleTableEntry=MibTableRow((1,3,6,6,1,5)).setMaxAccess('readcreate').setIndexNames((0, '__EXAMPLE-MIB', 'exampleTableColumn1')),
|
||||
# table column: string index
|
||||
exampleTableColumn1=MibTableColumn((1,3,6,6,1,5,1), v2c.OctetString()).setMaxAccess('readcreate'),
|
||||
# table column: string value
|
||||
exampleTableColumn2=MibTableColumn((1,3,6,6,1,5,2), v2c.OctetString()).setMaxAccess('readcreate'),
|
||||
# table column: integer value with default
|
||||
exampleTableColumn3=MibTableColumn((1,3,6,6,1,5,3), v2c.Integer32(123)).setMaxAccess('readcreate'),
|
||||
# table column: row status
|
||||
exampleTableStatus=MibTableColumn((1,3,6,6,1,5,4), RowStatus('notExists')).setMaxAccess('readcreate')
|
||||
'__EXAMPLE-MIB',
|
||||
# table object
|
||||
exampleTable=MibTable((1, 3, 6, 6, 1)).setMaxAccess('readcreate'),
|
||||
# table row object, also carries references to table indices
|
||||
exampleTableEntry=MibTableRow((1, 3, 6, 6, 1, 5)).setMaxAccess('readcreate').setIndexNames((0, '__EXAMPLE-MIB', 'exampleTableColumn1')),
|
||||
# table column: string index
|
||||
exampleTableColumn1=MibTableColumn((1, 3, 6, 6, 1, 5, 1), v2c.OctetString()).setMaxAccess('readcreate'),
|
||||
# table column: string value
|
||||
exampleTableColumn2=MibTableColumn((1, 3, 6, 6, 1, 5, 2), v2c.OctetString()).setMaxAccess('readcreate'),
|
||||
# table column: integer value with default
|
||||
exampleTableColumn3=MibTableColumn((1, 3, 6, 6, 1, 5, 3), v2c.Integer32(123)).setMaxAccess('readcreate'),
|
||||
# table column: row status
|
||||
exampleTableStatus=MibTableColumn((1, 3, 6, 6, 1, 5, 4), RowStatus('notExists')).setMaxAccess('readcreate')
|
||||
)
|
||||
|
||||
# --- end of custom SNMP table definition, empty table now exists ---
|
||||
|
||||
# --- populate custom SNMP table with one row ---
|
||||
|
||||
( exampleTableEntry,
|
||||
exampleTableColumn2,
|
||||
exampleTableColumn3,
|
||||
exampleTableStatus ) = mibBuilder.importSymbols(
|
||||
(exampleTableEntry,
|
||||
exampleTableColumn2,
|
||||
exampleTableColumn3,
|
||||
exampleTableStatus) = mibBuilder.importSymbols(
|
||||
'__EXAMPLE-MIB',
|
||||
'exampleTableEntry',
|
||||
'exampleTableColumn2',
|
||||
|
@ -102,9 +102,9 @@ mibBuilder.exportSymbols(
|
|||
rowInstanceId = exampleTableEntry.getInstIdFromIndices('example record one')
|
||||
mibInstrumentation = snmpContext.getMibInstrum()
|
||||
mibInstrumentation.writeVars(
|
||||
( (exampleTableColumn2.name+rowInstanceId, 'my string value'),
|
||||
(exampleTableColumn3.name+rowInstanceId, 123456),
|
||||
(exampleTableStatus.name+rowInstanceId, 'createAndGo') )
|
||||
((exampleTableColumn2.name + rowInstanceId, 'my string value'),
|
||||
(exampleTableColumn3.name + rowInstanceId, 123456),
|
||||
(exampleTableStatus.name + rowInstanceId, 'createAndGo'))
|
||||
)
|
||||
|
||||
# --- end of SNMP table population ---
|
||||
|
|
|
@ -46,7 +46,7 @@ config.addTransport(
|
|||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
# Allow full MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -45,7 +45,7 @@ config.addTransport(
|
|||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
# Allow full MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -68,7 +68,7 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -43,8 +43,8 @@ config.addV1System(snmpEngine, 'my-read-area', 'public')
|
|||
config.addV1System(snmpEngine, 'my-write-area', 'private')
|
||||
|
||||
# Allow full MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 1, 'my-read-area', 'noAuthNoPriv', (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-write-area', 'noAuthNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-read-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-write-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -33,15 +33,15 @@ 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) )
|
||||
('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)
|
||||
transportDispatcher.registerRoutingCbFun(lambda td, t, d: td)
|
||||
|
||||
# Instantiate and configure SNMP Engines
|
||||
for snmpEngineId, transportDomain, transportAddress in snmpEngineInfo:
|
||||
|
@ -71,7 +71,7 @@ for snmpEngineId, transportDomain, transportAddress in snmpEngineInfo:
|
|||
)
|
||||
|
||||
# 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))
|
||||
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)
|
||||
|
|
|
@ -56,9 +56,9 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -27,6 +27,7 @@ from pysnmp.carrier.asyncore.dgram import udp
|
|||
# Create SNMP engine
|
||||
snmpEngine = engine.SnmpEngine()
|
||||
|
||||
|
||||
# Execution point observer setup
|
||||
|
||||
# Register a callback to be invoked at specified execution point of
|
||||
|
@ -43,6 +44,7 @@ def requestObserver(snmpEngine, execpoint, variables, cbCtx):
|
|||
print('* contextName: %s' % variables['contextName'].prettyPrint())
|
||||
print('* PDU: %s' % variables['pdu'].prettyPrint())
|
||||
|
||||
|
||||
snmpEngine.observer.registerObserver(
|
||||
requestObserver,
|
||||
'rfc3412.receiveMessage:request',
|
||||
|
@ -68,7 +70,7 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -79,34 +79,34 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (2&3), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
# Create Notification Originator App instance.
|
||||
ntfOrg = ntforg.NotificationOriginator()
|
||||
|
||||
|
||||
# Error/confirmation receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
errorStatus, errorIndex, varBinds, cbCtx):
|
||||
print('Notification %s, status - %s' % (
|
||||
sendRequestHandle, errorIndication and errorIndication or 'delivered'
|
||||
)
|
||||
)
|
||||
|
||||
print('Notification %s, status - %s' % (sendRequestHandle,
|
||||
errorIndication and errorIndication or 'delivered'))
|
||||
|
||||
|
||||
# Build and submit notification message to dispatcher
|
||||
sendRequestHandle = ntfOrg.sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
# additional var-binds: ( (oid, value), ... )
|
||||
((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator'))
|
||||
((1, 3, 6, 1, 2, 1, 1, 1, 0), v2c.OctetString('Example Notificator'))
|
||||
],
|
||||
cbFun
|
||||
)
|
||||
|
|
|
@ -50,37 +50,39 @@ config.addTargetAddr(
|
|||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
# Create SNMP v2c TRAP PDU with defaults
|
||||
trapPDU = v2c.TrapPDU()
|
||||
trapPDU = v2c.TrapPDU()
|
||||
v2c.apiTrapPDU.setDefaults(trapPDU)
|
||||
|
||||
# Set custom var-binds to TRAP PDU
|
||||
v2c.apiTrapPDU.setVarBinds(
|
||||
trapPDU, [
|
||||
# sysUpTime
|
||||
( v2c.ObjectIdentifier('1.3.6.1.2.1.1.3.0'), v2c.TimeTicks(123) ),
|
||||
(v2c.ObjectIdentifier('1.3.6.1.2.1.1.3.0'), v2c.TimeTicks(123)),
|
||||
# snmpTrapPDU
|
||||
( (1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1)) )
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1)))
|
||||
]
|
||||
)
|
||||
|
||||
# Create Notification Originator App instance.
|
||||
ntfOrg = ntforg.NotificationOriginator()
|
||||
|
||||
|
||||
# Error/confirmation receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
errorStatus, errorIndex, varBinds, cbCtx):
|
||||
print('Notification %s, status - %s' % (
|
||||
sendRequestHandle, errorIndication and errorIndication or 'delivered'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Build and submit notification message to dispatcher
|
||||
ntfOrg.sendPdu(
|
||||
snmpEngine,
|
||||
# Notification targets
|
||||
'my-nms', # target address
|
||||
None, '', # contextEngineId, contextName
|
||||
'my-nms', # target address
|
||||
None, '', # contextEngineId, contextName
|
||||
trapPDU,
|
||||
cbFun
|
||||
)
|
||||
|
|
|
@ -75,7 +75,7 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
|
@ -87,14 +87,14 @@ ntfOrg.sendVarBinds(
|
|||
snmpEngine,
|
||||
# Notification targets
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
# additional var-binds: ( (oid, value), ... )
|
||||
((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
|
||||
((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
|
||||
((1, 3, 6, 1, 2, 1, 1, 1, 0), v2c.OctetString('Example Notificator')),
|
||||
((1, 3, 6, 1, 2, 1, 1, 5, 0), v2c.OctetString('Notificator Example'))
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
|
@ -86,14 +86,14 @@ ntfOrg.sendVarBinds(
|
|||
snmpEngine,
|
||||
# Notification targets
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
# additional var-binds: ( (oid, value), ... )
|
||||
((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
|
||||
((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
|
||||
((1, 3, 6, 1, 2, 1, 1, 1, 0), v2c.OctetString('Example Notificator')),
|
||||
((1, 3, 6, 1, 2, 1, 1, 5, 0), v2c.OctetString('Notificator Example'))
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (1), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
|
@ -68,11 +68,11 @@ ntfOrg = ntforg.NotificationOriginator()
|
|||
ntfOrg.sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1)))
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1)))
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -74,26 +74,26 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
# Create Notification Originator App instance.
|
||||
ntfOrg = ntforg.NotificationOriginator()
|
||||
|
||||
|
||||
# Build and submit notification message to dispatcher
|
||||
ntfOrg.sendVarBinds(
|
||||
snmpEngine,
|
||||
# Notification targets
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
# additional var-binds: ( (oid, value), ... )
|
||||
((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
|
||||
((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
|
||||
((1, 3, 6, 1, 2, 1, 1, 1, 0), v2c.OctetString('Example Notificator')),
|
||||
((1, 3, 6, 1, 2, 1, 1, 5, 0), v2c.OctetString('Notificator Example'))
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -56,30 +56,32 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (3), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
# Create Notification Originator App instance.
|
||||
ntfOrg = ntforg.NotificationOriginator()
|
||||
|
||||
|
||||
|
||||
# Error/confirmation receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
errorStatus, errorIndex, varBinds, cbCtx):
|
||||
print('Notification %s, status - %s' % (
|
||||
sendRequestHandle, errorIndication and errorIndication or 'delivered'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Build and submit notification message to dispatcher
|
||||
sendRequestHandle = ntfOrg.sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds: SNMPv2-MIB::coldStart, ...
|
||||
[ ((1,3,6,1,6,3,1,1,5,1), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1,3,6,1,2,1,1,5,0), v2c.OctetString('system name')) ],
|
||||
[((1, 3, 6, 1, 6, 3, 1, 1, 5, 1), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
((1, 3, 6, 1, 2, 1, 1, 5, 0), v2c.OctetString('system name'))],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (1), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
|
@ -71,9 +71,9 @@ ntfOrg.sendVarBinds(
|
|||
snmpEngine,
|
||||
# Notification targets
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
[
|
||||
# Uptime value with 12345
|
||||
(v2c.ObjectIdentifier('1.3.6.1.2.1.1.3.0'),
|
||||
v2c.TimeTicks(12345)),
|
||||
|
|
|
@ -28,7 +28,7 @@ from pysnmp.proto.api import v2c
|
|||
snmpEngine = engine.SnmpEngine()
|
||||
|
||||
# SecurityName <-> CommunityName mapping (+ transport binding)
|
||||
config.addV1System(snmpEngine, 'my-area', 'public',
|
||||
config.addV1System(snmpEngine, 'my-area', 'public',
|
||||
transportTag='all-my-managers')
|
||||
|
||||
# Specify security settings per SecurityName (SNMPv2c -> 1)
|
||||
|
@ -58,34 +58,36 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
# Create Notification Originator App instance.
|
||||
ntfOrg = ntforg.NotificationOriginator()
|
||||
|
||||
|
||||
# Error/confirmation receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
errorStatus, errorIndex, varBinds, cbCtx):
|
||||
print('Notification %s, status - %s' % (
|
||||
sendRequestHandle, errorIndication and errorIndication or 'delivered'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Build and submit notification message to dispatcher
|
||||
sendRequestHandle = ntfOrg.sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
# additional var-binds: ( (oid, value), ... )
|
||||
((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
|
||||
((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
|
||||
((1, 3, 6, 1, 2, 1, 1, 1, 0), v2c.OctetString('Example Notificator')),
|
||||
((1, 3, 6, 1, 2, 1, 1, 5, 0), v2c.OctetString('Notificator Example'))
|
||||
],
|
||||
cbFun
|
||||
)
|
||||
|
|
|
@ -83,7 +83,7 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
|
@ -94,7 +94,7 @@ ntfOrg = ntforg.NotificationOriginator()
|
|||
ntfOrg.sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
rfc1902.NotificationType(
|
||||
rfc1902.ObjectIdentity('IF-MIB', 'linkUp'),
|
||||
instanceIndex=instanceIndex,
|
||||
|
|
|
@ -57,35 +57,37 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (2), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
# Create Notification Originator App instance.
|
||||
ntfOrg = ntforg.NotificationOriginator()
|
||||
|
||||
|
||||
# Error/confirmation receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
errorStatus, errorIndex, varBinds, cbCtx):
|
||||
print('Notification %s, status - %s' % (
|
||||
sendRequestHandle, errorIndication and errorIndication or 'delivered'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Build and submit notification message to dispatcher
|
||||
sendRequestHandle = ntfOrg.sendVarBinds(
|
||||
snmpEngine,
|
||||
# Notification targets
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
# additional var-binds: ( (oid, value), ... )
|
||||
((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
|
||||
((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
|
||||
((1, 3, 6, 1, 2, 1, 1, 1, 0), v2c.OctetString('Example Notificator')),
|
||||
((1, 3, 6, 1, 2, 1, 1, 5, 0), v2c.OctetString('Notificator Example'))
|
||||
],
|
||||
cbFun
|
||||
)
|
||||
|
|
|
@ -61,7 +61,7 @@ config.addNotificationTarget(
|
|||
# Allow NOTIFY access to Agent's MIB by this SNMP model (3), securityLevel
|
||||
# and SecurityName
|
||||
config.addContext(snmpEngine, '')
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (), (), (1,3,6))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (), (), (1, 3, 6))
|
||||
|
||||
# *** SNMP engine configuration is complete by this line ***
|
||||
|
||||
|
@ -73,13 +73,13 @@ ntfOrg.sendVarBinds(
|
|||
snmpEngine,
|
||||
# Notification targets
|
||||
'my-notification', # notification targets
|
||||
None, '', # contextEngineId, contextName
|
||||
None, '', # contextEngineId, contextName
|
||||
# var-binds
|
||||
[
|
||||
# SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
|
||||
((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
|
||||
((1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0), v2c.ObjectIdentifier((1, 3, 6, 1, 6, 3, 1, 1, 5, 1))),
|
||||
# additional var-binds: ( (oid, value), ... )
|
||||
((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
|
||||
((1, 3, 6, 1, 2, 1, 1, 5, 0), v2c.OctetString('Notificator Example'))
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -60,15 +61,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
if errorIndication:
|
||||
print(errorIndication)
|
||||
elif errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message, pass custom ContextEngineId & ContextName
|
||||
cmdgen.GetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
|
@ -77,7 +76,7 @@ cmdgen.GetCommandGenerator().sendVarBinds(
|
|||
rfc1902.OctetString(hexValue='80004fb805636c6f75644dab22cc'),
|
||||
# contextName
|
||||
rfc1902.OctetString('da761cfc8c94d3aceef4f60f049105ba'),
|
||||
[ ((1,3,6,1,2,1,1,1,0), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 1, 0), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ config.addTargetAddr(
|
|||
retryCount=5
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -58,21 +59,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
if errorIndication:
|
||||
print(errorIndication)
|
||||
elif errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.GetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,1,0), None) ],
|
||||
None, '', # contextEngineId, contextName
|
||||
[((1, 3, 6, 1, 2, 1, 1, 1, 0), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -58,24 +59,22 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
print(errorIndication)
|
||||
return
|
||||
if errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
|
||||
return # stop on error
|
||||
for varBindRow in varBindTable:
|
||||
for oid, val in varBindRow:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
return True # signal dispatcher to continue
|
||||
return True # signal dispatcher to continue
|
||||
|
||||
|
||||
# Prepare initial request to be sent
|
||||
cmdgen.NextCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1), None),
|
||||
((1,3,6,1,4,1,1), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1), None),
|
||||
((1, 3, 6, 1, 4, 1, 1), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequesthandle, errorIndication,
|
||||
|
@ -60,25 +61,23 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication,
|
|||
print(errorIndication)
|
||||
return # stop on error
|
||||
if errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
|
||||
return # stop on error
|
||||
for varBindRow in varBindTable:
|
||||
for oid, val in varBindRow:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
return True # signal dispatcher to continue walking
|
||||
return True # signal dispatcher to continue walking
|
||||
|
||||
|
||||
# Prepare initial request to be sent
|
||||
cmdgen.BulkCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
0, 25, # non-repeaters, max-repetitions
|
||||
( ((1,3,6,1,2,1,1), None),
|
||||
((1,3,6,1,4,1,1), None) ),
|
||||
0, 25, # non-repeaters, max-repetitions
|
||||
(((1, 3, 6, 1, 2, 1, 1), None),
|
||||
((1, 3, 6, 1, 4, 1, 1), None)),
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequesthandle, errorIndication,
|
||||
|
@ -57,25 +58,23 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication,
|
|||
print(errorIndication)
|
||||
return # stop on error
|
||||
if errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
|
||||
return # stop on error
|
||||
for varBindRow in varBindTable:
|
||||
for oid, val in varBindRow:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
return True # signal dispatcher to continue walking
|
||||
return True # signal dispatcher to continue walking
|
||||
|
||||
|
||||
# Prepare initial request to be sent
|
||||
cmdgen.BulkCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
0, 25, # non-repeaters, max-repetitions
|
||||
[ ((1,3,6,1,2,1,1), None),
|
||||
((1,3,6,1,4,1,1), None) ],
|
||||
0, 25, # non-repeaters, max-repetitions
|
||||
[((1, 3, 6, 1, 2, 1, 1), None),
|
||||
((1, 3, 6, 1, 4, 1, 1), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ snmpEngine = engine.SnmpEngine()
|
|||
# This call will fail if PySMI is not present on the system
|
||||
compiler.addMibCompiler(snmpEngine.getMibBuilder())
|
||||
# ... alternatively, this call will not complain on missing PySMI
|
||||
#compiler.addMibCompiler(snmpEngine.getMibBuilder(), ifAvailable=True)
|
||||
# compiler.addMibCompiler(snmpEngine.getMibBuilder(), ifAvailable=True)
|
||||
|
||||
# Used for MIB objects resolution
|
||||
mibViewController = view.MibViewController(snmpEngine.getMibBuilder())
|
||||
|
@ -60,6 +60,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -70,24 +71,23 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
|
||||
# so we ignore noSuchName error here
|
||||
if errorStatus and errorStatus != 2:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
|
||||
return # stop on error
|
||||
for varBindRow in varBindTable:
|
||||
for varBind in varBindRow:
|
||||
print(rfc1902.ObjectType(rfc1902.ObjectIdentity(varBind[0]), varBind[1]).resolveWithMib(mibViewController).prettyPrint())
|
||||
return 1 # signal dispatcher to continue
|
||||
print(rfc1902.ObjectType(rfc1902.ObjectIdentity(varBind[0]),
|
||||
varBind[1]).resolveWithMib(mibViewController).prettyPrint())
|
||||
return 1 # signal dispatcher to continue
|
||||
|
||||
|
||||
# Prepare initial request to be sent
|
||||
cmdgen.NextCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ rfc1902.ObjectType(rfc1902.ObjectIdentity('iso.org.dod')).resolveWithMib(mibViewController),
|
||||
rfc1902.ObjectType(rfc1902.ObjectIdentity('IF-MIB', 'ifMIB')).resolveWithMib(mibViewController) ],
|
||||
[rfc1902.ObjectType(rfc1902.ObjectIdentity('iso.org.dod')).resolveWithMib(mibViewController),
|
||||
rfc1902.ObjectType(rfc1902.ObjectIdentity('IF-MIB', 'ifMIB')).resolveWithMib(mibViewController)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -59,24 +60,22 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
|
||||
# so we ignore noSuchName error here
|
||||
if errorStatus and errorStatus != 2:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
|
||||
return # stop on error
|
||||
for varBindRow in varBindTable:
|
||||
for oid, val in varBindRow:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
return 1 # signal dispatcher to continue
|
||||
return 1 # signal dispatcher to continue
|
||||
|
||||
|
||||
# Prepare initial request to be sent
|
||||
cmdgen.NextCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1), None),
|
||||
((1,3,6,1,4,1,1), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1), None),
|
||||
((1, 3, 6, 1, 4, 1, 1), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ from pysnmp.entity.rfc3413 import cmdgen
|
|||
# Create SNMP engine instance
|
||||
snmpEngine = engine.SnmpEngine()
|
||||
|
||||
|
||||
# Execution point observer setup
|
||||
|
||||
# Register a callback to be invoked at specified execution point of
|
||||
|
@ -41,8 +42,9 @@ def requestObserver(snmpEngine, execpoint, variables, cbCtx):
|
|||
print('* contextName: %s' % variables['contextName'].prettyPrint())
|
||||
print('* PDU: %s' % variables['pdu'].prettyPrint())
|
||||
|
||||
|
||||
snmpEngine.observer.registerObserver(
|
||||
requestObserver,
|
||||
requestObserver,
|
||||
'rfc3412.sendPdu',
|
||||
'rfc3412.receiveMessage:response'
|
||||
)
|
||||
|
@ -76,6 +78,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -83,21 +86,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
if errorIndication:
|
||||
print(errorIndication)
|
||||
elif errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.GetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,1,0), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 1, 0), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -60,26 +61,24 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
print(errorIndication)
|
||||
return
|
||||
if errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
|
||||
return # stop on error
|
||||
for varBindRow in varBindTable:
|
||||
for oid, val in varBindRow:
|
||||
if initialOID.isPrefixOf(oid):
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
else:
|
||||
return False # signal dispatcher to stop
|
||||
return True # signal dispatcher to continue
|
||||
return False # signal dispatcher to stop
|
||||
return True # signal dispatcher to continue
|
||||
|
||||
|
||||
# Prepare initial request to be sent
|
||||
cmdgen.NextCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ (initialOID, None) ],
|
||||
[(initialOID, None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -58,24 +59,22 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
print(errorIndication)
|
||||
return
|
||||
if errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
|
||||
return # stop on error
|
||||
for varBindRow in varBindTable:
|
||||
for oid, val in varBindRow:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
return 1 # signal dispatcher to continue
|
||||
return 1 # signal dispatcher to continue
|
||||
|
||||
|
||||
# Prepare initial request to be sent
|
||||
cmdgen.NextCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1), None),
|
||||
((1,3,6,1,2,1,11), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1), None),
|
||||
((1, 3, 6, 1, 2, 1, 11), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -58,22 +59,20 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
|
||||
# so we ignore noSuchName error here
|
||||
elif errorStatus and errorStatus != 2:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.SetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,9,1,3,1), rfc1902.OctetString('my value')),
|
||||
((1,3,6,1,2,1,1,9,1,4,1), rfc1902.TimeTicks(123)) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 9, 1, 3, 1), rfc1902.OctetString('my value')),
|
||||
((1, 3, 6, 1, 2, 1, 1, 9, 1, 4, 1), rfc1902.TimeTicks(123))],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ config.addTargetAddr(
|
|||
sourceAddress=('1.2.3.4', 0)
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -79,21 +80,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
|
||||
# so we ignore noSuchName error here
|
||||
elif errorStatus and errorStatus != 2:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.GetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,1,0), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 1, 0), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -56,21 +57,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
if errorIndication:
|
||||
print(errorIndication)
|
||||
elif errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.GetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,1,0), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 1, 0), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -57,21 +58,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
if errorIndication:
|
||||
print(errorIndication)
|
||||
elif errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.SetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,9,1,3,1), rfc1902.OctetString('my new value')) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 9, 1, 3, 1), rfc1902.OctetString('my new value'))],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -55,21 +56,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
|
||||
# so we ignore noSuchName error here
|
||||
elif errorStatus and errorStatus != 2:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.GetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,1,0), None) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 1, 0), None)],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ config.addTargetAddr(
|
|||
'my-creds'
|
||||
)
|
||||
|
||||
|
||||
# Error/response receiver
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
||||
|
@ -55,21 +56,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
|
|||
if errorIndication:
|
||||
print(errorIndication)
|
||||
elif errorStatus:
|
||||
print('%s at %s' % (
|
||||
errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex)-1][0] or '?'
|
||||
)
|
||||
)
|
||||
print('%s at %s' % (errorStatus.prettyPrint(),
|
||||
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
|
||||
else:
|
||||
for oid, val in varBinds:
|
||||
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Prepare and send a request message
|
||||
cmdgen.SetCommandGenerator().sendVarBinds(
|
||||
snmpEngine,
|
||||
'my-router',
|
||||
None, '', # contextEngineId, contextName
|
||||
[ ((1,3,6,1,2,1,1,9,1,4,1), rfc1902.TimeTicks(123)) ],
|
||||
[((1, 3, 6, 1, 2, 1, 1, 9, 1, 4, 1), rfc1902.TimeTicks(123))],
|
||||
cbFun
|
||||
)
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ config.addTransport(
|
|||
# SecurityName <-> CommunityName mapping
|
||||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
|
@ -48,19 +49,17 @@ def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
|||
)
|
||||
|
||||
# ... and use inner SNMP engine data to figure out peer address
|
||||
print('Notification from %s, ContextEngineId "%s", ContextName "%s"' % (
|
||||
'@'.join([str(x) for x in execContext['transportAddress']]),
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from %s, ContextEngineId "%s", ContextName "%s"' % ('@'.join([str(x) for x in execContext['transportAddress']]),
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send confirmations
|
||||
try:
|
||||
|
|
|
@ -46,22 +46,21 @@ config.addTransport(
|
|||
# SecurityName <-> CommunityName mapping
|
||||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
varBinds, cbCtx):
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send confirmations
|
||||
try:
|
||||
|
|
|
@ -40,29 +40,28 @@ config.addTransport(
|
|||
snmpEngine,
|
||||
udp6.domainName,
|
||||
udp6.Udp6Transport().openServerMode(('::1', 162))
|
||||
)
|
||||
)
|
||||
|
||||
# SNMPv1/2c setup
|
||||
|
||||
# SecurityName <-> CommunityName mapping
|
||||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
varBinds, cbCtx):
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send confirmations
|
||||
try:
|
||||
|
|
|
@ -87,22 +87,21 @@ config.addV3User(
|
|||
securityEngineId=v2c.OctetString(hexValue='8000000001020304')
|
||||
)
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
varBinds, cbCtx):
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send confirmations
|
||||
try:
|
||||
|
|
|
@ -27,6 +27,7 @@ from pysnmp.entity.rfc3413 import ntfrcv
|
|||
# to socket transport dispatcher
|
||||
snmpEngine = engine.SnmpEngine()
|
||||
|
||||
|
||||
# Execution point observer setup
|
||||
|
||||
# Register a callback to be invoked at specified execution point of
|
||||
|
@ -43,6 +44,7 @@ def requestObserver(snmpEngine, execpoint, variables, cbCtx):
|
|||
print('* contextName: %s' % variables['contextName'].prettyPrint())
|
||||
print('* PDU: %s' % variables['pdu'].prettyPrint())
|
||||
|
||||
|
||||
snmpEngine.observer.registerObserver(
|
||||
requestObserver,
|
||||
'rfc3412.receiveMessage:request',
|
||||
|
@ -63,29 +65,28 @@ config.addTransport(
|
|||
snmpEngine,
|
||||
udp6.domainName,
|
||||
udp6.Udp6Transport().openServerMode(('::1', 162))
|
||||
)
|
||||
)
|
||||
|
||||
# SNMPv1/2c setup
|
||||
|
||||
# SecurityName <-> CommunityName mapping
|
||||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
varBinds, cbCtx):
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send confirmations
|
||||
try:
|
||||
|
|
|
@ -35,7 +35,8 @@ import re
|
|||
# to socket transport dispatcher
|
||||
snmpEngine = engine.SnmpEngine()
|
||||
|
||||
# Register a callback to be invoked at specified execution point of
|
||||
|
||||
# Register a callback to be invoked at specified execution point of
|
||||
# SNMP Engine and passed local variables at execution point's local scope.
|
||||
# If at this execution point passed variables are modified, their new
|
||||
# values will be propagated back and used by SNMP Engine for securityName
|
||||
|
@ -46,6 +47,7 @@ def requestObserver(snmpEngine, execpoint, variables, cbCtx):
|
|||
print('Rewriting communityName \'%s\' from %s into \'public\'' % (variables['communityName'], ':'.join([str(x) for x in variables['transportInformation'][1]])))
|
||||
variables['communityName'] = variables['communityName'].clone('public')
|
||||
|
||||
|
||||
snmpEngine.observer.registerObserver(
|
||||
requestObserver,
|
||||
'rfc2576.processIncomingMsg:writable'
|
||||
|
@ -65,22 +67,21 @@ config.addTransport(
|
|||
# SecurityName <-> CommunityName mapping
|
||||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
varBinds, cbCtx):
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send confirmations
|
||||
try:
|
||||
|
|
|
@ -70,8 +70,7 @@ config.addV1System(snmpEngine, '1-my-area', 'public')
|
|||
# to let it match first in snmpCommunityTable on response processing.
|
||||
#
|
||||
|
||||
config.addV1System(snmpEngine, '0-distant-area', 'public',
|
||||
transportTag='remote')
|
||||
config.addV1System(snmpEngine, '0-distant-area', 'public', transportTag='remote')
|
||||
|
||||
#
|
||||
# Transport target used by Manager
|
||||
|
@ -81,20 +80,21 @@ config.addTargetParams(
|
|||
snmpEngine, 'distant-agent-auth', '0-distant-area', 'noAuthNoPriv', 1
|
||||
)
|
||||
config.addTargetAddr(
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName, ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0, tagList='remote'
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName, ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0, tagList='remote'
|
||||
)
|
||||
|
||||
# Default SNMP context
|
||||
config.addContext(snmpEngine, '')
|
||||
|
||||
|
||||
class CommandResponder(cmdrsp.CommandResponderBase):
|
||||
cmdGenMap = {
|
||||
cmdGenMap = {
|
||||
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
|
||||
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
|
||||
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
}
|
||||
pduTypes = cmdGenMap.keys() # This app will handle these PDUs
|
||||
|
||||
|
@ -105,14 +105,14 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
contextEngineId = None # address authoritative SNMP Engine
|
||||
try:
|
||||
self.cmdGenMap[PDU.tagSet].sendPdu(
|
||||
snmpEngine, 'distant-agent',
|
||||
snmpEngine, 'distant-agent',
|
||||
contextEngineId, contextName,
|
||||
PDU,
|
||||
self.handleResponsePdu, cbCtx
|
||||
)
|
||||
except error.PySnmpError:
|
||||
self.handleResponsePdu(
|
||||
stateReference, 'error', None, cbCtx
|
||||
snmpEngine, stateReference, 'error', None, cbCtx
|
||||
)
|
||||
|
||||
# SNMP response relay
|
||||
|
@ -131,9 +131,10 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
|
||||
self.releaseStateInformation(stateReference)
|
||||
|
||||
|
||||
CommandResponder(snmpEngine, context.SnmpContext(snmpEngine))
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send responses
|
||||
try:
|
||||
|
|
|
@ -79,20 +79,21 @@ config.addTargetParams(snmpEngine, 'distant-agent-auth', 'distant-area',
|
|||
'noAuthNoPriv', 0)
|
||||
|
||||
config.addTargetAddr(
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName + (2,), ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0, tagList='distant'
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName + (2,), ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0, tagList='distant'
|
||||
)
|
||||
|
||||
# Default SNMP context
|
||||
config.addContext(snmpEngine, '')
|
||||
|
||||
|
||||
class CommandResponder(cmdrsp.CommandResponderBase):
|
||||
cmdGenMap = {
|
||||
cmdGenMap = {
|
||||
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
|
||||
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
|
||||
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
}
|
||||
pduTypes = cmdGenMap.keys() # This app will handle these PDUs
|
||||
|
||||
|
@ -103,14 +104,14 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
contextEngineId = None # address authoritative SNMP Engine
|
||||
try:
|
||||
self.cmdGenMap[PDU.tagSet].sendPdu(
|
||||
snmpEngine, 'distant-agent',
|
||||
snmpEngine, 'distant-agent',
|
||||
contextEngineId, contextName,
|
||||
PDU,
|
||||
self.handleResponsePdu, cbCtx
|
||||
)
|
||||
except error.PySnmpError:
|
||||
self.handleResponsePdu(
|
||||
stateReference, 'error', None, cbCtx
|
||||
snmpEngine, stateReference, 'error', None, cbCtx
|
||||
)
|
||||
|
||||
# SNMP response relay
|
||||
|
@ -129,9 +130,10 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
|
||||
self.releaseStateInformation(stateReference)
|
||||
|
||||
|
||||
CommandResponder(snmpEngine, context.SnmpContext(snmpEngine))
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send responses
|
||||
try:
|
||||
|
|
|
@ -79,20 +79,21 @@ config.addTargetParams(
|
|||
snmpEngine, 'distant-agent-auth', 'usr-md5-none', 'authNoPriv'
|
||||
)
|
||||
config.addTargetAddr(
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName + (2,), ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName + (2,), ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0
|
||||
)
|
||||
|
||||
# Default SNMP context
|
||||
config.addContext(snmpEngine, '')
|
||||
|
||||
|
||||
class CommandResponder(cmdrsp.CommandResponderBase):
|
||||
cmdGenMap = {
|
||||
cmdGenMap = {
|
||||
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
|
||||
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
|
||||
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
}
|
||||
pduTypes = cmdGenMap.keys() # This app will handle these PDUs
|
||||
|
||||
|
@ -110,7 +111,7 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
)
|
||||
except error.PySnmpError:
|
||||
self.handleResponsePdu(
|
||||
stateReference, 'error', None, cbCtx
|
||||
snmpEngine, stateReference, 'error', None, cbCtx
|
||||
)
|
||||
|
||||
# SNMP response relay
|
||||
|
@ -129,9 +130,10 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
|
||||
self.releaseStateInformation(stateReference)
|
||||
|
||||
|
||||
CommandResponder(snmpEngine, context.SnmpContext(snmpEngine))
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send responses
|
||||
try:
|
||||
|
|
|
@ -82,20 +82,21 @@ config.addTargetParams(snmpEngine, 'distant-agent-auth', 'my-area',
|
|||
'noAuthNoPriv', 0)
|
||||
|
||||
config.addTargetAddr(
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName + (2,), ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0
|
||||
snmpEngine, 'distant-agent',
|
||||
udp.domainName + (2,), ('195.218.195.228', 161),
|
||||
'distant-agent-auth', retryCount=0
|
||||
)
|
||||
|
||||
# Default SNMP context
|
||||
config.addContext(snmpEngine, '')
|
||||
|
||||
|
||||
class CommandResponder(cmdrsp.CommandResponderBase):
|
||||
cmdGenMap = {
|
||||
cmdGenMap = {
|
||||
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
|
||||
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
|
||||
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
|
||||
}
|
||||
pduTypes = cmdGenMap.keys() # This app will handle these PDUs
|
||||
|
||||
|
@ -106,14 +107,14 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
contextEngineId = None # address authoritative SNMP Engine
|
||||
try:
|
||||
self.cmdGenMap[PDU.tagSet].sendPdu(
|
||||
snmpEngine, 'distant-agent',
|
||||
snmpEngine, 'distant-agent',
|
||||
contextEngineId, contextName,
|
||||
PDU,
|
||||
self.handleResponsePdu, cbCtx
|
||||
)
|
||||
except error.PySnmpError:
|
||||
self.handleResponsePdu(
|
||||
stateReference, 'error', None, cbCtx
|
||||
snmpEngine, stateReference, 'error', None, cbCtx
|
||||
)
|
||||
|
||||
# SNMP response relay
|
||||
|
@ -126,15 +127,14 @@ class CommandResponder(cmdrsp.CommandResponderBase):
|
|||
PDU = v2c.apiPDU.getResponse(reqPDU)
|
||||
PDU.setErrorStatus(PDU, 5)
|
||||
|
||||
self.sendPdu(
|
||||
snmpEngine, stateReference, PDU
|
||||
)
|
||||
self.sendPdu(snmpEngine, stateReference, PDU)
|
||||
|
||||
self.releaseStateInformation(stateReference)
|
||||
|
||||
|
||||
CommandResponder(snmpEngine, context.SnmpContext(snmpEngine))
|
||||
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
|
||||
|
||||
# Run I/O dispatcher which would receive queries and send responses
|
||||
try:
|
||||
|
|
|
@ -43,7 +43,7 @@ config.addTransport(
|
|||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
# Allow read MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1,3,6,5))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1, 3, 6, 5))
|
||||
|
||||
# Create an SNMP context
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
@ -56,6 +56,7 @@ MibScalar, MibScalarInstance = mibBuilder.importSymbols(
|
|||
'SNMPv2-SMI', 'MibScalar', 'MibScalarInstance'
|
||||
)
|
||||
|
||||
|
||||
class MyStaticMibScalarInstance(MibScalarInstance):
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal
|
||||
def getValue(self, name, idx):
|
||||
|
@ -63,9 +64,10 @@ class MyStaticMibScalarInstance(MibScalarInstance):
|
|||
'Python %s running on a %s platform' % (sys.version, sys.platform)
|
||||
)
|
||||
|
||||
|
||||
mibBuilder.exportSymbols(
|
||||
'__MY_MIB', MibScalar((1,3,6,5,1), rfc1902.OctetString()),
|
||||
MyStaticMibScalarInstance((1,3,6,5,1), (0,), rfc1902.OctetString())
|
||||
'__MY_MIB', MibScalar((1, 3, 6, 5, 1), rfc1902.OctetString()),
|
||||
MyStaticMibScalarInstance((1, 3, 6, 5, 1), (0,), rfc1902.OctetString())
|
||||
)
|
||||
|
||||
# --- end of Managed Object Instance initialization ----
|
||||
|
|
|
@ -48,7 +48,7 @@ config.addTransport(
|
|||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
# Allow full MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -44,8 +44,8 @@ config.addV1System(snmpEngine, 'my-read-area', 'public')
|
|||
config.addV1System(snmpEngine, 'my-write-area', 'private')
|
||||
|
||||
# Allow full MIB access for this user / securityModels at VACM
|
||||
config.addVacmUser(snmpEngine, 1, 'my-read-area', 'noAuthNoPriv', (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-write-area', 'noAuthNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-read-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 1, 'my-write-area', 'noAuthNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -60,9 +60,9 @@ config.addV3User(
|
|||
)
|
||||
|
||||
# Allow full MIB access for each user at VACM
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
|
||||
|
||||
# Get default SNMP context this SNMP engine serves
|
||||
snmpContext = context.SnmpContext(snmpEngine)
|
||||
|
|
|
@ -49,18 +49,17 @@ config.addTransport(
|
|||
# SecurityName <-> CommunityName mapping
|
||||
config.addV1System(snmpEngine, 'my-area', 'public')
|
||||
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
varBinds, cbCtx):
|
||||
print('Notification from ContextEngineId "%s", Context "%s"' % (
|
||||
contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from ContextEngineId "%s", Context "%s"' % (contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
|
|
|
@ -88,19 +88,19 @@ config.addV3User(
|
|||
securityEngineId=rfc1902.OctetString(hexValue='8000000001020304')
|
||||
)
|
||||
|
||||
|
||||
# -- end of SNMPv3/USM setup
|
||||
|
||||
# Callback function for receiving notifications
|
||||
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
|
||||
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
|
||||
varBinds, cbCtx):
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (
|
||||
contextEngineId.prettyPrint(), contextName.prettyPrint()
|
||||
)
|
||||
)
|
||||
print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
|
||||
contextName.prettyPrint()))
|
||||
for name, val in varBinds:
|
||||
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
|
||||
# Register SNMP Application at the SNMP engine
|
||||
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
|
||||
|
||||
|
|
Loading…
Reference in New Issue