Perl Site-Health Watchdog with SMTP Alerts
Build a Perl watchdog that checks a list of your websites every few minutes with LWP::UserAgent, records whether each is up and how long it took to answer, and sends an email through SMTP when a site goes down or becomes slow, and again when it recovers, without repeating the same alert. Sites and limits are set in a config file, results are logged, and it runs from cron. Only monitor sites you own or manage. It's a good intermediate Perl project: you'll learn HTTP requests and timing with LWP::UserAgent and Time::HiRes, keeping state between runs, sending email with Net::SMTP (with TLS and login) or Email::Sender, reading YAML configs, logging, and testing.
- Estimate
- ~8h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
LWP::UserAgent · Net::SMTP
Project roadmap
- 01
Check the URLs
~1.5hWrite watchdog.pl that, for each URL, sends a request with LWP::UserAgent (with a timeout and a descriptive agent name), measures the time with Time::HiRes, and classifies the result: up (expected status), slow (over the time limit), down (wrong status) or unreachable (connection error or timeout, from the response's error message). Done when: running it prints each site's status and response time.
- 02
Load the config
~1hRead a YAML config (with YAML::XS or YAML::Tiny): sites with a name, URL, expected status codes and a slow limit; how many failed checks in a row mean down; and the email settings (SMTP host, port, user, sender and recipients), with the password from an environment variable. Validate it and stop with clear messages when it's wrong. Done when: a valid config loads, and mistakes are reported clearly.
- 03
Track state and detect changes
~1.5hKeep each site's state (up, slow or down, consecutive failures and since when) in a JSON state file, loaded at start and saved at the end (written to a temporary file and renamed), locked with flock so overlapping runs can't clash. Declare a site down only after N failures in a row, and detect changes between states. Done when: states survive between runs, and a single failed check doesn't count as down.
- 04
Send email alerts
~1.5hWhen a site's state changes, send an email with Net::SMTP (using starttls and auth) or Email::Sender with an SMTP transport: a clear subject such as [DOWN] shop.example.com, and a body with the time, status, response time and how long it was down on recovery. Log send failures without crashing. Add --test-email to check the settings. Done when: a state change sends exactly one email, and a test email arrives.
- 05
Schedule and log
~1hLog every check (time, site, status, response time and state) to a log file, and add an example crontab line running it every 5 minutes with full paths. Add --once for testing and --status to print the current state of every site. Done when: the watchdog runs from cron, and the log records each check.
- 06
Test it
~1.5hWrite Test::More tests with a local HTTP server (HTTP::Daemon or Plack) that can answer normally, slowly, with errors or not at all, and with a fake mail sender that records messages: classification, the failures-in-a-row rule, one alert per state change, recovery messages and state file handling. Done when: prove -l t/ passes.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack