Skip to content

This Python script monitors Docker resources (containers, images, volumes, networks) and sends notifications when changes are detected. It supports various messaging services such as Telegram, Discord, Slack, Gotify, Ntfy, Pushbullet, Pushover, and Matrix.

Notifications You must be signed in to change notification settings

2boom-ua/dockcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Monitoring & Notification Script

This Python script monitors Docker resources (containers, images, volumes, networks) and sends notifications when changes are detected. It supports various messaging services.

Features

  • Monitors Docker resources:
    • Containers (running, stopped, created, unhealthy, etc.)
    • Images (pulled, removed, unused)
    • Volumes and Networks (created, removed, unused)
  • Real-time notifications with support for multiple accounts via:
    • Telegram
    • Discord
    • Slack
    • Gotify
    • Ntfy
    • Pushbullet
    • Pushover
    • Matrix
  • Customizable polling interval through a configuration file (config.json).
  • Periodic checks with Docker resource updates logged and reported.

Requirements

  • Python 3.x
  • Docker installed and running
  • Dependencies: docker, requests, schedule

Clone the repository:

git clone https://github.com/2boom-ua/dockcheck.git
cd dockcheck

Install required Python packages:

pip install -r requirements.txt

Edit config.json:

A config.json file in the same directory as the script, and include your API tokens and configuration settings.

{
    "TELEGRAM": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ],
        "CHAT_IDS": [
            "first chat_id",
            "second chat_id",
            "...."
        ]
    },
    "DISCORD": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ]
    },
    "SLACK": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ]
    },
    "GOTIFY": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ],
        "CHAT_URLS": [
            "first server_url",
            "second server_url",
            "...."
        ]
    },
    "NTFY": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ],
        "CHAT_URLS": [
            "first server_url",
            "second server_url",
            "...."
        ]
    },
    "PUSHBULLET": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ]
    },
    "PUSHOVER": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ],
        "USER_KEYS": [
            "first user_key",
            "second user_key",
            "...."
        ]
    },
    "MATRIX": {
        "ON": false,
        "TOKENS": [
            "first tocken",
            "second tocken",
            "...."
        ],
        "SERVER_URLS": [
            "first server_url",
            "second server_url",
            "...."
        ],
        "ROOM_IDS": [
            "!first room_id",
            "!second room_id",
            "...."
        ]
    },
    "DEFAULT_DOT_STYLE": true,
    "SEC_REPEAT": 10
}

Running as a Linux Service

You can set this script to run as a Linux service for continuous monitoring.

Create a systemd service file:

nano /etc/systemd/system/dockcheck.service

Add the following content:

[Unit]
Description=docker state change monitor
After=multi-user.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 /opt/dockcheck/dockcheck.py

[Install]
WantedBy=multi-user.target

Start and enable the service:

systemctl daemon-reload
systemctl enable dockcheck.service
systemctl start dockcheck.service

License

This project is licensed under the MIT License - see the MIT License for details.

Author

About

This Python script monitors Docker resources (containers, images, volumes, networks) and sends notifications when changes are detected. It supports various messaging services such as Telegram, Discord, Slack, Gotify, Ntfy, Pushbullet, Pushover, and Matrix.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages