-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.py
56 lines (45 loc) · 2.02 KB
/
dashboard.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
from lib import url
import time
try: import json
except ImportError: import simplejson as json
def isOldEntry(endTime, lowerBound):
endTime = time.mktime(time.strptime(endTime, "%Y-%m-%dT%H:%M:%SZ"))
lowerBound = time.mktime(time.strptime(lowerBound, "%Y-%m-%dT%H:%M:%SZ"))
return endTime < lowerBound
def getDowntimes(downtimeMetricURL, lowerBound = None):
# get downtimes from dashboard and parse json
dashboardDT = json.loads(url.read(downtimeMetricURL))
# downtime events to be inserted
# structure: {1 : [entry1, entry2], 2 : [entry3, entry4, ..] ..}
downtimeEvents = {}
for i in dashboardDT['csvdata']:
color = i['COLORNAME']
site = i['VOName']
tier = int(site[1])
stat = i['Status']
# slot start and end times
start = i['Time'] + 'Z'
end = i['EndTime'] + 'Z'
# skip the entry if it is not downtime
if color == 'green': continue
# create google calendar entry summary
summary = "%s %s [%s to %s]" % (site, stat,
start.replace('T', ' ').replace('Z', ''),
end.replace('T', ' ').replace('Z', ''))
# if service partially down, put the hash mark before the event summary
# (please, go to the dashboard::siteStatusBoard metric number 121 and
# see the metric details to understand better)
if color == 'yellow':
summary = '# ' + summary
downtimeEvent = {'summary' : summary,
'start': {'dateTime': start, 'timeZone' : 'UTC'},
'end' : {'dateTime': end , 'timeZone' : 'UTC'} }
# check if the downtime entry is in the lower bound
if lowerBound and isOldEntry(end, lowerBound):
print '# skip: %s' % summary
continue
if not tier in downtimeEvents:
downtimeEvents[tier] = []
if not downtimeEvent in downtimeEvents[tier]:
downtimeEvents[tier].append(downtimeEvent)
return downtimeEvents