The Notifier is a Go-based application that periodically checks the connectivity of remote services and sends SMS notifications to administrators if any service becomes unreachable. It is designed to be simple, reliable, and easy to configure.
- Periodic Service Checks: Monitors services at a configurable interval (e.g., every 5 minutes).
- SMS Notifications: Sends SMS alerts to multiple administrators if a service is down.
- Graceful Shutdown: Handles termination signals (e.g.,
Ctrl+C) gracefully. - Configurable: Supports configuration via environment variables or a customer env file.
- HTTP Connectivity Checks: Uses http to verify service availability
- TCP Connectivity Checks: Uses TCP (Telnet) to verify service availability. (WIP)
- Go 1.20 or higher
- An SMS gateway API endpoint (for sending notifications)
-
Clone the repository:
git clone https://github.com/fruganyumisa/notifier.git cd notifier -
Install dependencies:
go mod tidy
-
Build the application:
go build -o notifier ./cmd/notifier
The service can be configured using either a Environment File or os environment variables.
Create a config.env file in the root directory:
SERVICES="http://host1:8080,http://host2:22"
CHECK_INTERVAL="5m"
SMS_GATEWAY_URL="http://sms-gateway.com/send
NOTIFIER_ADMIN_PHONES="+1234567890,+0987654321"
NOTIFIER_SENDER_HEADER="ALERTS"Alternatively, you can configure the service using environment variables:
export NOTIFIER_SERVICES="http://host1:8080,http://host2:22"
export NOTIFIER_CHECK_INTERVAL="5m"
export NOTIFIER_SMS_GATEWAY_URL="http://sms-gateway.com/api/send"
export NOTIFIER_ADMIN_PHONES="+1234567890,+0987654321"
export NOTIFIER_SENDER_HEADER="ALERTS"Start the service using the following command:
./notifierWhen a service is down, the following SMS message is sent to administrators:
🚨 Service Alert 🚨
Service: {ServiceName}
Status: Down
Time: {Timestamp}
Details:
{FailureDetails}
Action Required:
Please investigate immediately. Check server logs and restart if necessary.
The service supports graceful shutdown. When a termination signal (e.g., Ctrl+C) is received, it stops the monitoring process and cleans up resources before exiting.
notifier/
├── cmd/
│ └── notifier/
│ └── main.go # Entry point of the application
├── internal/
│ ├── config/
│ │ └── config.go # Configuration management
│ ├── notifier/
│ │ ├── checker.go # Service connectivity checker
│ │ ├── sms.go # SMS notification logic
│ │ └── notifier.go # Main notifier logic
│ ├── models/
│ │ └── models.go # Data models (e.g., SMSRequest)
│ └── utils/
│ └── utils.go # Utility functions (e.g., joinStrings)
├── config.env # Configuration file (optional)
├── go.mod # Go module file
├── go.sum # Go dependencies checksum file
└── README.md # Project documentation
Starting notifier service...
Notifier started. Waiting for the first tick...
Tick received. Checking services...
Checking service: host1:8080
Connection to host1:8080 succeeded.
Service host1:8080 is up.
Checking service: host2:22
Connection to host2:22 failed: dial tcp ...
Service host2:22 is down.
Sending SMS notification: Services down: host2:22
SMS notification sent successfully.
^CReceived signal: interrupt. Shutting down...
Received shutdown signal. Stopping notifier...
Notifier service stopped.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or issues, please open an issue on the GitHub repository.
- Built with ❤️ using Go.
- Inspired by the need for reliable service monitoring and alerting.
- Appreciating code review and technical support from Sr. Go Eng Bethuel Mmbaga
Enjoy using the Notifier!