Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writecommit failed #77

Open
HarelAshwal opened this issue Aug 31, 2017 · 2 comments
Open

writecommit failed #77

HarelAshwal opened this issue Aug 31, 2017 · 2 comments

Comments

@HarelAshwal
Copy link

HarelAshwal commented Aug 31, 2017

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?

@etingof
Copy link
Owner

etingof commented Aug 31, 2017

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.

@HarelAshwal
Copy link
Author

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
agent.serve_forever()
File "C:\projects_node\CompleteDemo\SNMP\SNMP.py", line 193, in serve_forever
self._snmpEngine.transportDispatcher.runDispatcher()
File "C:\Python27\lib\site-packages\pysnmp\carrier\asyncore\dispatch.py", line
49, in runDispatcher
raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))
)
PySnmpError: poll error: Traceback (most recent call last):
; File "C:\Python27\lib\site-packages\pysnmp\carrier\asyncore\dispatch.py", lin
e 45, in runDispatcher
use_poll=True, map=self.__sockMap, count=1)
; File "C:\Python27\lib\asyncore.py", line 220, in loop
poll_fun(timeout, map)
; File "C:\Python27\lib\asyncore.py", line 156, in poll
read(obj)
; File "C:\Python27\lib\asyncore.py", line 87, in read
obj.handle_error()
; File "C:\Python27\lib\asyncore.py", line 83, in read
obj.handle_read_event()
; File "C:\Python27\lib\asyncore.py", line 449, in handle_read_event
self.handle_read()
; File "C:\Python27\lib\site-packages\pysnmp\carrier\asyncore\dgram\base.py", l
ine 157, in handle_read
self._cbFun(self, transportAddress, incomingMessage)
; File "C:\Python27\lib\site-packages\pysnmp\carrier\base.py", line 68, in _cbF
un
self, transportDomain, transportAddress, incomingMessage
; File "C:\Python27\lib\site-packages\pysnmp\entity\engine.py", line 145, in __
receiveMessageCbFun
self, transportDomain, transportAddress, wholeMsg
; File "C:\Python27\lib\site-packages\pysnmp\proto\rfc3412.py", line 407, in re
ceiveMessage
PDU, maxSizeResponseScopedPDU, stateReference)
; File "C:\Python27\lib\site-packages\pysnmp\entity\rfc3413\cmdrsp.py", line 13
3, in processPdu
(self.__verifyAccess, snmpEngine))
; File "C:\Python27\lib\site-packages\pysnmp\entity\rfc3413\cmdrsp.py", line 31
7, in handleMgmtOperation
(acFun, acCtx)))
; File "C:\Python27\lib\site-packages\pysnmp\smi\instrum.py", line 250, in writ
eVars
return self.flipFlopFsm(self.fsmWriteVar, vars, acInfo)
; File "C:\Python27\lib\site-packages\pysnmp\smi\instrum.py", line 218, in flip
FlopFsm
rval = f(tuple(name), val, idx, acInfo)
; File "c:\users\ashwalh\appdata\local\temp\pip-build-iibrk4\pysnmp\pysnmp\smi
mibs\SNMPv2-SMI.py", line 470, in writeTest
; File "c:\users\ashwalh\appdata\local\temp\pip-build-iibrk4\pysnmp\pysnmp\smi
mibs\SNMPv2-SMI.py", line 570, in writeTest
; File "c:\users\ashwalh\appdata\local\temp\pip-build-iibrk4\pysnmp\pysnmp\smi
mibs\SNMPv2-SMI.py", line 470, in writeTest
; File "C:\projects_node\CompleteDemo\SNMP\SNMP.py", line 87, in writeTest
raise error.ValueConstraintError()
;ValueConstraintError

Press any key to continue . . .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants