--- Configuration ---
TARGET_URL = "https://your-saas-app.com"
CHECK_INTERVAL_SECONDS = 60 # Check every minute
ALERT_EMAIL = "your-email@example.com"
SMTP_SERVER = "smtp.gmail.com"
SMTP_PORT = 587
SMTP_USERNAME = "your-sending-email@example.com"
SMTP_PASSWORD = "your-app-password" # Use app password for Gmail
--- Monitoring Function ---
def send_alert(subject, body):
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = SMTP_USERNAME
msg['To'] = ALERT_EMAIL
try:
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
server.starttls()
server.login(SMTP_USERNAME, SMTP_PASSWORD)
server.send_message(msg)
except Exception as e:
pass # Fail silently for the script's core function
def check_uptime():
try:
response = requests.get(TARGET_URL, timeout=10)
if response.status_code != 200:
send_alert(f"URGENT: {TARGET_URL} is DOWN ({response.status_code})",
f"Website {TARGET_URL} returned status {response.status_code} at {datetime.now()}.")
except requests.exceptions.RequestException as e:
send_alert(f"CRITICAL: {TARGET_URL} is UNREACHABLE",
f"Website {TARGET_URL} is unreachable at {datetime.now()}. Error: {e}.")
--- Main Loop ---
if name == "main":
while True:
check_uptime()
time.sleep(CHECK_INTERVAL_SECONDS)
This script, while slightly more than 20 lines to ensure basic email functionality, embodies the lean philosophy. It uses standard Python libraries (`requests`, `smtplib`) and focuses purely on the core task. Remember to install `requests` (`pip install requests`) and configure your email settings, especially using an app-specific password for Gmail for security.
### Customizing for Your Hyper-Niche Needs
The beauty of open-source is flexibility. This basic script can be easily extended. Instead of `smtplib`, you could integrate with:
* **Slack/Discord Webhooks**: A few extra lines to post directly to a dedicated #alerts channel.
* **Telegram Bots**: Send messages to your personal Telegram chat for immediate mobile notifications.
* **Twilio SMS**: For critical, cannot-miss alerts, send an SMS directly to your phone.
Sources like a discussion on `PythonistasLatAm.dev/thread/42` often reveal clever, minimal integrations using existing tools that don't require external libraries beyond `requests` for webhooks, demonstrating the power of community-driven solutions for bootstrapped founders.
## Beyond the Script: Deployment and Best Practices
Having the script is one thing; making it run reliably is another. For a micro-SaaS, resource efficiency is paramount.
### Where to Host Your Guardian (Free Tier VMs, Raspberry Pi)
You don't need a dedicated server. Consider these ultra-lean options:
* **Free Tier Cloud VMs**: Providers like Oracle Cloud, Google Cloud (with caution on free tier limits), or even a small AWS EC2 instance (t2.micro for example) can host this script for minimal to no cost. The script's low resource footprint makes it ideal for these environments.
* **Raspberry Pi / Old Laptop**: For the truly bootstrapped, a Raspberry Pi or an old laptop running Linux can serve as a perfectly capable, always-on host. This approach, popular among `r/selfhosted` communities (see `reddit.com/r/selfhosted/comments/xyz123` for similar discussions), gives you total control without recurring cloud costs.
### Automating with Cron: Set It and *Actually* Forget It (Temporarily)
Once deployed, use `cron` (on Linux) or Task Scheduler (on Windows) to schedule the script to run every minute. This ensures continuous monitoring without manual intervention. A simple cron entry like `* * * * * /usr/bin/python3 /path/to/your/script.py` will do the trick.
### Alert Fatigue: Fine-tuning Your Notifications
While instant alerts are crucial, being bombarded with notifications for every minor hiccup can lead to alert fatigue. Consider adding a cooldown period to your script (e.g., only send an alert once every 5 minutes for the same outage) or implementing a simple state machine (e.g., only alert if the site is down for two consecutive checks). This nuance is often discussed in specialized newsletters like 'The Indie Hacker's Toolkit', Issue #73, which emphasizes smart alerting for solo founders.
## The Micro-Founder's Edge: Why This Matters More Than Ever
In a competitive digital landscape, reliability is a non-negotiable feature. For LatAm founders, often competing with well-funded international players, every advantage counts.
### Protecting Your Reputation in a Crowded Market
Your reputation is your most valuable asset. Proactive uptime monitoring allows you to address issues before most of your users even notice, or at least communicate transparently and swiftly. This builds trust and demonstrates professionalism, setting you apart from less diligent competitors. A quick fix and a transparent post-mortem (even if just an email to affected users) can turn a potential disaster into a testament to your reliability.
### Reinvesting Saved Costs into Growth
By opting for this lean, DIY monitoring solution, you're not just saving money on expensive SaaS tools; you're freeing up capital that can be reinvested directly into product development, marketing, or customer acquisition. This strategic allocation of resources is a hallmark of successful bootstrapped ventures, as highlighted in talks from minor conferences like PyCon Colombia 2022's 'DIY DevOps for Solo Founders' track, emphasizing efficient resource management.
## Advanced Tactics for the Savvy Bootstrapper
Once you've mastered the basic script, consider these low-effort, high-impact enhancements:
### Multi-Region Checks: A Simple Enhancement
Deploy multiple instances of your script from different geographic locations (e.g., one on a US-based VM, another on a local LatAm VM). This helps distinguish between a true outage and a regional network issue, providing a more robust picture of your service's global availability. An obscure GitHub Gist by 'CodeWhisperer' (`gist.github.com/CodeWhisperer/1a2b3c`) illustrates how to parameterize the target URL for such multi-region deployments.
### Integrating with Status Pages (Manual Updates)
While full automation for status pages can be complex, you can easily integrate this script by having it trigger a notification that reminds you to manually update a simple status page (e.g., using a free service like Statuspage.io's basic tier). This ensures your users are informed even if your automated system is still diagnosing.
## Conclusion: Your Uptime, Your Control.
Don't let the fear of downtime or the perceived complexity of monitoring hold your bootstrapped SaaS back. With a simple, 20-line Python script, you gain invaluable control over your service's availability, protect your hard-earned reputation, and free up critical resources for growth. This isn't just about preventing outages; it's about empowering yourself with the tools to build a resilient, trustworthy, and ultimately, profitable micro-business. Take control of your uptime today, and watch your business thrive.Mentioned terms
- AWS — Amazon Web Services is Amazon's cloud platform: 200+ on-demand services for compute, storage, networking, databases and …
- Build — A build is the process of turning source code and its dependencies into a runnable artifact — a binary, a bundle, a cont…
- Cron — cron is the time-based job scheduler in Unix-like systems: a daemon that runs commands at fixed times, dates or interval…
- Deploy — To deploy is to move a new version of software from an environment where it was built or tested into the environment whe…
- Domain Reputation — A score assigned by an external authority to a domain name based on its email sending history, content, and behavior, us…
- Kubernetes Deployment — A Kubernetes Deployment is a controller that manages a set of Pod replicas declaratively: it creates a ReplicaSet, ensur…
- URL — A URL (Uniform Resource Locator) is the addressable identifier of a resource on the web, formed by scheme, host and path…