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 problem #2

Open
korwin7474 opened this issue Jun 7, 2019 · 4 comments
Open

writeCommit problem #2

korwin7474 opened this issue Jun 7, 2019 · 4 comments

Comments

@korwin7474
Copy link

Im managing a variable that can assume '0' or '1' value.
if generic mib browser try to set '3' an exception make the agent crash.
of course i can try-except that, but im not able to send to client (mib browser) the error.
Thats the code on my pythonized mib:

def writeTest(self, varBind, **context):
    cbFun = context['cbFun']
    name, value = varBind
    if value in [0,1]:
        cbFun(varBind, **context)
    else:
        pass


def writeCommit(self, varBind, **context):
    # Put your code here
    print("arrivato al write commit")
    cbFun = context['cbFun']
    name, value = varBind
    cbFun((name, value), **context)
    my_agent.setcConnection(value)

can anyone help me?
Thanks

@etingof
Copy link
Owner

etingof commented Jun 7, 2019

One thing is that you should always call cbFun. Otherwise internal state machine stalls.

To indicate an error you should add error key to **context. That should stop and rollback the whole request, then report SNMP error back to the browser.

@korwin7474
Copy link
Author

Thank you, Ilya, I've updated my writeTest method as reported.

def writeTest(self, varBind, **context):
    print("status n.1",context['status'])
    cbFun = context['cbFun']
    name, value = varBind
    my_test = not( value in [0,1] )
    try:
        self.getOK(my_test,name,**context)
    except (pysnmp.smi.error.WrongValueError) as exc:
        context = dict(dict(context, error=exc))
        cbFun(varBind, **context) 
        print("status n.2",context['status'])
    else:
        print("test OK")
        cbFun(varBind, **context)
    print("status n.3",context['status'])

If i try (using mib browser) to set an out of range value (i.e. "3") the varialble is correctly not updated, but mib browser get timed out in response.
Context status :
status n.1 ok
status n.2 ok
status n.3 ok
but, i expected to read "status n.2 err"

Thank you for helping me.

@etingof
Copy link
Owner

etingof commented Jun 10, 2019

Looking at the code, I am guessing that may be something is missing to respond an error back... I wonder if you could run snmpresponder with debugging enabled to see where the request ends up. That would be helpful.

@korwin7474
Copy link
Author

that's what i can't understand:
.....
2019-06-20 17:05:26,366 flipFlopFsm: state writeCleanup status err -> transitioned into state stop
2019-06-20 17:05:26,370 sendVarBinds: stateReference 15457236, errorStatus 0, errorIndex 0, varBinds
.....

The status looks to pass from error to OK.

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