Open HarelAshwal opened 7 years ago
Depending on which SNMP error you are trying to convey to the client, you should only raise exceptions based on the pysnmp.smi.error.SmiError
class. For example NotWritableError
or NoAccessError
.
Also note that it is generally cheaper to fail in the writeTest()
method which is called for every variable in the SET request prior to writeCommit
. That's because if you fail in writeCommit()
, the rest of the variables in the SET query that were "set" prior to the failure would have to be "unset".
Here is a baseline implementation for your reference.
LK"I
Thanks for the quick replay. here is my code:
main function to start the agent: def serve_forever(self): print "Starting agent" self._snmpEngine.transportDispatcher.jobStarted(1) try: self._snmpEngine.transportDispatcher.runDispatcher() except: self._snmpEngine.transportDispatcher.closeDispatcher() raise
and the writeTest: (raising the ValueConstraintError from SmiError)
def writeTest(self, name, idx, acInfo, *args):
print " Testing var..."
raise error.ValueConstraintError()
but it still just fails and stops the snmp engine:
Testing var...
Traceback (most recent call last):
File "C:\projects_node\CompleteDemo\SNMP\SNMP.py", line 265, in
Press any key to continue . . .
Hi All,
I'm having a SET Sequence with SNMP using the writeCommit method:
def writeCommit(self, name, val, *args):
print " Setting var..." obj = setValue(fullPath,val)
if (obj == 'err') : raise 'some error'
I'm trying to fail the write sequence in case the set operation didn't passed OK. but, when i'm raising an error the entire agent is stopping. how do i do that? how do i inform the SNMP client the set operation failed without stopping the agent?