|
@@ -0,0 +1,69 @@
|
|
|
|
+#!/usr/bin/python3
|
|
|
|
+
|
|
|
|
+"""
|
|
|
|
+smells like updog in here
|
|
|
|
+
|
|
|
|
+generates an email for sendmail to notify me if all my websites are up,
|
|
|
|
+ or if one or more of them is down. "up" means http response is 200.
|
|
|
|
+
|
|
|
|
+./up_checker.py | sendmail user@email.com
|
|
|
|
+
|
|
|
|
+authored:
|
|
|
|
+ Jun 15 2022; spokane valley, wa
|
|
|
|
+ jordyn
|
|
|
|
+"""
|
|
|
|
+
|
|
|
|
+from collections import namedtuple
|
|
|
|
+
|
|
|
|
+import time
|
|
|
|
+import requests
|
|
|
|
+
|
|
|
|
+Status = namedtuple('Status', ['website', 'status'])
|
|
|
|
+
|
|
|
|
+websites = [
|
|
|
|
+ "https://queerscompute.gay/",
|
|
|
|
+ "https://jordandashel.com/",
|
|
|
|
+ "https://acrossthecountryin90days.com/",
|
|
|
|
+ "https://4-letters.net/"
|
|
|
|
+]
|
|
|
|
+
|
|
|
|
+def website_is_up(website):
|
|
|
|
+ return website.status == 200
|
|
|
|
+
|
|
|
|
+def website_status(website):
|
|
|
|
+ try:
|
|
|
|
+ response = requests.head(website)
|
|
|
|
+ status = response.status_code
|
|
|
|
+ return Status(website, status)
|
|
|
|
+ except:
|
|
|
|
+ return Status(website, None)
|
|
|
|
+
|
|
|
|
+statuses = [website_status(website) for website in websites]
|
|
|
|
+
|
|
|
|
+all_up = all([website_is_up(website) for website in statuses])
|
|
|
|
+
|
|
|
|
+report = ""
|
|
|
|
+
|
|
|
|
+for status in statuses:
|
|
|
|
+ website_name = str.split(status.website, "://")[1]
|
|
|
|
+ website_name = website_name[:-1]
|
|
|
|
+ report += f'{website_name:.<40} {"up" if website_is_up(status) else "DOWN"}\n'
|
|
|
|
+
|
|
|
|
+email = f"""Subject: websites are {"up" if all_up else "DOWN"}
|
|
|
|
+From: robot.dashel@gmail.com
|
|
|
|
+Content-Type: text/html; charset="utf8"
|
|
|
|
+
|
|
|
|
+<html>
|
|
|
|
+<body>
|
|
|
|
+<pre>
|
|
|
|
+all up? {all_up}.
|
|
|
|
+
|
|
|
|
+reporting at {time.strftime("%A %B %d %Y, %X %Z")}
|
|
|
|
+
|
|
|
|
+from squidward at bikinib:
|
|
|
|
+{report}
|
|
|
|
+</pre>
|
|
|
|
+</body>
|
|
|
|
+</html>"""
|
|
|
|
+
|
|
|
|
+print(email)
|