forked from gbit-is/Jymon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jymon.py
executable file
·64 lines (40 loc) · 1.63 KB
/
jymon.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
#!/usr/bin/env python
# Import requirements
import commands # Needed to run the xymon-client
import json # JSON is needed for this JSON based project, surprise
message_list = []; #Initalise list
xymon_client = "/usr/lib/xymon/client/bin/xymon" # Location of the xymon client
xymon_server = "xymonserver.intra" # URL of the Xymon Server
xymon_board = "xymondboard" # name of the board, defaults are hobbitdboard or xymondboard (notice the d in there)
status, messages = commands.getstatusoutput(xymon_client + " " + xymon_server + " " + xymon_board) # Run xymon client
messages = messages.decode('utf-8','ignore').encode("utf-8") # Let's just get rid of those pesky non-utf character
for line in messages.split('\n'): # Lets get to parsing the xymon data, split by newline seperators
data = line.split('|') # the xymon client sends each data field with a | seperator
# Let's assign the data to variables
hostname = data[0]
testname = data[1]
testcolor = data[2]
testflags = data[3]
lastchange = data[4]
logtime = data[5]
validtime = data[6]
acktime = data[7]
disabledtime = data[8]
sender = data[9]
# And populate a json with those variables
parsed_data = {
'hostname' : hostname,
'testname' : testname,
'testcolor' : testcolor,
'testflags' : testflags,
'lastchange' : lastchange,
'logtime' : logtime,
'validtime' : validtime,
'acktime' : acktime,
'disabledtime' : disabledtime,
'sender' : sender
}
message_list.append(parsed_data) # Then add those variables to the list
# Once all the responses have been parsed
print json.dumps(message_list) # Print out the JSON
exit()