diff options
author | elie <elie> | 2015-01-07 10:28:09 +0000 |
---|---|---|
committer | elie <elie> | 2015-01-07 10:28:09 +0000 |
commit | a0fd414a38cc6cf7d342974eea9a0f8f9d55799a (patch) | |
tree | f3d178aeaa91fb008a31c04ac5c82ffe2568cae3 | |
parent | ed42a1ddf7f8160085866f9726d62c2005376056 (diff) | |
download | pysnmp-a0fd414a38cc6cf7d342974eea9a0f8f9d55799a.tar.gz |
first attempt to make SNMP Engine settings persistent across reboots
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | pysnmp/entity/engine.py | 36 |
2 files changed, 37 insertions, 1 deletions
@@ -62,6 +62,8 @@ Revision 4.2.6rc0 startup time. - Multiple fixes to verify pyasn1 decoder.decode() return to withstand broken SNMP messages or its components. +- First attempt made to make some of SNMP Engine settings persistent + across reboots. - Fix to authoritative engine side snmpEngineID discovery procedure: respond with notInTimeWindows rather then with unsupportedSecurityLevel at time synchronization phase. diff --git a/pysnmp/entity/engine.py b/pysnmp/entity/engine.py index a497e48..6076e19 100644 --- a/pysnmp/entity/engine.py +++ b/pysnmp/entity/engine.py @@ -1,4 +1,6 @@ # SNMP engine +import os +import tempfile from pysnmp.proto.rfc3412 import MsgAndPduDispatcher from pysnmp.proto.mpmod.rfc2576 import SnmpV1MessageProcessingModel, \ SnmpV2cMessageProcessingModel @@ -8,6 +10,7 @@ from pysnmp.proto.secmod.rfc2576 import SnmpV1SecurityModel, \ from pysnmp.proto.secmod.rfc3414 import SnmpUSMSecurityModel from pysnmp.proto.acmod import rfc3415, void from pysnmp.entity import observer +from pysnmp import debug from pysnmp import error class SnmpEngine: @@ -50,9 +53,40 @@ class SnmpEngine: snmpEngineBoots, = self.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('__SNMP-FRAMEWORK-MIB', 'snmpEngineBoots') snmpEngineBoots.syntax = snmpEngineBoots.syntax + 1 origSnmpEngineID, = self.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('__SNMP-FRAMEWORK-MIB', 'snmpEngineID') + if snmpEngineID is not None: origSnmpEngineID.syntax = origSnmpEngineID.syntax.clone(snmpEngineID) - self.snmpEngineID = origSnmpEngineID.syntax + self.snmpEngineID = origSnmpEngineID.syntax + + debug.logger & debug.flagApp and debug.logger('SnmpEngine: using custom SNMP Engine ID: %s' % self.snmpEngineID.prettyPrint()) + + # Attempt to make some of snmp Engine settings persistent. + # This should probably be generalized as a non-volatile MIB store. + + persistentPath = os.path.join(tempfile.gettempdir(), '__pysnmp', self.snmpEngineID.prettyPrint()) + + debug.logger & debug.flagApp and debug.logger('SnmpEngine: using persistent directory: %s' % persistentPath) + + if not os.path.exists(persistentPath): + try: + os.makedirs(persistentPath) + except OSError: + return + + f = os.path.join(persistentPath, 'boots') + try: + snmpEngineBoots.syntax = snmpEngineBoots.syntax.clone(open(f).read()) + except: + pass + + snmpEngineBoots.syntax = snmpEngineBoots.syntax + 1 + + try: + open(f, 'w').write(snmpEngineBoots.syntax.prettyPrint()) + except: + pass + + debug.logger & debug.flagApp and debug.logger('SnmpEngine: stored SNMP Engine Boots: %s' % snmpEngineBoots.syntax.prettyPrint()) # Transport dispatcher bindings |