A robust, TypeScript-based utility to monitor the availability of URLs and send alerts via Email or AWS SNS when availability changes.
- Multi-protocol support: Checks both HTTP and HTTPS URLs.
- Configurable Intervals: Set sleep time between checks and alert intervals.
- Modular Alerting System:
- Email: Send alerts via SMTP (Gmail, etc.).
- AWS SNS: Publish alerts to an SNS topic.
- Structured Logging: Uses
winstonfor clean, informative logs. - TypeScript: Typed, maintainable codebase.
The checker operates on a simple state machine logic for each URL:
- State Tracking: Each URL maintains a state of either
normal(200 OK) oralerted(Down / Non-200). - Check Loop: The system fetches the URL.
- If the response code is
200and the current state isalerted, it transitions back tonormal(Recovery). - If the response code is not
200(or timeout) and the current state isnormal, it transitions toalerted(Failure).
- If the response code is
- Alerting: Alerts are triggered only on state transitions.
- To prevent spam, alerts are throttled by a configurable
INTERVAL. If a transition happens but the last alert was sent too recently, the alert is skipped (but state is still updated).
- To prevent spam, alerts are throttled by a configurable
- Node.js (v14 or higher)
- npm or yarn
- Clone the repository.
- Install dependencies:
npm install
The application is configured using environment variables. You can set these in your shell or use a .env file loader (not included by default, but easy to add).
| Variable | Default | Description |
|---|---|---|
URLS |
https://www.google.com https://www.amazon.com |
Space-separated list of URLs to monitor. |
TIMEOUT |
1000 |
Request timeout in milliseconds. |
SLEEP |
15 |
Sleep time (seconds) between checking all URLs. |
INTERVAL |
300 |
Minimum interval (seconds) between repeat alerts for the same URL. |
| Variable | Description |
|---|---|
EMAIL_USER |
SMTP username (e.g., your gmail address). |
EMAIL_PASS |
SMTP password (or App Password). |
EMAIL_TO |
Recipient email address. |
EMAIL_SUBJ |
(Optional) Subject line for alerts. |
| Variable | Description |
|---|---|
AWS_ACCESS_KEY_ID |
AWS Access Key. |
AWS_SECRET_ACCESS_KEY |
AWS Secret Key. |
AWS_REGION |
AWS Region (e.g., us-east-1). |
AWS_TOPIC_ARN |
The ARN of the SNS topic to publish to. |
Start the application:
npm startThe project uses Jest for automated unit testing.
npm testThis will run tests for:
- Network utility
- Checker logic (state transitions, alerts)
- Alerter implementations (Email, AWS)
src/index.ts: Entry point.src/lib/: Core logic (Checker, Network, Logger).src/alerters/: Alerting implementations (Email, AWS) and Manager.src/config.ts: Configuration loading.src/types.ts: TypeScript interfaces.