This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
live.py.old
107 lines (87 loc) · 3.78 KB
/
live.py.old
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python
#
socket_path = "/opt/monitor/var/rw/live"
import operator
import ConfigParser
parser = ConfigParser.ConfigParser()
import socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(socket_path)
# Write command to socket
s.send("GET hosts\nColumns: name groups state acknowledged num_services_hard_ok num_services_hard_unknown num_services_hard_warn num_services_hard_crit\n")
# Important: Close sending direction. That way
# the other side knows, we are finished.
s.shutdown(socket.SHUT_WR)
# Now read the answer
answer = s.recv(1000000000)
# Parse the answer into a table (a list of lists)
table = [ line.split(';') for line in answer.split('\n')[:-1] ]
def matching_servers(import_text):
temp_list = []
import_table = import_text.split(',')
for i in range(0, len(table)):
if len(import_table) == len(set(table[i][1].split(',')) & set(import_table)):
temp_list.append(table[i])
temp_list.sort(key=operator.itemgetter(5), reverse=True)
temp_list.sort(key=operator.itemgetter(6), reverse=True)
temp_list.sort(key=operator.itemgetter(7), reverse=True)
temp_list.sort(key=operator.itemgetter(2), reverse=True)
return temp_list
def is_error(host_error):
host_ok = '<div class="ok"><img src="icons/shield-ok.png"></img>'
host_down = '<div class="critical_host"><img src="icons/shield-error-host.png"></img>'
service_crit = '<div class="critical"><img src="icons/shield-error.png"></img>'
service_warn = '<div class="warning"><img src="icons/shield-warning.png"></img>'
service_unknown = '<div class="unknown"><img src="icons/shield-unknown.png"></img>'
if host_error[2] == 1:
return host_down
elif host_error[7] >= 1:
return service_crit
elif host_error[6] >= 1:
return service_warn
elif host_error[5] >= 1:
return service_unknown
else:
return host_ok
# Read from a file containing most of the html code such as stylesheets and so forth.
def painting_base():
return None
# Creating all the html code for the rows.
def painting_rows():
return None
# Insert hosts in the rows, check for status of the first host and ad apropriate image from that.
def painting_hosts():
return None
def main():
parser.read('live.conf')
row_list = []
hostgrp_list = []
for i in range(0, len(parser.sections())):
if parser.sections()[i].startswith('row'):
row_list.append([parser.sections()[i],parser.get(parser.sections()[i],'title')])
else:
hostgrp_list.append([parser.get(parser.sections()[i],'row'),parser.sections()[i],matching_servers(parser.get(parser.sections()[i],'groups'))])
# print row_list
# print hostgrp_list
start_html = open('start.html', 'r').read()
end_html = open('end.html', 'r').read()
div_list = []
script_list = []
for i in range(0, len(row_list)):
div_list.append(['<div class="positionDiv" id="', row_list[i][0],'">\n<div class="group">', row_list[i][1],'</div>\n'])
if i == 0:
script_list.append(['<script>\n $( "#', row_list[i][0], ' ).position({ my: "left+30 top+10", at: "left top", of: "#main" });'])
else:
script_list.append(['<script>\n $( "#', row_list[i][0], ' ).position({ my: "left+10 top", at: "left top", of: "#', row_list[i-1][0], '" });'])
for i in range(0, len(hostgrp_list)):
for j in range(0, len(div_list)):
if hostgrp_list[i][0] == div_list[j][1]:
div_list[j].append(is_error(hostgrp_list[i][2][0]))
div_list[j].append(hostgrp_list[i][1])
div_list[j].append('</div>')
print div_list[j]
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print "\nKeyboard interrupt, hiding under my bed!"