forked from hosthvo/pyagentx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·69 lines (48 loc) · 1.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
"""
Rayed Alrashed 2013-10-09
AgentX sub agent library
To help debugging run snmpd in foreground debug mode:
sudo /usr/sbin/snmpd -f -Lsd -Dagentx -Le -u snmp -g snmp -I -smux -p /var/run/snmpd.pid
snmpget -v2c -c public localhost .1.3.6.1.3.9999.100.1.0
snmpwalk -v2c -c public localhost .1.3.6.1.3.9999
"""
import logging
import time
import pyagentx
from pyagentx.pdu import PDU
from pyagentx.agent import Agent
class MyAgent(Agent):
def setup(self):
self.register('1.3.6.1.3.9999.100', self.update)
self.register('1.3.6.1.3.9999.200', self.update2, 10)
def update(self):
self.append('1.0', pyagentx.TYPE_COUNTER32, 1000)
self.append('2.0', pyagentx.TYPE_COUNTER32, 2000)
self.append('3.0', pyagentx.TYPE_OCTETSTRING, "String for 100 MIB")
def update2(self):
self.append('1.0', pyagentx.TYPE_COUNTER32, int(time.time()))
self.append('2.0', pyagentx.TYPE_COUNTER32, 2000)
self.append('3.0', pyagentx.TYPE_OCTETSTRING, "String for 200 MIB")
def setup_login():
logger = logging.getLogger('pyagentx')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
def main():
setup_login()
a = MyAgent()
try:
#a.debug = 0
a.start()
except:
#exiting main loop'
pass
finally:
# call stop to end all async registred threads
a.stop()
if __name__=="__main__":
main()