forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
site_view.py
executable file
·73 lines (62 loc) · 1.86 KB
/
site_view.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
70
71
72
73
#!/usr/bin/env python
#
# Sara Alderweireldt ([email protected])
# 2012-06-21
#
# parsing site_view table from cms dashboard
import os
tmpdir='/tmp/cmst1'
# helper function for parsing entries
def json_read(jstring):
jin = jstring.strip('{').strip('}')
jarr = jin.split(', ')
d1 = {}
for j in jarr:
key,value = j.split(': ')
d1[key.strip('\'')] = value.strip('\'')
return d1
# get file
if os.path.exists(os.path.join(tmpdir,'site_view.txt')):
os.remove(os.path.join(tmpdir,'site_view.txt'))
os.system('curl -H \'Accept:text/csv\' http://dashb-ssb.cern.ch/dashboard/request.py/getall > '+os.path.join(tmpdir,'site_view.txt'))
os.chmod(os.path.join(tmpdir,'site_view.txt'),0755)
# parse file
fin = open(os.path.join(tmpdir,'site_view.txt'),'r+')
entries = []
for lno,l in enumerate(fin):
entry = {}
if lno == 0:
headers = l.strip().split(',')
else:
fields = l.strip().split(',"')
for i in range(1,len(fields)):
fields[i] = '"'+fields[i]
for i,h in enumerate(headers):
entry[h] = fields[i]
entries.append(entry)
fin.close()
headers.remove(headers[15])
widths = [20,11,11,8,8,11,11,7,7,12,12,10,12,12,12,12,200]
# write summary
fout = open(os.path.join(tmpdir,'site_view.summary'),'w+')
for hno,h in enumerate(headers):
fout.write( ' %-*s |' % (widths[hno],h[0:12]), )
fout.write( ' %-*s |' % (widths[hno],"Savannah URL"), )
fout.write( '\n' )
for w in widths:
fout.write( '-'*w+'-+', )
fout.write( '\n' )
for lno in range(len(entries)):
for hno,h in enumerate(headers):
if hno == 0:
fout.write( ' %-*s |' % (widths[hno],entries[lno][h]), )
else:
dic1 = json_read(entries[lno][h][1:-1])
fout.write( ' %-*s |' % (widths[hno],dic1['Status']), )
if h == "Savannah CMS":
dicsave = dic1
fout.write( ' %-*s |' % (widths[hno+1],dicsave['URL']), )
fout.write( '\n' )
fout.close()
# cleaning
os.remove(os.path.join(tmpdir,'site_view.txt'))