forked from wungad/isc-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacti_script.py
executable file
·46 lines (39 loc) · 967 Bytes
/
cacti_script.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
#!/usr/bin/env python
import urllib
import json
import sys
class Cacti(object):
'''
Helper class for formatted output
'''
@staticmethod
def print_dict(stats_dict):
'Prints python dict in cacti-understandable script output format'
for k,v in sorted(stats_dict.items()):
print '%s:%s' % (k.upper(), v),
class App(object):
'''
Main class
'''
stats_dict = {
'discover': 0,
'offer': 0,
'request': 0,
'ack': 0,
'nak': 0
}
@staticmethod
def main():
'''
Main method
'''
try:
App.stats_dict = json.loads(urllib.urlopen(App.stats_url).read())
except IOError:
pass
finally:
Cacti.print_dict(App.stats_dict)
if __name__ == '__main__':
try: App.stats_url = sys.argv[1]
except IndexError: sys.exit('Usage: %s <stats-daemon-url>' % __file__)
App.main()