-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysinform.py
65 lines (56 loc) · 1.81 KB
/
sysinform.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
#!/usr/bin/python
###############################################################################
#
# SysInfoRM - System Information Remote Monitoring
#
###############################################################################
#
# TODO: Set License
# TODO: Use assertions and other error handling.
# TODO: Introduce methods and classes.
import urllib2 # http://www.voidspace.org.uk/python/articles/urllib2.shtml#{{{
import time
import amara
from amara import bindery
from xml.parsers.xmlproc import xmlproc
from xml.parsers.xmlproc import xmlval
from xml.parsers.xmlproc import xmldtd
from pprint import pprint
#}}}
# XML Structure Checking # {{{
class MyApp(xmlproc.Application):
def handle_start_tag(self,name,attrs):
pass
def handle_end_tag(self,name):
pass
def handle_data(self,data,start,end):
pass
def handle_comment(self,data):
pass
# }}}
configXML = bindery.parse('config.xml');
config = configXML.SysInfoRM;
try:
while (1):
for host in config.Hosts.host:
print "Checking %s SysInfo XML" % host.name;
print host.sysinfourl;
# TODO: Validate that URL is Valid
req = urllib2.Request(
str(host.sysinfourl),
{},
{'User-Agent' : str(config.Config.UserAgent), 'Accept' : 'text/xml'}
);
sysInfoXML = urllib2.urlopen(req).read();
p = xmlproc.XMLProcessor();
p.set_application(MyApp());
if (str(p.parse_string(sysInfoXML)) == 'None'):
# TODO: Validate that reutrned data is both XML and valid.
sysInfo = bindery.parse(sysInfoXML);
print sysInfo.phpsysinfo.Vitals.IPAddr;
# Now match against rules and checks in config XML
else:
sys.stderr.write('Error XML structure invalid');
time.sleep (30); # This is just for testing final version will monitor timing in another thread
except (KeyboardInterrupt, SystemExit):
print 'Exiting SysInfoRM';