DEV Community

devbox-zero-ops
devbox-zero-ops

Posted on

Replacing $49/mo Uptime SaaS with Pure Python: TLS/SSL Cert Expiry, SQLite WAL Incident Cooldowns, and Telegram/Discord Alerts

Most indie hackers and small teams pay $29–$79/month for uptime monitoring SaaS just to ping 10 endpoints, watch SSL certificate expirations, and send a Telegram or Discord message when a server goes down.

You can run the entire stack yourself on any $5 VPS, Raspberry Pi, or Docker container with pure Python standard library (ssl, socket, sqlite3, concurrent.futures) plus requests.

Here are the three engineering details that make a self-hosted monitor genuinely production-ready.


1. Real TLS/SSL Certificate Expiry Checks in 15 Lines

Waiting for users to screenshot a browser NET::ERR_CERT_DATE_INVALID warning is the worst way to discover a broken Let's Encrypt renewal. Reading notAfter directly over a TLS socket takes milliseconds:

import socket
import ssl
from datetime import datetime, timezone

def get_ssl_days_remaining(hostname: str, port: int = 443, timeout: float = 8.0) -> int:
    ctx = ssl.create_default_context()
    with socket.create_connection((hostname, port), timeout=timeout) as sock:
        with ctx.wrap_socket(sock, server_hostname=hostname) as ssock:
            cert = ssock.getpeercert()
    not_after = datetime.strptime(cert["notAfter"], "%b %d %H:%M:%S %Y %Z").replace(tzinfo=timezone.utc)
    return (not_after - datetime.now(timezone.utc)).days
Enter fullscreen mode Exit fullscreen mode

2. SQLite WAL Incident State Machine (Zero Alert Spam + Recovery Notices)

A naive cron script that sends a message on every failed check will flood your phone with 60 alerts during a 1-hour outage. Instead, track open incidents in SQLite (PRAGMA journal_mode=WAL) with a cooldown window and explicit recovery transitions:

def should_notify_down(conn, monitor_id: str, now_ts: int, cooldown_sec: int = 900) -> bool:
    row = conn.execute(
        "SELECT id, last_alert_ts FROM incidents WHERE monitor_id = ? AND resolved_at IS NULL",
        (monitor_id,),
    ).fetchone()
    if row is None:
        conn.execute(
            "INSERT INTO incidents (monitor_id, started_at, last_alert_ts) VALUES (?, ?, ?)",
            (monitor_id, now_ts, now_ts),
        )
        conn.commit()
        return True
    inc_id, last_alert = row
    if now_ts - last_alert >= cooldown_sec:
        conn.execute("UPDATE incidents SET last_alert_ts = ? WHERE id = ?", (now_ts, inc_id))
        conn.commit()
        return True
    return False
Enter fullscreen mode Exit fullscreen mode

When the endpoint returns 200 OK again, close the open incident row, compute downtime_sec = now_ts - started_at, and fire a single RESOLVED alert.


3. HMAC-SHA256 Signed Webhooks + Exponential Backoff

When alerting downstream Slack/Discord/custom automation endpoints, sign every JSON payload with X-CronPulse-Signature and retry transient 5xx errors with exponential backoff so an alert never silently drops during a network blip:

import hashlib, hmac, json

def sign_payload(secret: str, payload: dict) -> tuple[bytes, str]:
    body = json.dumps(payload, separators=(",", ":"), sort_keys=True).encode("utf-8")
    sig = hmac.new(secret.encode("utf-8"), body, hashlib.sha256).hexdigest()
    return body, f"sha256={sig}"
Enter fullscreen mode Exit fullscreen mode

Want the Complete 20-File Production Kit Out of the Box?

If you want all of this wired up with concurrent checking, response-keyword verification, Telegram/Discord/HMAC Webhook notifiers, a self-contained static HTML Status Page generator (24h uptime %, average latency, SSL days left & incident timeline), Docker / docker-compose / systemd / Windows Task Scheduler templates, and a verified 7/7 real-HTTP-server pytest suite (MIT commercial license):

👉 CronPulse Pro — Self-Hosted Website Uptime, SSL & API Monitor ($19)

Also available:

  • WebWatch Pro ($14.99) — Self-hosted Playwright + Telegram screenshot monitor for JS-rendered price drops & restocks.
  • LocalVault Tools (Free) — 100% browser-local PDF merge/split/compress, EXIF stripper, static QR code & invoice utilities.

What's the most annoying outage or expired cert you've ever caught late? Drop it below!

Top comments (0)