Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, there's an already written <a href="http://pypi.python.org/pypi/snmp-passpersist" rel="nofollow">snmp-passpersist Python module</a> specifically for this task. Its page has a link to a real-world usage example. An example code for your case is below.</p> <p>Regarding your specific questions: </p> <ol> <li><p>The description of <code>getnext</code> is indeed notoriously unclear in both specification and wikipedia. It is explained well in <a href="http://www.net-snmp.org/wiki/index.php/TUT%3asnmpgetnext" rel="nofollow">TUT:snmpgetnext - Net-SNMP Wiki</a>.<br/><br/> In brief, it retrieves <em>the first valid OID</em> (and its value) <em>that goes after the specified one in the agent's hierarchy</em>. The "hierarchy" here can be represented as an ordered list of all OIDs the agent knows of that are valid at the moment.</p> <ul> <li>There are two major use cases for this: <ol> <li>The response <em>contains the OID</em> of that "next" value as well as the value itself. So you can <em>walk the hierarchy</em> at the agent by using returned OIDs in subsequent requests. The agent is supposed to return the "not found" error (and <code>pass_persist</code> handler - <code>"NONE"</code>) when the hierarchy is exhausted.</li> <li>You can <em>specify an incomplete OID</em> too, and the agent is supposed to return <em>the first complete one it knows of</em> that matches the one provided.</li> </ol></li> <li>At packet level, <code>getnext</code> is indeed different from <code>get</code> too (its request type ID is <code>1</code>, <code>get</code>'s is <code>0</code>).</li> <li>You might want to ignore this "magic" altogether and handle it the same way as <code>get</code>: this only means that "walking" and "guessing" will not work (walking might loop indefinitely). This is how a handler I maintained at my last occupation worked <strong>and this is just what is happening in your present code too :^)</strong>.</li> <li><ul> <li>So, the fix is simple: <code>getFileLine(int(sub_oid)+1, lines)</code> - since your code is already smart enough to return <code>"NONE"</code> on exhaustion. "Guessing" will still not work, but... do you need it?</li> </ul></li> </ul></li> <li><p><code>net-snmpd</code> has a plethora of logging options - search "log" on <a href="http://www.net-snmp.org/docs/man/snmpd.html" rel="nofollow">its manpage</a> (and, hell, it's free software! you can always consult or even debug the source when all else fails). But in this particular case, logging stdin and stdout while giving queries with <code>snmpget</code>/<code>snmpgetnext</code> and/or using sniffer is more than enough.</p></li> </ol> <p>With the aforementioned <code>snmp-passpersist</code>, your code boils down to:</p> <pre><code>base_oid=".1.3.6.1.4.1..[snip]" data_file="&lt;path&gt;" import snmp_passpersist as snmp pp=snmp.PassPersist(base_oid) for l in (l.rstrip() for l in open(data_file)): pp.add_int(l,int(l)) pp.start(user_func=lambda:True,refresh=1800) # If data updates are needed, # replace lambda with a real fn # and adjust refresh (sec) </code></pre> <p>If you need to monitor changes to the file, you can either poll it (like the comment above suggests to) or (in Linux) use something like <a href="https://github.com/seb-m/pyinotify/wiki" rel="nofollow">pyinotify</a> - in this case, you'll probably need to replace <code>pp.main_update()</code> before calling <code>pp.start()</code> or otherwise patch up the module's machinery somehow.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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