A Python-based script that allows you to monitor the status of servers and services. It supports various monitoring types such as ping, port check, HTTP(s) check, and keyword check. You can easily configure the script to monitor your desired servers and receive notifications via Telegram.
- Ping: Checks the reachability and latency of a target IP address.
- Port Check: Verifies if a specific port on a target IP address is open.
- HTTP(s) Check: Sends an HTTP(s) request to a target URL and checks the response status code. It validates that the status code is 200 and the SSL certificate is present in case it's a https target.
- Keyword Check: Verifies if a specific keyword is present or absent in the response content of an HTTP(s) request.
Install Docker
curl -sSL https://get.docker.com | sh
Download pymon
mkdir -p /opt && cd /opt/ && git clone https://github.com/iandk/pymon.git
Edit configuration
# settings
mv /opt/pymon/settings-sample.json /opt/pymon/settings.json
nano /opt/pymon/settings.json
# monitoring targets
mv /opt/pymon/servers-sample.json /opt/pymon/servers.json
nano /opt/pymon/servers.json
Build container
cd pymon && docker build -t pymon:latest .
Run container
docker run -d --name pymon -v /opt/pymon:/opt/pymon --network host pymon
You have two options for running the script: running it in the background, which will automatically monitor for status changes, or running it in the terminal with a graphical output.
To run the script as a background service, follow the steps below:
- Clone the repository to your local machine:
mkdir -p /opt && cd /opt/
git clone https://github.com/iandk/pymon.git
cd pymon && bash install.sh
- Edit configuration
# settings
mv /opt/pymon/settings-sample.json /opt/pymon/settings.json
nano /opt/pymon/settings.json
# monitoring targets
mv /opt/pymon/servers-sample.json /opt/pymon/servers.json
nano /opt/pymon/servers.json
- Start pymon
systemctl start pymon
systemctl status pymon
To run the script in the terminal with a graphical output, use the following command:
Note: The terminal view should only be used if the system service is stopped. Running both the service and terminal view simultaneously may cause conflicts.
cd /opt/pymon/ && myvenv/bin/python3 main.py
The monitoring script utilizes two configuration files: servers.json to specify monitoring targets such as descriptions, types, and targets, and settings.json to configure application behavior including bot token, chat ID, intervals, and notification preferences
servers.json
-
description
: A brief description of the server or service being monitored. -
type
: The type of monitoring to perform. Supported types are:ping
: Checks the reachability and latency of a target IP address.port
: Verifies if a specific port on a target IP address is open.http
: Sends an HTTP(s) request to a target URL and checks the response status code.keyword
: Verifies if a specific keyword is present or absent in the response content of an HTTP(s) request.
-
target
: The IP address or URL of the server or service to monitor. -
port
(only forport
type): The port number to check for theport
monitoring type. -
keyword
(only forkeyword
type): The keyword to search for in the response content. -
expect_keyword
(only forkeyword
type): Set totrue
if the keyword should be present, orfalse
if it should be absent.
settings.json
-
bot_token
: The token of your Telegram bot. You can obtain this token by creating a bot using the BotFather bot on Telegram. -
chat_id
: The chat ID where you want to receive the monitoring notifications. You can find the chat ID by sending a message to your bot and then accessing the following URL:https://api.telegram.org/bot<bot_token>/getUpdates
. -
failure_threshold
: The number of consecutive failures before considering a server as "Down". -
check_interval_seconds
: The interval, in seconds, between each server check. -
status_report_interval_minutes
: The interval, in minutes, between each status report. The script will send a status report message at this interval, indicating the overall status of all monitored servers. -
report_only_on_down
: Set this value totrue
if you want to receive status report messages only when a server is "Down". Set it tofalse
if you want to receive status report messages regardless of the server status.
Example configuration
{
"servers": [
{
"description": "1.1.1.1",
"type": "ping",
"target": "1.1.1.1"
},
{
"description": "v6Node.com",
"type": "http",
"target": "https://v6node.com"
},
{
"description": "Google",
"type": "port",
"target": "google.com",
"port": 80
},
{
"description": "v6Node Keyword check",
"type": "keyword",
"target": "https://v6node.com",
"keyword": "v6node",
"expect_keyword": true
}
]
}