-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcp.py
More file actions
89 lines (70 loc) · 2.84 KB
/
gcp.py
File metadata and controls
89 lines (70 loc) · 2.84 KB
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
import requests
from bs4 import BeautifulSoup
import constants
import templates
import ES_Reader as ES
import logging
logger = logging.getLogger(__name__)
# print soup.prettify()
HAPPY_STATE = 'service is operating normally'
INFORMATIONAL_STATE = 'informational message'
DEGRADATIONAL_STATE = 'service degradation'
DISRUPTIONAL_STATE = 'service disruption'
status_dict = {
HAPPY_STATE: constants.STATUS_GOOD,
DEGRADATIONAL_STATE: constants.STATUS_WARNING,
DISRUPTIONAL_STATE: constants.STATUS_CRITICAL
}
def run():
page = requests.get(constants.URL_GOOGLE)
soup = BeautifulSoup(page.content, 'html.parser')
json_template = templates.get_json_template()
json_template.update({
'source': constants.SOURCE_GOOGLE,
'sourceUrl': constants.URL_GOOGLE,
'sourceStatus': constants.STATUS_GOOD,
})
try:
service_status = constants.STATUS_GOOD
status_set = set()
html_element = soup.body.find('div', attrs={'class':'body'})
html_main = html_element.find('div', attrs={'id':'maia-main'})
html_timeline = html_element.find('div', attrs={'class':'timeline clearfix'})
html_table = html_timeline.find('table')
#--------------------------------------
#Check this line below and above this
#-------------------------------------
#table_body = html_tables.find('tbody')
rows = html_table.find_all('tr')
#print(rows)
for row in rows[1:-1]:
service_name_column = row.find('td', attrs={'class':'service-status'})
service_status_column = row.find('td', attrs={'class':'day col8'})
service_name = service_name_column.text.strip()
service_status = service_status_column.span['class'][2]
if service_status.lower()=='high':
status_set.add(constants.STATUS_CRITICAL)
elif service_status.lower()=='medium':
status_set.add(constants.STATUS_WARNING)
else:
status_set.add(constants.STATUS_GOOD)
json_template['services'].append({
'name': service_name,
'value': service_status
})
if constants.STATUS_CRITICAL in status_set:
service_status = constants.STATUS_CRITICAL
elif constants.STATUS_WARNING in status_set:
service_status = constants.STATUS_WARNING
json_template['sourceStatus'] = service_status
#print(json_template)
ES.create_index_data(json_template)
except Exception:
logger.error('error parsing %s', constants.SOURCE_GOOGLE, exc_info=1)
logger.error("-" * 100)
logger.error(unicode(soup))
logger.error("-" * 100)
json_template['sourceStatus'] = constants.STATUS_CRITICAL
ES.create_index_data(json_template)
if __name__ == '__main__':
run()