71 lines
2.7 KiB
Markdown
71 lines
2.7 KiB
Markdown
# Synology Monitor Service
|
|
|
|
This is a lightweight Python monitoring service designed to keep track of the availability of critical servers. It periodically pings defined endpoints to ensure they are online and responsive.
|
|
|
|
## Features
|
|
* **Heartbeat & Outage Alerts:** Sends a regular heartbeat status check to a Rocket.Chat webhook.
|
|
* **Email Notifications:** Triggers beautifully formatted HTML emails exclusively when a server goes down, and sends a follow-up recovery email when the server comes back online.
|
|
* **State Persistence:** Keeps track of the downtime duration so recovery alerts can report exactly how long the outage lasted.
|
|
* **Easy Testing:** Built-in `--test-email` flag to trigger an instant test of the email formatting without waiting for the scheduled check.
|
|
|
|
## Local Development & Testing
|
|
|
|
1. Create a Python virtual environment:
|
|
```bash
|
|
python -m venv venv
|
|
```
|
|
2. Activate the virtual environment:
|
|
* **Windows (PowerShell):** `.\venv\Scripts\Activate.ps1`
|
|
* **Linux/Mac:** `source venv/bin/activate`
|
|
3. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
4. Copy `.env.example` to `.env` and fill in your credentials.
|
|
5. Run the script:
|
|
```bash
|
|
python monitor.py
|
|
```
|
|
*(To test the email layout instantly: `python monitor.py --test-email`)*
|
|
|
|
---
|
|
|
|
## Production Deployment (Linux / VPS)
|
|
|
|
This repository includes a deployment script (`deploy.sh`) and a systemd service file (`synology-monitor.service`) to easily deploy this as a continuous background service on a Linux server.
|
|
|
|
### Step 1: Clone the repository to the server
|
|
```bash
|
|
git clone https://git.seekright.com/kaushik/Enigma-Synology-Monitor.git
|
|
cd Enigma-Synology-Monitor
|
|
```
|
|
|
|
### Step 2: Run the deployment script
|
|
The provided `deploy.sh` script automates the installation. It will:
|
|
* Create a dedicated, secure system user named `monitor`.
|
|
* Copy the files to `/opt/synology-monitor`.
|
|
* Set up a fresh Python virtual environment and install dependencies.
|
|
* Install and enable the `systemd` service.
|
|
|
|
Run it with sudo:
|
|
```bash
|
|
sudo bash deploy.sh
|
|
```
|
|
|
|
### Step 3: Configure your credentials
|
|
The deployment script creates a skeleton `.env` file from the example. You **must** edit this file and add your actual SMTP passwords and RocketChat webhooks before starting the service:
|
|
```bash
|
|
sudo nano /opt/synology-monitor/.env
|
|
```
|
|
|
|
### Step 4: Start the service
|
|
Once your `.env` file is saved, start the background monitor:
|
|
```bash
|
|
sudo systemctl start synology-monitor
|
|
```
|
|
|
|
### Useful Commands
|
|
* **Check the status:** `sudo systemctl status synology-monitor`
|
|
* **View live logs:** `sudo journalctl -u synology-monitor -f`
|
|
* **Stop the monitor:** `sudo systemctl stop synology-monitor`
|