Configurable server and service monitor for detecting outages, tracking recovery time, recording incidents, and sending local or remote alerts.
This project is intended for environments where it is important to know:
- when a service goes down
- when it comes back online
- how long the outage lasted
- what error was detected during the incident
- Monitoring via
http,tcp, orping - Configurable outage and recovery thresholds
- Persistent incident history in CSV format
- Runtime log output to file
- Local Windows alert with sound and popup window
- SMTP email alert support
- Webhook alert support
- Python 3.10 or later
- Windows if local sound and popup alerts are required
Clone the repository or download the project, then install the dependency:
pip install -r requirements.txtIf pip is not directly available:
python -m pip install -r requirements.txt- Copy the example configuration file:
Copy-Item .\config.example.json .\config.json-
Edit
config.jsonwith the URL, host, or port you want to monitor. -
Run a single test check:
python monitor_servidor.py --config config.json --once- Start continuous monitoring:
python monitor_servidor.py --config config.jsonThe monitor supports three check types:
http: validates a URL and compares the response code against expected valuestcp: validates that a host and port accept connectionsping: validates basic connectivity to a host
A local UniFi console commonly uses a self-signed certificate and may return a redirect instead of 200. A typical configuration looks like this:
{
"target": {
"name": "UniFi or local server",
"type": "http",
"url": "https://YOUR_HOST_OR_IP:8443/",
"method": "GET",
"timeout_seconds": 10,
"expected_status_codes": [200, 302],
"allow_redirects": false,
"verify_ssl": false
},
"monitoring": {
"check_interval_seconds": 10,
"failure_threshold": 2,
"recovery_threshold": 1,
"heartbeat_every_checks": 30
}
}In this setup:
verify_ssl: falseavoids failures caused by a self-signed certificateallow_redirects: falsekeeps the original response visible to the monitorexpected_status_codes: [200, 302]treats both responses as healthy
The public example file is config.example.json.
Main configuration sections:
target: what to monitor and how to check itmonitoring: interval and outage detection thresholdsalerts: email, webhook, and desktop notification settingsfiles: output paths for logs, state, and incident history
Key monitoring settings:
check_interval_seconds: how often to run checksfailure_threshold: number of consecutive failures required to declare an outagerecovery_threshold: number of consecutive successful checks required to declare recovery
Example:
check_interval_seconds = 10failure_threshold = 2
With that configuration, an outage is confirmed after 2 consecutive failed checks, usually in about 20 seconds.
The monitor can send alerts through three channels:
desktopemailwebhook
When alerts.desktop.enabled is set to true, the monitor can:
- play a loud alert sound when an outage is detected
- show a popup window with the outage details
Useful desktop options:
sound_on_downpopup_on_downsound_repeat_downsound_on_recoverypopup_on_recovery
SMTP configuration requires:
smtp_serversmtp_portusernamepasswordsender_emailrecipient_emails
Webhook payloads are supported for:
discordslackteamsgeneric
The following files are created during execution:
data/monitor.log: general runtime logdata/state.json: current monitoring statedata/incidentes.csv: outage and recovery history
Each entry saved to data/incidentes.csv includes:
- monitored target name
- check type
- hostname of the machine running the monitor
- outage start time
- recovery time
- duration in seconds
- human-readable duration
- failure reason
- failure details
- recovery details
This project is prepared to be published without exposing real local configuration.
The following are excluded from version control:
config.jsondata/__pycache__/
Use config.example.json as the public template and keep real values only in your local config.json.
Contributions are welcome for:
- new alert channels
- monitoring improvements
- better Windows service integration
- bug fixes and documentation updates
If you plan to contribute:
- Fork the repository.
- Create a feature branch.
- Make your changes with clear commits.
- Test the behavior locally.
- Open a pull request with a short description of the change.
.
|-- monitor_servidor.py
|-- config.example.json
|-- requirements.txt
|-- README.md
`-- data/