Skip to content

Commit 9b6fa60

Browse files
author
100daysofdevops
committed
script to check website status and send mail if its down
1 parent e0137ff commit 9b6fa60

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import requests
2+
import bs4
3+
import smtplib
4+
import os
5+
6+
email_add = os.environ.get('EMAIL_ADD')
7+
password = os.environ.get('EMAIL_PASS')
8+
9+
def send_email():
10+
s = smtplib.SMTP('smtp.gmail.com', 587)
11+
s.starttls()
12+
s.login(email_add, password)
13+
subject = "!!!!!! 100 days of devops site is down"
14+
body = "Check the status of 100 days of devops"
15+
message = f'Subject: {subject}\n\n {body}'
16+
s.sendmail(email_add, email_add, message)
17+
s.quit()
18+
19+
20+
producturl="http://100daysofdevops.com/contact-us/"
21+
22+
res = requests.get(producturl, timeout=5)
23+
if res.status_code != 200:
24+
send_email()
25+
26+
soup = bs4.BeautifulSoup(res.text,'html.parser')
27+
28+
elems = soup.select('#post-67 > div > div > header > h2')
29+
try:
30+
if elems[0].text != "Welcome":
31+
send_email()
32+
except Exception as e:
33+
send_email()

0 commit comments

Comments
 (0)