Here’s a DIY script written in Python that will do uptime / healthchecks and notify you via Gmail. It’s a basic idea you could start with though.

Sometimes you need a quick and dirty solution to monitor your services without setting up a full monitoring stack. Maybe you’re between monitoring solutions, need something for a side project, or just want a simple backup alerting mechanism. This Python script gives you basic uptime monitoring with Gmail notifications when things go sideways.

the script itself

import requests
import smtplib
import time
from email.mime.text import MIMEText

# Configuration - Edit these values
SITES_TO_CHECK = [
    "https://yoursite.com",
    "https://api.yoursite.com/health"
]

GMAIL_USER = "[email protected]"
GMAIL_PASSWORD = "your-app-password"  # Use Gmail App Password
ALERT_EMAIL = "[email protected]"

CHECK_INTERVAL = 300  # 5 minutes

def check_site(url):
    """Check if a site is up"""
    try:
        response = requests.get(url, timeout=10)
        if response.status_code == 200:
            print(f"✅ {url} is UP")
            return True
        else:
            print(f"❌ {url} is DOWN (Status: {response.status_code})")
            return False
    except Exception as e:
        print(f"❌ {url} is DOWN (Error: {e})")
        return False

def send_alert(failed_sites):
    """Send email alert"""
    if not failed_sites:
        return
    
    subject = f"🚨 ALERT: {len(failed_sites)} site(s) down"
    body = f"The following sites are down:\n\n" + "\n".join(failed_sites)
    
    msg = MIMEText(body)
    msg['Subject'] = subject
    msg['From'] = GMAIL_USER
    msg['To'] = ALERT_EMAIL
    
    try:
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login(GMAIL_USER, GMAIL_PASSWORD)
        server.send_message(msg)
        server.quit()
        print(f"📧 Alert sent for {len(failed_sites)} failed sites")
    except Exception as e:
        print(f"Failed to send email: {e}")

def main():
    """Main monitoring loop"""
    print("Starting uptime monitor...")
    
    while True:
        failed_sites = []
        
        for site in SITES_TO_CHECK:
            if not check_site(site):
                failed_sites.append(site)
        
        if failed_sites:
            send_alert(failed_sites)
        else:
            print("All sites are UP ✅")
        
        print(f"Sleeping for {CHECK_INTERVAL} seconds...\n")
        time.sleep(CHECK_INTERVAL)

if __name__ == "__main__":
    main()

Security note: If you plan to commit this script to GitHub or any Git repo, don’t hardcode the GMAIL_PASSWORD. Use environment variables instead or even a secrets manager. Something like GMAIL_PASSWORD = os.getenv('GMAIL_APP_PASSWORD') would be much safer.

create gmail app password

You can Google “app password for python smtp” and let AI spill it out for you, or follow these steps:

  1. Enable 2-Step Verification on your Gmail account (if not already done)
  2. Go to your Google Account Security settings
  3. Find the “App Passwords” section
  4. Select “Mail” as the app and “Other (custom name)” as the device
  5. Give it a descriptive name like “Python Uptime Monitor”
  6. Click Generate
  7. Copy the 16-digit password that’s displayed

Use this app password in your script, not your regular Gmail password.

bottom line

If you’re running this in production, consider setting it up as a systemd service, or even dockerize it. However, you could also deploy it as a simple cron job for less frequent checks.

Shameless plug alert: Still monitoring your stuff manually? Check out justanotheruptime.com and yeah that’s all.