i had been searching way use pysnmp dynamically update snmp table during snmp agent running. far no luck...
the table had been defined in mib file(see below), seems need overwrite "readget()" method in order return correct data current system status.
according instructions http://pysnmp.sourceforge.net/examples/v3arch/asyncore/agent/cmdrsp/agent-side-mib-implementations.html#implementing-conceptual-table
i'm able build static table pre-defined value before snmp agent startup, , after snmp agent startup:
# register imaginary never-ending job keep i/o dispatcher running forever self.snmpengine.transportdispatcher.jobstarted(1) # run i/o dispatcher receive queries , send responses try: self.snmpengine.transportdispatcher.rundispatcher() except: self.snmpengine.transportdispatcher.closedispatcher() raise
it able return expected value.
but system, dynamically generate many alarm information, , information need updated snmp's mib table, allow other snmp manager send "get/getnext" fetch alarm information system.
so know
- is there way in pysnmp?
- or have update alarm table statically? , restart snmp agent after each update action?
- or have initialize alarm table possible 2147483647 instances during snmp agent startup? , use "name[-1]" index/row number each query?
if so, how getnext query? ignore empty table row? or return next one, dummy one?
- or there better way fetch "index/row" number query message?
@ilya etingof, expert of pysnmp. me if have time?
br, -dapeng jiao
1.
mib file definition of alarm table (some sensitive info removed)
alarmtable = mibtable((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3)) alarmentry = mibtablerow((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1)).setindexnames((0, "my-mib", "alarmindex")) alarmindex = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 1), integer32().subtype(subtypespec=valuerangeconstraint(1, 2147483647))).setmaxaccess("readonly") alarmid = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 2), integer32().subtype(subtypespec=valuerangeconstraint(1, 2147483647))).setmaxaccess("readonly") alarmname = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 3), displaystring().subtype(subtypespec=valuesizeconstraint(0, 255))).setmaxaccess("readonly") alarmseverity = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 4), alarmseverity()).setmaxaccess("readonly") alarmtime = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 5), dateandtime()).setmaxaccess("readonly") alarmtype = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 6), alarmtype()).setmaxaccess("readonly") alarmsource = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 7), displaystring().subtype(subtypespec=valuesizeconstraint(0, 255))).setmaxaccess( "readonly") alarmcategory = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 8), displaystring().subtype(subtypespec=valuesizeconstraint(0, 255))).setmaxaccess("readonly") alarmprobablecause = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 9), probablecause()).setmaxaccess("readonly") alarmcomparable = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 10), displaystring().subtype(subtypespec=valuesizeconstraint(0, 255))).setmaxaccess("readonly") alarmadditionaltext = mibtablecolumn((1, 3, 6, *, *, *, *, *, *, *, *, *, , 3, 1, 11), displaystring().subtype(subtypespec=valuesizeconstraint(0, 255))).setmaxaccess("readonly")
it possible maintain dynamic snmp table pysnmp. there many approaches problem:
periodically update table (via table callback or dedicated thread) calling
mibinstrumentation.writevars
in this example script. backsides includes delays in serving new data , queries if come @ moment of running update. no coding required.extend
mibtablecolumn
class , implementreadget
/readgetnext
methods data when being called , return oid/value pair. complication here handle getnext query need maintain sort of consistent ordering of oids , search next greater given.ditch whole pysnmp's smi infrastructure , implement own mib controller on top of whatever data source have read data from. need implement
readget
(easy) ,readgetnext
(more complicated stable oids sort required) methods. way relief learning details of rather generic , complicated pysnmp smi implementation , focus on minimal requirements.
to answer other questions:
- it not idea restart service update date serving.
- you may update dynamically (timer callback or thread) unless have many (2^31) rows in snmp table. if more few hundreds way keep alarm data now, read when query comes , build snmp response it.
- the knowledge of part of oid belongs snmp table index belongs
mibtablerow
,mibtablecolumn
classes. if extend them figure out. there helper methods purpose though.
Comments
Post a Comment