コード例 #1
0
    def EvaluateSiteReadiness(self):
        print "\nEvaluating Site Readiness\n"
        prog = ProgressBar(0, 100, 77)
        sitesit = self.matrices.dailyMetrics.keys()
        sitesit.sort()
        for sitename in sitesit:
            prog.increment(100./len(sitesit))
            if not self.matrices.readiValues.has_key(sitename):
                self.matrices.readiValues[sitename] = {}
            tier = sitename.split("_")[0]
            start = self.tinfo.today
            stop  = self.tinfo.today - datetime.timedelta(self.cinfo.days - self.cinfo.daysSC)
            for iday in daterange(start, stop, datetime.timedelta(-1)): # loop from today to the first day on which we try to calculate the readiness (default: today to (today - 60 - 7) days)
                idaystamp = iday.strftime("%Y-%m-%d")
                statusE = 0 # number of days over the previous daysSC days that dailyMetric was in error
                for jday in daterange(iday, iday - datetime.timedelta(self.cinfo.daysSC), datetime.timedelta(-1)): # loop over the dailyMetric values from the previous daysSC days
                    jdaystamp = jday.strftime("%Y-%m-%d")
                    if self.matrices.dailyMetrics[sitename][jdaystamp] == 'E': # if dailyMetric in error
                        if ( tier == "T2" or tier == "T3") and (jday.weekday() == 5 or jday.weekday() == 6):
                            if not self.options.t2weekends: # skip Errors on weekends for T2s
                                continue
                        statusE += 1
    
                status = "n/a"
                color = "white"
                previousDayStamp = (iday - datetime.timedelta(1)).strftime("%Y-%m-%d") # iday minus one day
                dailyMetric = self.matrices.dailyMetrics[sitename][idaystamp]
                if statusE > 2: # if in error for more than two of the last daysSC days
                    status="NR"
                    color="red"
                if dailyMetric == 'E' and statusE <= 2 : # if in error today
                    status="W"
                    color="yellow"
                if dailyMetric == 'O' and statusE <= 2 : # if ok
                    status="R"
                    color="green"
                if dailyMetric == 'O' and self.matrices.dailyMetrics[sitename][previousDayStamp] == 'O':
                    status="R"
                    color="green"
                if dailyMetric == 'SD':
                    status='SD'
                    color="brown"
                self.matrices.readiValues[sitename][idaystamp] = status # set actual SR value

            # correct weekend t2 and t3 readiness values to 'R' if they're in downtime, otherwise to friday's value
            if tier=="T2" or tier=="T3":
                start = self.tinfo.today - datetime.timedelta(self.cinfo.days - self.cinfo.daysSC - 3)
                stop  = self.tinfo.today
                for iday in daterange(start, stop):
                    idaystamp = iday.strftime("%Y-%m-%d")
                    previousDayStamp = (iday - datetime.timedelta(1)).strftime("%Y-%m-%d")
                    if self.matrices.dailyMetrics[sitename][idaystamp] == 'E':
                        if iday.weekday() == 5 or iday.weekday() == 6: # id. weekends
                            if not self.options.t2weekends: # skip Errors on weekends for T2s
                                if self.matrices.readiValues[sitename][previousDayStamp] == 'SD':
                                    self.matrices.readiValues[sitename][idaystamp] = 'R'
                                else:
                                    self.matrices.readiValues[sitename][idaystamp] = self.matrices.readiValues[sitename][previousDayStamp]
                            
        prog.finish()
    
        # put in blank current day
        for sitename in self.matrices.dailyMetrics:
            for col in self.cinfo.urls:
                if self.matrices.columnValues[sitename][self.tinfo.todaystamp].has_key(col):
                    self.matrices.columnValues[sitename][self.tinfo.todaystamp][col]['Status'] = ' '
                    self.matrices.columnValues[sitename][self.tinfo.todaystamp][col]['Color'] = 'white'
                    self.matrices.readiValues[sitename][self.tinfo.todaystamp] = ' '
コード例 #2
0
 def FillSummaryMatrix(self):
     print "\nExtracting Column Info for CMS sites\n"
     prog = ProgressBar(0, 100, 77)
     for sitename in self.matrices.xmlInfo:
         prog.increment(100./len(self.matrices.xmlInfo))
         if not self.matrices.columnValues.has_key(sitename): # add site if not already there
             self.matrices.columnValues[sitename] = {}
         for col in self.cinfo.urls:
             if not self.matrices.xmlInfo[sitename].has_key(col) or col == 'Downtimes_top':
                 continue
 
             # set to null (default) values
             for iday in daterange(self.tinfo.today - tdelta(60), self.tinfo.today + tdelta(1)):
                 idaystamp = iday.strftime("%Y-%m-%d")
                 if not self.matrices.columnValues[sitename].has_key(idaystamp):
                     self.matrices.columnValues[sitename][idaystamp] = {}
                 if not self.matrices.columnValues[sitename][idaystamp].has_key(col):
                     self.matrices.columnValues[sitename][idaystamp][col] = {}
                 nullValues = {}
                 nullValues['Status'] = 'n/a'
                 nullValues['Color'] = 'white'
                 nullValues['URL'] = ' '
                 nullValues['validity'] = 0
                 self.matrices.columnValues[sitename][idaystamp][col] = nullValues
 
             items = self.matrices.xmlInfo[sitename][col].keys()
             items.sort()
             for coldate in items: # loop over each time/date combination
                 xmltime = datetime.datetime(*time.strptime(self.matrices.xmlInfo[sitename][col][coldate]['Time'], "%Y-%m-%d %H:%M:%S")[0:6])
                 xmlendtime = datetime.datetime(*time.strptime(self.matrices.xmlInfo[sitename][col][coldate]['EndTime'], "%Y-%m-%d %H:%M:%S")[0:6])
 
                 startxmldatetmp = xmltime.strftime("%Y-%m-%d 00:00:00")
                 startxmldate = datetime.datetime(*time.strptime(startxmldatetmp, "%Y-%m-%d %H:%M:%S")[0:6])
 
                 EndTXML = True
                 i = 0
                 while ( EndTXML ):
                     d = datetime.timedelta(i) # convert i to number of days
                     i += 1
                     dayloop = startxmldate + d
                     dayloopstamp = dayloop.strftime("%Y-%m-%d")
                     dayloopstamp2 = dayloop.strftime("%Y-%m-%d 00:00:00")
                     looptime = datetime.datetime(*time.strptime(dayloopstamp2, "%Y-%m-%d %H:%M:%S")[0:6])
                     if dayloop > self.tinfo.today:
                         EndTXML = False
                         continue
                     diff1  = xmltime-looptime
                     diff1s = (diff1.days*86400+diff1.seconds)
                     diff2  = xmlendtime-looptime
                     diff2s = (diff2.days*86400+diff2.seconds)
                     diff3  = xmlendtime-xmltime
                     diff3s = (diff3.days*86400+diff3.seconds)
                     if diff1s<=0 and diff2s>0:
                         if diff2s>=86400: validity=86400
                         else: validity=diff2s
                     if diff1s>0 and diff1s<86400:
                         if diff2s>86400: validity=86400-diff1s
                         else: validity=diff3s
                     if diff1s<0 and diff2s<=0:
                         EndTXML=False
                         continue
                       
                     if self.cinfo.colorCodes[col][self.matrices.xmlInfo[sitename][col][coldate]['COLOR']] == "green":
                         status=self.matrices.xmlInfo[sitename][col][coldate]['Status']
                         statusu=self.matrices.xmlInfo[sitename][col][coldate]['URL']
                         statusc='green'
                         if self.matrices.xmlInfo[sitename][col][coldate]['Status']=="pend":
                             status='-'
                             statusc='orange'
                     elif self.cinfo.colorCodes[col][self.matrices.xmlInfo[sitename][col][coldate]['COLOR']] == "red":
                         status=self.matrices.xmlInfo[sitename][col][coldate]['Status']
                         statusu=self.matrices.xmlInfo[sitename][col][coldate]['URL']
                         statusc='red'
                     elif self.cinfo.colorCodes[col][self.matrices.xmlInfo[sitename][col][coldate]['COLOR']] == "yellow":
                         status=self.matrices.xmlInfo[sitename][col][coldate]['Status']
                         statusu=self.matrices.xmlInfo[sitename][col][coldate]['URL']
                         statusc='yellow'
                     elif self.cinfo.colorCodes[col][self.matrices.xmlInfo[sitename][col][coldate]['COLOR']] == "white":
                         status='n/a'
                         statusu=' '
                         statusc='white'
                     else:
                         status=self.matrices.xmlInfo[sitename][col][coldate]['Status']
                         statusu=self.matrices.xmlInfo[sitename][col][coldate]['URL']
                         statusc=self.cinfo.colorCodes[col][self.matrices.xmlInfo[sitename][col][coldate]['COLOR']]
 
                     dayloopstamp3 = self.ShiftDayForMetric(dayloop,col)
                     todayst = date(int(self.tinfo.todaystamp[0:4]),int(self.tinfo.todaystamp[5:7]),int(self.tinfo.todaystamp[8:10]))
                     dayloop3 = date(int(dayloopstamp3[0:4]),int(dayloopstamp3[5:7]),int(dayloopstamp3[8:10]))
 
                     if abs((dayloop3-todayst).days) > self.cinfo.days:
                         continue
                     if status == "Ready":
                        status = "R"
                     elif status == "NotReady":
                        status = "NR"
                     elif status == "Downtime":
                        status = "SD"
                     elif status == "Waiting_Room":
                        status = "WR"
                     elif status == "Morgue":
                        status = "M" 
                     elif status == "OK" or status == "Ok":
                        status = "O"
                     elif status == "Error":
                        status = "E"
                     # set the actual values in self.matrices.columnValues
                     infocol = {}
                     infocol['Status'] = status
                     infocol['Color'] = statusc
                     infocol['URL'] = statusu
                     infocol['validity'] = validity
                     if self.matrices.columnValues[sitename][dayloopstamp3][col].has_key('validity'):
                         if validity > self.matrices.columnValues[sitename][dayloopstamp3][col]['validity']:
                             self.matrices.columnValues[sitename][dayloopstamp3][col] = infocol
                     else:
                         self.matrices.columnValues[sitename][dayloopstamp3][col] = infocol
                                 
                     if dayloopstamp == self.tinfo.todaystamp:
                         infocol = {}
                         infocol['Status'] = ' '
                         infocol['Color'] = 'white'
                         infocol['URL'] = ' '
                         infocol['validity'] = '0'                       
                         self.matrices.columnValues[sitename][dayloopstamp][col] = infocol
 
     prog.finish()