This Python script monitors changes in JSON responses from a specified endpoint and sends notifications via Discord webhook when changes are detected. It's designed to run continuously, checking for updates at regular intervals.
- Monitors JSON responses from any endpoint
- Sends notifications through Discord webhooks
- Generates and displays readable diffs of detected changes
- Caches responses to efficiently detect differences
- Auto-updates from the GitHub repository (optional)
- Easy setup with interactive prompts for configuration
- Can be run as a background service using PM2 with log rotation
- Python 3.6+
- Node.js and npm (for PM2 installation)
Install system packages:
sudo apt update
# python3
sudo apt install -y python3 python3-pip python3-venv
# npm and additional tools
sudo apt install jq npm -y
# pm2 and enable startup on reboot (careful, this restarts pm2 processes)
npm install pm2@latest -g && pm2 update && pm2 save --force && pm2 startup && pm2 save
Clone this repository:
export WATCHDOG_NAME="Name"
export WATCHDOG_SERVICE="name-watchdog"
cd $HOME
git clone https://github.com/sirouk/endpoint-watchdog $WATCHDOG_SERVICE
Install the required Python packages:
cd $HOME/$WATCHDOG_SERVICE
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Run the script:
cd $HOME/$WATCHDOG_SERVICE
source .venv/bin/activate
python3 endpoint_watchdog.py
On the first run, you will be prompted to enter your endpoint URL, watch interval, Discord webhook URL, and Discord mention code. The script will validate these inputs and save them to a .env
file for future use. Kill the script with Ctrl+C
to stop it if you plan to run it as a service with PM2.
Start the PM2 service:
pm2 start endpoint_watchdog.py --name "$WATCHDOG_SERVICE" --interpreter python3 -- "$WATCHDOG_NAME"
pm2 save --force
pm2 logs $WATCHDOG_SERVICE
Set up PM2 Logrotate:
# Install pm2-logrotate module
pm2 install pm2-logrotate
# Set maximum size of logs to 50M before rotation
pm2 set pm2-logrotate:max_size 50M
# Retain 10 rotated log files
pm2 set pm2-logrotate:retain 10
# Enable compression of rotated logs
pm2 set pm2-logrotate:compress true
# Set rotation interval to every 6 hours
pm2 set pm2-logrotate:rotateInterval '00 */6 * * *'
To view logs:
pm2 logs $WATCHDOG_SERVICE
To stop the service:
pm2 stop $WATCHDOG_SERVICE
To restart the service:
pm2 restart $WATCHDOG_SERVICE
The script uses the following variables that you can configure in the .env
file or during the initial setup:
ENDPOINT_URL
: The URL of the JSON endpoint to monitorWATCH_INTERVAL
: The interval in minutes between each checkDISCORD_WEBHOOK_URL
: The Discord webhook URL to send notificationsDISCORD_MENTION_CODE
: The Discord group to tag for the change notifications. You can get this by putting a \ in front of a mention and sending a message in discord GUI client
Additional constants in the code:
CACHE_FILE
: Filename for caching responsesauto_update_enabled
: Set toTrue
to enable auto-updates from the GitHub repositoryUPDATE_INTERVAL_MULTIPLIER
: Multiplier for how often updates are checked relative to the watch intervalDISCORD_MAX_LENGTH
: Maximum size of a message to send to Discord before truncationDPASTE_MAX_LENGTH
: Maximum size of the diff to to include in a dpaste link before truncation
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This script is not officially associated with any endpoint provider. Use at your own risk.