Permalink
Browse files

Add increment method to asntypes COUNTER and COUNTER64

  • Loading branch information...
1 parent da08641 commit 7d3d7058c01d09086b8ecc85f443cd709f1b1ec3 @kwirk kwirk committed with Mar 5, 2013
Showing with 8 additions and 2 deletions.
  1. +4 −2 example_agent.py
  2. +4 −0 netsnmpagent.py
View
@@ -221,7 +221,9 @@ def HupHandler(signum, frame):
exampleCounter32.update(exampleCounter32.value() + 2)
exampleCounter64.update(exampleCounter64.value() + 4294967294)
exampleTimeTicks.update(exampleTimeTicks.value() + 1)
- exampleCounter32Context2.update(exampleCounter32Context2.value() + 1)
- exampleCounter64Context2.update(exampleCounter64Context2.value() + 1)
+
+ # With counters, you can also increment them
+ exampleCounter32Context2.increment() # By 1
+ exampleCounter64Context2.increment(5) # By 5
print "{0}: Terminating.".format(prgname)
View
@@ -274,6 +274,10 @@ def update(self, val):
self._cvar.value = val
self._data_size = len(val)
+ if props["asntype"] in [ASN_COUNTER, ASN_COUNTER64]:
+ def increment(self, count=1):
+ self.update(self.value() + count)
+
cls.__name__ = property_func.__name__
# Return an instance of the just-defined class to the agent

0 comments on commit 7d3d705

Please sign in to comment.