Uptime Bot

Goal

  • Know when an app is down
  • No 3rd party or cloud solutions
  • Notifications go to Slack

The other day, my buddy and I were chatting about uptime and how you find out when a script stops working. That got me thinking - there’s all this automation running on these servers, but no way to know when something breaks.

I’m not usually one for adding more notifications to my life, but the script below will send downtime alerts to your personal Slack. That way, you decide if your phone / watch / tablet / laptop / TV / should ruin your day with constant interruptions.

Uptime Alert

uptime.py

import requests
from slack_lib import send_message_to_slack

def check_urls(url_dict):
    for name, url in url_dict.items():
        try:
            response = requests.get(url, timeout=7)
            if response.status_code == 200:
                print(f"✅ {name} is up.")
            else:
                print(f"⚠️ {name} returned status code {response.status_code}.")
        except requests.exceptions.RequestException as e:
            send_message_to_slack(f"❌ {name} is down. Error: {e}", username="🔥 Uptime Bot 🚨")

# Update this list
urls = {
    "Main site": "https://mcwain.net",
    "RSS": "https://rss.mcwain.net",
    "Bookmarks": "https://links.mcwain.net"
}

check_urls(urls)

Sources

Questions or comments?

Previous: Choreboard Next: Latte Night Light