forked from CMSCompOps/MonitoringScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsableSites.py
executable file
·242 lines (172 loc) · 6.58 KB
/
UsableSites.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/python
""" @author: Josep Flix (jflix@pic.es) """
import sys, xml.dom.minidom, os, datetime, time, pprint
from xml import xpath
today=datetime.datetime.utcnow()
todaystamp=today.strftime("%Y-%m-%d")
todaystampfile=today.strftime("%Y-%m-%d %H:%M:%S")
todaystamptofile=today.strftime("%Y%m%d_%H")
todaystamptotxt=today.strftime("%Y%m%d %H")
#GetURLs=False
GetURLs=True
path_out = '/var/www/html/cms/SiteReadinessAnalysis/'
hours=1 # Number of hours to get info from SSB
# URLs with SSB inputs --------------------------------------------------------------------------------------
#webserver_devel="http://dashb-ssb-devel.cern.ch"
webserver="http://dashb-ssb.cern.ch"
Downtimes_sam= webserver + '/dashboard/request.py/siteviewhistory?columnid=71&time=' + str(hours) + "&fullstatus=1"
Ranking= webserver + '/dashboard/request.py/siteviewhistory?columnid=96&time=' + str(hours) + "&fullstatus=1"
CE_sam= webserver + '/dashboard/request.py/siteviewhistory?columnid=4&time=' + str(hours) + "&fullstatus=1"
SRM_sam= webserver + '/dashboard/request.py/siteviewhistory?columnid=5&time=' + str(hours) + "&fullstatus=1"
ColumnMatrix = {} # SSB URLs Matrix
ColumnMatrix['Downtimes_sam']=Downtimes_sam
ColumnMatrix['CE_sam']=CE_sam
ColumnMatrix['SRM_sam']=SRM_sam
ColumnMatrix['Ranking']=Ranking
# -----------------------------------------------------------------------------------------------------------
SiteDB_url="https://cmsweb.cern.ch/sitedb/reports/showXMLReport?reportid=naming_convention.ini"
SiteDB_sites=[]
fileSiteDB="/tmp/sitedb.txt"
print "Getting the url %s" % SiteDB_url
os.system("curl -k -H 'Accept: text/xml' '%s' > %s" % (SiteDB_url,fileSiteDB))
f=file(fileSiteDB,'r')
t= xml.dom.minidom.parse(f)
f.close()
for urls in xpath.Evaluate('/report/result/item', t):
info={}
for target in xpath.Evaluate("cms", urls):
if target.hasChildNodes():
s=target.firstChild.nodeValue.encode('ascii')
else:
s=""
SiteDB_sites.append(s)
#pprint.pprint(SiteDB_sites)
########################################################
# Reading data from SSB
########################################################
sites={}
ColumnItems = ColumnMatrix.keys()
ColumnItems.sort()
ColumnItems.reverse()
for col in ColumnItems:
# print col
url=ColumnMatrix[col]
fileN="/tmp/"+col
if GetURLs == True:
print "Getting the url %s" % url
os.system("curl -H 'Accept: text/xml' '%s' > %s" % (url,fileN))
f=file(fileN,'r')
t= xml.dom.minidom.parse(f)
f.close()
for urls in xpath.Evaluate('/siteviewhistory/data/item', t):
info={}
for option in ('Status', "COLOR", 'Time', 'EndTime','VOName'):
for target in xpath.Evaluate(option, urls):
if target.hasChildNodes():
s=target.firstChild.nodeValue.encode('ascii')
else:
s=""
info[option]=s
if not sites.has_key(info['VOName']):
sites[info['VOName']]={}
if not sites[info['VOName']].has_key(col):
sites[info['VOName']][col]={}
sites[info['VOName']][col][info['Time']]=info
filetxt= path_out + 'UsableSites_' + todaystamptofile + ".txt"
fileHandle = open ( filetxt , 'w' )
reptime="# Usable Sites Report made on %s (UTC)\n" % todaystampfile
fileHandle.write("#\n")
fileHandle.write(reptime)
fileHandle.write("#\n")
fileHandle.write("# Usability procedure described in: https://twiki.cern.ch/twiki/bin/view/CMS/FacOps_Tier2UsableForAnalysis\n")
fileHandle.write("#\n\n")
site = sites.keys()
site.sort()
usability={}
usable={}
not_usable={}
for sitename in site:
if sitename.find("T3_") == 0 or sitename.find("T0_") == 0 or sitename.find("T1_") == 0: continue
if not sitename in SiteDB_sites: continue
if sitename.find("T2_CH_CAF") == 0 or sitename.find("T2_PT_LIP_Coimbra") == 0: continue
useit=1
for col in ColumnMatrix:
if not sites[sitename].has_key(col):
continue
items = sites[sitename][col].keys()
items.sort()
lastState= ""
lastBegin= ""
lastEnd= ""
for i in items:
lastState=sites[sitename][col][i]['Status']
lastBegin=sites[sitename][col][i]['Time']
lastEnd=sites[sitename][col][i]['EndTime']
if lastState != "":
if col == "Ranking":
if lastState == "n/a":
useit=0
continue
if sitename.find("T1_") == 0 and int(lastState)<90:
useit=0
if sitename.find("T2_") == 0 and int(lastState)<80:
useit=0
if col == "CE_sam" and lastState != "OK":
useit=0
if col == "SRM_sam" and lastState != "OK":
useit=0
if col == "Downtimes_sam" and lastState != "":
useit=0
usability[sitename]=useit
if usability[sitename] == 1:
if not usable.has_key(sitename): usable[sitename]=1
else:
if not not_usable.has_key(sitename): not_usable[sitename]=0
############################################################
fileHandle.write("---------- USABLE SITES FOR ANALYSIS ---------- \n\n")
siteus = usable.keys()
siteus.sort()
for sitename in siteus: fileHandle.write(sitename+"\n")
fileHandle.write("\n---------- *NOT* USABLE SITES FOR ANALYSIS ---------- \n\n")
sitenous = not_usable.keys()
sitenous.sort()
for sitename in sitenous: fileHandle.write(sitename+"\n")
############################################################
totalsites=len(usable)+len(not_usable)
fileHandle.write("\n--------- Statistics ---------- \n\n")
fileHandle.write(todaystamptotxt + " / " + str(len(usable)) + " usable sites" + " / " + str(len(not_usable)) + " not usable sites\n\n")
fileHandle.write("\n--------- Detailed Site Status ---------- \n\n")
for sitename in site:
if sitename.find("T3_") == 0 or sitename.find("T0_") == 0 or sitename.find("T1_") == 0: continue
if not sitename in SiteDB_sites:
# fileHandle.write("Site is not on SiteDB\n\n")
continue
if sitename.find("T2_CH_CAF") == 0 or sitename.find("T2_PT_LIP_Coimbra") == 0:
# fileHandle.write("Site shall be skipped\n\n")
continue
for col in ColumnMatrix:
if not sites[sitename].has_key(col):
continue
items = sites[sitename][col].keys()
items.sort()
lastState= ""
lastBegin= ""
lastEnd= ""
for i in items:
lastState=sites[sitename][col][i]['Status']
lastBegin=sites[sitename][col][i]['Time']
lastEnd=sites[sitename][col][i]['EndTime']
if lastState != "":
if col == "Ranking":
mes = sitename + "," + col + " : " + lastState + "%\n"
else:
mes = sitename + "," + col + " : " + lastState + "\n"
fileHandle.write(mes)
if usability[sitename] == 1:
fileHandle.write(sitename + " is usable\n\n")
else:
fileHandle.write(sitename + " is *not* usable\n\n")
#pprint.pprint(usable)
#pprint.pprint(not_usable)
fileHandle.close()
sys.exit(0)