1212#extract nonwaitingroommsites from ActiveSites script output
1313url2 = "https://cmsdoc.cern.ch/cms/LCG/SiteComm/T2WaitingList/WasCommissionedT2ForSiteMonitor.txt"
1414
15- # function needed to fetch a list of all sites from siteDB
16- def fetch_all_sites (url ,api ):
17- # examples in:
18- # https://github.com/gutsche/old-scripts/blob/master/SiteDB/extract_site_executive_mail_addresses.py
19- # https://github.com/dballesteros7/dev-scripts/blob/master/src/reqmgr/input-blocks.py
20- # https://twiki.cern.ch/twiki/bin/view/CMSPublic/CompOpsWorkflowOperationsWMAgentScripts#Resubmit
21- headers = {"Accept" : "application/json" }
22- if 'X509_USER_PROXY' in os .environ :
23- print 'X509_USER_PROXY found'
24- conn = httplib .HTTPSConnection (url , cert_file = os .getenv ('X509_USER_PROXY' ), key_file = os .getenv ('X509_USER_PROXY' ))
25- elif 'X509_USER_CERT' in os .environ and 'X509_USER_KEY' in os .environ :
26- print 'X509_USER_CERT and X509_USER_KEY found'
27- conn = httplib .HTTPSConnection (url , cert_file = os .getenv ('X509_USER_CERT' ), key_file = os .getenv ('X509_USER_KEY' ))
28- else :
29- print 'You need a valid proxy or cert/key files'
30- sys .exit ()
31- print 'conn found in if else structure'
32- r1 = conn .request ("GET" ,api , None , headers )
33- print 'r1 passed'
34- r2 = conn .getresponse ()
35- print 'r2 passed'
36- inputjson = r2 .read ()
37- print '-------------------------------------------------------------'
38- #print inputjson
39- result = simplejson .loads (inputjson )
40- conn .close ()
41- return result
15+ def extractJson ():
16+ url = "http://dashb-ssb.cern.ch/dashboard/request.py/getplotdata?columnid=153&time=24&dateFrom=&dateTo=&site=T2_AT_Vienna&sites=all&clouds=undefined&batch=1"
17+ print "Getting the url %s" % url
18+ request = urllib2 .Request (url , headers = {"Accept" :"application/json" })
19+ response = urllib2 .urlopen (request )
20+ data = response .read ()
21+ rows = simplejson .loads (data )
22+ return rows
23+
24+ # function needed to fetch a list of all sites from metric
25+ def fetch_all_sites (jsn ):
26+ site_T2 = []
27+ for row in jsn ['csvdata' ]:
28+ if row ['VOName' ][0 :2 ] == 'T2' :
29+ site_T2 .append (row ['VOName' ])
30+ return site_T2
31+
4232
4333def getNonWaitingRoomSites (url ):
4434 tmp_sites = []
@@ -51,8 +41,6 @@ def getNonWaitingRoomSites(url):
5141 if not row .strip ().startswith ("#" ):
5242 split_row = row .split ('\t ' )
5343 if len (split_row )> 1 :
54- #print split_row
55- #print split_row[1]
5644 tmp_sites .append (split_row [1 ])
5745 return tmp_sites
5846
@@ -65,32 +53,8 @@ def main_function(outputfile_txt):
6553 print '------------------------------------------'
6654
6755 # all sites
68- print 'starting to fetch all sites from siteDB'
69- jn = fetch_all_sites ('cmsweb.cern.ch' ,'/sitedb/data/prod/site-names' )
70- #json form:
71- #{"desc": {"columns": ["type", "site_name", "alias"]},
72- # "result": [
73- # ["cms", "ASGC", "T1_TW_ASGC"],
74- # ["cms", "BY-NCPHEP", "T3_BY_NCPHEP"]
75- # ...
76-
77- # match the information
78- #print jn['result']
79- #site_T1= []
80- site_T2 = []
81- #site_T3= []
82- #print 'printing i'
83- for i in jn ['result' ]:
84- if i [jn ['desc' ]['columns' ].index ('type' )]== 'cms' :
85- sitedbname = i [jn ['desc' ]['columns' ].index ('alias' )]
86- #print sitedbname
87- #if 'T1' in sitedbname:
88- # site_T1.append(sitedbname)
89- if 'T2' in sitedbname :
90- site_T2 .append (sitedbname )
91- #if 'T3' in sitedbname:
92- # site_T3.append(sitedbname)
93- #print site_T2
56+ print 'starting to fetch all sites from metric'
57+ site_T2 = fetch_all_sites (extractJson ())
9458 print '--------------------------------------------------------'
9559 print 'Sites in waiting room:'
9660 waitingRoom_sites = [ site for site in site_T2 if not site in nonWaitingRoom_Sites ]
@@ -126,4 +90,4 @@ def main_function(outputfile_txt):
12690
12791if __name__ == '__main__' :
12892 outputfile_txt = sys .argv [1 ]
129- main_function (outputfile_txt )
93+ main_function (outputfile_txt )
0 commit comments