Note that there are some explanatory texts on larger screens.

plurals
  1. POproper getnext logic in a pass_persist handler
    text
    copied!<p>I'm working on a small script that'll act as an snmp pass_persist handler. I want it to read a file in (called 'numbers', for now in the same dir) which just contains some integers and return these as an oid tree. </p> <p>I've been stuck on this for a few days now, and I realise now it's due to a <em>fundamental misunderstanding</em> of how snmpd works. I'm using the snmpd.conf man page which makes no mention of any difference in how 'get' and 'getnext' requests are to be handled, but I assume there is one. I can't for the life of me get snmpwalk to work with this script.</p> <p>Could someone who knows a little more about snmp look this code over ? I've seen several other versions of pass scripts, including a few in python but I've not been able to see from looking at the code how they handle the protocol differently to my code. I saw one implementation that handled a blank command ( '' ), but others that apparently didn't.</p> <p>Basically, I'm pretty confused at this point ! - It's also proving pretty hard to debug snmpd as it's the one calling my script, not me. I'm logging what i can, and running snmpd in the foreground, but other than that it's all a bit "black-box".</p> <p>Can anyone shed some light ?</p> <p>i.e: numbers file:</p> <pre> 101 102 103 I want returned as: .1.3.6.1.4.1..[snip]..1 = 101 .1.3.6.1.4.1..[snip]..2 = 102 .1.3.6.1.4.1..[snip]..3 = 103 </pre> <p>My script (I'm not worried about returning anything other than integers, and i know the file close will never be reached, but it makes me feel better):</p> <pre><code> #!/bin/python -u import os,sys, syslog def getLine(): return sys.stdin.readline().strip() def getFileLine(sub_oid, lines): sub_oid = int(sub_oid) if sub_oid >= len(lines): return 'NONE' else: return lines[sub_oid] def printOutput(oid, var_type, varbind_value): if varbind_value == 'NONE': print 'NONE' else: print oid print var_type print varbind_value ###################################################### sub_oid = 0 FH = open('numbers','r') lines = FH.readlines() while True: command = getLine() syslog.syslog("command: %s" % command) if command == 'PING': syslog.syslog('got a ping') print 'PONG' elif command == 'get': given_oid = getLine() sub_oid = int(given_oid.split('.')[-1]) varbind_value = getFileLine(sub_oid, lines) printOutput(given_oid, 'integer', varbind_value.strip()) elif command == 'getnext': given_oid = getLine() syslog.syslog("got a requested oid of: %s" % given_oid) sub_oid = int(given_oid.split('.')[-1]) varbind_value = getFileLine(sub_oid, lines) printOutput(given_oid, 'integer', varbind_value.strip()) else: syslog.syslog("Unknown command: %s" % command) FH.close() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload