@@ -37,54 +37,24 @@ def extractJson(col, startDate, endDate):
3737
3838#_______________________________________________________________________
3939
40- # function needed to fetch a list of all sites from siteDB
41- def fetch_all_sites (url ,api ):
42- # examples in:
43- # https://github.com/gutsche/old-scripts/blob/master/SiteDB/extract_site_executive_mail_addresses.py
44- # https://github.com/dballesteros7/dev-scripts/blob/master/src/reqmgr/input-blocks.py
45- # https://twiki.cern.ch/twiki/bin/view/CMSPublic/CompOpsWorkflowOperationsWMAgentScripts#Resubmit
46- headers = {"Accept" : "application/json" }
47- if 'X509_USER_PROXY' in os .environ :
48- print 'X509_USER_PROXY found'
49- conn = httplib .HTTPSConnection (url , cert_file = os .getenv ('X509_USER_PROXY' ), key_file = os .getenv ('X509_USER_PROXY' ))
50- elif 'X509_USER_CERT' in os .environ and 'X509_USER_KEY' in os .environ :
51- print 'X509_USER_CERT and X509_USER_KEY found'
52- conn = httplib .HTTPSConnection (url , cert_file = os .getenv ('X509_USER_CERT' ), key_file = os .getenv ('X509_USER_KEY' ))
53- else :
54- print 'You need a valid proxy or cert/key files'
55- sys .exit ()
56- print 'conn found in if else structure'
57- r1 = conn .request ("GET" ,api , None , headers )
58- print 'r1 passed'
59- r2 = conn .getresponse ()
60- print 'r2 passed'
61- inputjson = r2 .read ()
62- print '-------------------------------------------------------------'
63- jn = simplejson .loads (inputjson )
64- conn .close ()
65-
66- site_T2 = []
67- for i in jn ['result' ]:
68- if i [jn ['desc' ]['columns' ].index ('type' )]== 'cms' :
69- sitedbname = i [jn ['desc' ]['columns' ].index ('alias' )]
70- if 'T2' in sitedbname :
71- site_T2 .append (sitedbname )
40+ # function needed to fetch a list of all sites from metric 153
41+ def fetch_all_sites (jsn ):
42+ site_T2 = []
43+ for row in jsn ['csvdata' ]:
44+ if row ['VOName' ][0 :2 ] == 'T2' :
45+ site_T2 .append (row ['VOName' ])
7246 return site_T2
7347#_______________________________________________________________________
7448
75- def main_function (outputfile_txt , submonths , allSites ):
49+ def main_function (outputfile_txt , submonths ):
7650 print outputfile_txt
7751 columnnumber = '153'
7852 enddate = date .today () # query date
7953 startdate = addmonths (enddate ,submonths ) # query date
8054 start = startdate .strftime ("%Y-%m-%d" ) # as string field to query
8155 end = enddate .strftime ("%Y-%m-%d" ) # as string field to query
8256 jsn = extractJson (columnnumber , start , end ) # results from dashboard extracts into JSON file
83- filename = 'tmpjson' + start + '.json'
84- f = open (filename ,'w' )
85- f .write (unicode (simplejson .dumps (jsn , ensure_ascii = False )))
86- f .close ()
87-
57+ allSites = fetch_all_sites (jsn )
8858 # sum @ days
8959 days_per_site = {}
9060 for site in allSites : # Read all sites from allsites variable
@@ -123,12 +93,12 @@ def main_function(outputfile_txt, submonths,allSites):
12393 print '------------------------------'
12494 print days_per_site
12595
126-
12796 # write to file
128- f1 = open ('./' + outputfile_txt , 'w+' )
97+ #f1=open('./'+outputfile_txt, 'w+')
98+ f1 = open ('/afs/cern.ch/user/c/cmst1/scratch0/Waitingroom_Dashboard/Waitingroom_SummedMetric/' + outputfile_txt , 'w' )
12999 f1 .write ('# This txt goes into SSB and shows the number of days a site has been in the Waiting Room for X months --> See filename)\n ' )
130100 f1 .write ('# Readme:\n # https://raw.githubusercontent.com/CMSCompOps/MonitoringScripts/master/SR_View_SSB/WRDays/Readme.txt\n ' )
131- now_write = ( datetime . utcnow ()). strftime (" %Y-%m-%d %H:%M:%S" )
101+ now_write = time . strftime (' %Y-%m-%d %H:%M:%S' )
132102 print "Local current time :" , now_write
133103 link = "https://dashb-ssb.cern.ch/dashboard/request.py/siteviewhistorywithstatistics?columnid=153#time=2184&start_date=&end_date=&use_downtimes=false&merge_colors=false&sites=all"
134104 for key , number in days_per_site .iteritems ():
@@ -142,12 +112,12 @@ def main_function(outputfile_txt, submonths,allSites):
142112if __name__ == '__main__' :
143113 outputfile_txt = sys .argv [1 ]
144114 print 'starting to fetch all sites from siteDB'
145- allSitesList = fetch_all_sites ('cmsweb.cern.ch' ,'/sitedb/data/prod/site-names' )
146- main_function (outputfile_txt + '1MonthSum.txt' ,- 1 ,allSitesList )
115+ main_function (outputfile_txt + '1MonthSum.txt' ,- 1 )
147116 print '__________________________________________________'
148117 print '__________________________________________________'
149- main_function (outputfile_txt + '2MonthSum.txt' ,- 2 , allSitesList )
118+ main_function (outputfile_txt + '2MonthSum.txt' ,- 2 )
150119 print '__________________________________________________'
151120 print '__________________________________________________'
152- main_function (outputfile_txt + '3MonthSum.txt' ,- 3 ,allSitesList )
121+ main_function (outputfile_txt + '3MonthSum.txt' ,- 3 )
122+
153123
0 commit comments