[pysnmp-users] varbind persistence in my trap object?
Brought to you by:
elie
From: Pete K. <pet...@ka...> - 2003-07-31 22:04:42
|
A list for users of pure-Python SNMP framework <pysnmp-users.lists.sourceforge.net> List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/pysnmp-users>, <mailto:pys...@li...?subject=unsubscribe> List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum=pysnmp-users> Hi! First, thanks for writing this library! I can't tell you how much more I prefer using a pure python library than some wrapper around net-snmp! Now my question :-) I have a long running process that periodically fires v2c traps. Based on the examples and documentation, it appears that there are two ways of sending a trap. This is what I am doing now (it works): trap = v2c.TRAP() encoded_oids = [] encoded_vals = [] [add the encoded oids and vals] host.send(trap.encode(encoded_oids=encoded_oids, encoded_vals=encoded_vals)) This is what I first tried, but was never able to get working because each time a trap was fired, the trap contained all of the varbinds from the previous trap (i.e. they kept appending): def add_varbind(trap, oid, val): trap['encoded_oids'].append(oid) trap['encoded_vals'].append(val) trap = v2c.TRAP() [add the encoded oids and vals using 'add_varbind(trap, oid, val)' function] encoded_trap = trap.encode() host.send(encoded_trap) This never worked; yet I am not sure why because I create myself a new trap object each time a trap is fired and I stuff it with the appropriate values. Clearly, I am using the API wrong. I searched for a method to clear the object state (trap.clear() didn't work). My questions are: 1) Should I just abandon the second approach? Or am I just using the API incorrectly in this case? 2) In both examples above, the 'host' object (created from role.manager()) is created once in the lifetime of the program. Is it safe to use this object multiple times for each trap that I send? Thanks for the help! Please CC me directly as I am not a subscriber yet. Thanks, Pete |