-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasitechecker.py
More file actions
47 lines (39 loc) · 1.3 KB
/
asitechecker.py
File metadata and controls
47 lines (39 loc) · 1.3 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
import requests
import slack_sdk as slacker
import os
import logging
import csv
slack_token = os.environ.get('SLACK_TOKEN')
client = slacker.WebClient(token=slack_token)
#try:
# response = client.chat_postMessage(
# channel="C0226ELG6R4",
# text="health notifier test"
# )
#except slacker.errors.SlackApiError as e:
# assert e.response["error"]
website_url = "https://eightknot.chaoss.tv"
#website_url = "http://192.168.0.95:5038"
r = requests.get(f'{website_url}', timeout=5)
##Need to set verifiable=False for non-https
#r = requests.get(f'{website_url}', verify=False, timeout=5)
if r.status_code != 200:
if os.path.isfile('./fail.txt'):
#do nothing
print('hi')
else:
try:
response = client.chat_postMessage(
channel="C0226ELG6R4",
text=(f"Please verify that {website_url} is working. It appears to be down right now.")
)
except slacker.errors.SlackApiError as e:
assert e.response["error"]
with open('./fail.txt', a, newline='') as file:
writer = csv.writer(file)
writer.writerow(['failed'])
file.close()
else:
if os.path.isfile('./fail.txt'):
os.remove('./fail.txt')
print(f"Good News, {website_url} is up")