Extensible monitoring agent with Uptime Kuma integration. Includes port scanning with heartbeat monitoring.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
Kuma Sentinel
Extensible monitoring agent with Uptime Kuma integration. Currently includes port scanning with heartbeat health monitoring.
A Python CLI tool that scans specified IP ranges for open TCP ports using nmap and reports the results to Uptime Kuma with separate push tokens for heartbeat monitoring and port-scan alerts. Designed to be extended with additional monitoring checks like ZFS pools, disk space, etc.
Features
- Nmap Integration: Powerful network scanning with configurable port ranges and timing profiles
- Uptime Kuma Integration: Reports scan results and health status to Uptime Kuma monitoring
- Heartbeat Monitoring: Sends periodic heartbeat pings during long scans to signal agent health and activity
- Flexible Configuration: Support for INI config files, environment variables, and CLI arguments with clear priority
- Multi-Source Configuration:
- Command-line arguments (highest priority)
- INI config file
- Environment variables
- Hardcoded defaults (lowest priority)
- Comprehensive Logging: File, console, and syslog/journalctl output
- Exclusion Lists: Exclude specific IPs/ranges from scans
- Extensible Architecture: Built to support additional monitoring checks beyond port scanning
Installation
Via pip (PyPI)
pip install kuma-sentinel
From source
git clone https://go.hugobatista.com/gh/kuma-sentinel.git
cd kuma-sentinel
pip install -e .
Development installation
pip install -e ".[dev]"
Docker
You can run Kuma Sentinel in a Docker container for isolated execution and easy deployment.
Using docker-compose (Recommended)
- Copy the example environment file:
cp .env.example .env
- Edit
.envwith your configuration:
# Set your Uptime Kuma URL and tokens
export UPTIME_KUMA_URL=http://uptimekuma:3001/api/push
export UPTIME_KUMA_HEARTBEAT_TOKEN=your-heartbeat-token
export UPTIME_KUMA_PORTSCAN_TOKEN=your-portscan-token
- Build and run:
docker-compose up --build -it
- Run a scan inside the container:
docker-compose exec kuma-sentinel portscan 192.168.100.110-199 $UPTIME_KUMA_URL $UPTIME_KUMA_HEARTBEAT_TOKEN $UPTIME_KUMA_PORTSCAN_TOKEN
Using docker run directly
docker build -t kuma-sentinel:latest .
# Linux/macOS
docker run -it --rm \
-v $(pwd)/config.ini:/etc/kuma-sentinel/config.ini:ro \
-v $(pwd)/logs:/var/log/kuma-sentinel \
kuma-sentinel:latest \
portscan 192.168.100.110-199 http://uptimekuma:3001/api/push your-heartbeat-token your-portscan-token
# Windows (PowerShell)
docker run -it --rm `
-v ${pwd}/config.ini:/etc/kuma-sentinel/config.ini:ro `
-v ${pwd}/logs:/var/log/kuma-sentinel `
kuma-sentinel:latest `
portscan 192.168.100.110-199 http://uptimekuma:3001/api/push your-heartbeat-token your-portscan-token
Usage
Port Scan
kuma-sentinel portscan 192.168.1.0/24 http://uptimekuma:3001/api/push your-heartbeat-token your-portscan-token
With Custom Ports and Timing
kuma-sentinel portscan \
--ports 22,80,443,3389 \
--timing T4 \
192.168.100.0/24 \
http://uptimekuma:3001/api/push \
your-heartbeat-token \
your-portscan-token
Multiple IP Ranges
kuma-sentinel portscan \
192.168.1.0/24 \
10.0.0.0/8 \
172.16.0.0/12 \
http://uptimekuma:3001/api/push \
your-heartbeat-token \
your-portscan-token
Using Configuration File
kuma-sentinel portscan --config /etc/kuma-sentinel/config.ini
With Exclusions
kuma-sentinel portscan \
--exclude 192.168.1.1,192.168.1.254 \
192.168.1.0/24 \
http://uptimekuma:3001/api/push \
your-heartbeat-token \
your-portscan-token
Help
kuma-sentinel --help
kuma-sentinel portscan --help
Configuration
INI File Format
Default location: /etc/kuma-sentinel/config.ini
[logging]
log_file = /var/log/kuma-sentinel.log
[heartbeat]
enabled = true
interval = 300
[uptime_kuma]
url = http://uptimekuma:3001/api/push
heartbeat_token = your-heartbeat-token
portscan_token = your-portscan-token
[portscan.nmap]
timing = T3
arguments =
keep_xml_output = false
[portscan.targets]
ports = 1-1000
exclude_ips = 192.168.1.1,192.168.1.254
ip_ranges = 192.168.1.0/24,10.0.0.0/8
Environment Variables
KUMA_SENTINEL_LOG_FILE=/var/log/kuma-sentinel.log
KUMA_SENTINEL_HEARTBEAT_ENABLED=true
KUMA_SENTINEL_HEARTBEAT_INTERVAL=300
KUMA_SENTINEL_NMAP_PORTS=1-1000
KUMA_SENTINEL_NMAP_TIMING=T3
KUMA_SENTINEL_NMAP_EXCLUDE_IPS=192.168.1.1
KUMA_SENTINEL_NMAP_ARGUMENTS=--script vuln
KUMA_SENTINEL_NMAP_KEEP_XMLOUTPUT=false
CLI Arguments
kuma-sentinel portscan \
--ports 22,80,443 \
--timing T4 \
--exclude 192.168.1.1 \
--log-file /tmp/scan.log \
192.168.1.0/24 \
http://uptimekuma:3001/api/push \
your-heartbeat-token \
your-portscan-token
Nmap Timing Profiles
T0: Paranoid - Very slow, useful for IDS evasionT1: Sneaky - Slow, IDS evasionT2: Polite - Slowed to minimize network loadT3: Normal - Default, no delaysT4: Aggressive - Fast, assumes reasonable networkT5: Insane - Very fast, assumes excellent network
Cron Job Example
# Run scan every 30 minutes
*/30 * * * * kuma-sentinel portscan --config /etc/kuma-sentinel/config.ini
Systemd Timer Example
Create /etc/systemd/system/kuma-sentinel.service:
[Unit]
Description=Kuma Sentinel Monitoring Agent
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/kuma-sentinel portscan --config /etc/kuma-sentinel/config.ini
StandardOutput=journal
StandardError=journal
Create /etc/systemd/system/kuma-sentinel.timer:
[Unit]
Description=Kuma Sentinel Timer
[Timer]
OnBootSec=2min
OnUnitActiveSec=30min
Persistent=true
[Install]
WantedBy=timers.target
Then enable and start:
systemctl enable kuma-sentinel.timer
systemctl start kuma-sentinel.timer
systemctl status kuma-sentinel.timer
Uptime Kuma Push Tokens
Creating Monitors
-
In Uptime Kuma, create two new Push monitors:
- Heartbeat Monitor: Reports agent health every X seconds (shared across all commands)
- Port-Scan Monitor: Reports port scan results (UP=all ports closed, DOWN=open ports found)
-
Configure with appropriate heartbeat intervals (suggest 10-15 minutes for heartbeat monitor)
-
Copy the push tokens to your configuration
Logging
Logs are written to:
- File: Configured in
log_file(default:/var/log/kuma-sentinel.log) - Console: Standard output for direct execution
- Journalctl: Syslog integration for systemd systems
Example log output:
[2024-01-18 14:30:00] 🔍 PORT SCANNER CONFIGURATION SUMMARY
[2024-01-18 14:30:00] 📝 Nmap Configuration:
[2024-01-18 14:30:00] Ports: 1-1000
[2024-01-18 14:30:00] Timing: T3
[2024-01-18 14:30:00] 🔍 Running: nmap -p 1-1000 -T3 -oX /tmp/nmap_output.xml 192.168.1.0/24
[2024-01-18 14:30:15] ✅ Heartbeat sent: Port scan in progress...
[2024-01-18 14:35:00] ✅ Nmap scan completed successfully
[2024-01-18 14:35:00] ✅ Parsed XML: found 3 hosts with open ports
[2024-01-18 14:35:00] ⚠️ Open ports found: 192.168.1.10:22/tcp,80/tcp, 192.168.1.11:443/tcp
[2024-01-18 14:35:01] ✅ Port alert sent (down): Open ports found: 192.168.1.10:22/tcp,80/tcp, 192.168.1.11:443/tcp (5m)
[2024-01-18 14:35:02] ✅ Port scanner complete (5m)
Requirements
- Python 3.7+
- nmap (must be installed on system and in PATH)
- click (installed automatically)
Development
Setup
git clone https://go.hugobatista.com/gh/kuma-sentinel.git
cd kuma-sentinel
pip install -e ".[dev]"
Running Tests
pytest
pytest --cov=src/kuma_sentinel
pytest -v
Code Quality
# Lint with ruff
ruff check src/ tests/
# Format with black
black src/ tests/
# Fix linting issues
ruff check --fix src/ tests/
Building Package
python -m pip install build
python -m build
License
MIT License - See LICENSE file for details
Author
Hugo Batista - GitHub
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run tests and linting
- Submit a pull request
Issues
Found a bug? Report it on GitHub Issues
Related Projects
- Uptime Kuma - Self-hosted monitoring tool
- Nmap - Network mapper and security scanner
- Click - Python CLI framework
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kuma_sentinel-0.0.1.tar.gz.
File metadata
- Download URL: kuma_sentinel-0.0.1.tar.gz
- Upload date:
- Size: 86.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d92714deabb2427e43a136deb5964da2585d72800b961ff2a56f37840cb75ae5
|
|
| MD5 |
99d80a95be18b0ad32d86e7771e496cf
|
|
| BLAKE2b-256 |
d69fda836205e5e6675a767c20bd4cfc7858ea8947014e5f3343fcbb8c002774
|
Provenance
The following attestation bundles were made for kuma_sentinel-0.0.1.tar.gz:
Publisher:
build-and-publish-to-pypi.yml on 0x6f677548/kuma-sentinel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kuma_sentinel-0.0.1.tar.gz -
Subject digest:
d92714deabb2427e43a136deb5964da2585d72800b961ff2a56f37840cb75ae5 - Sigstore transparency entry: 833810041
- Sigstore integration time:
-
Permalink:
0x6f677548/kuma-sentinel@b10464a3b5ab7dc6c2b2b1c5633c861c238de239 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/0x6f677548
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish-to-pypi.yml@b10464a3b5ab7dc6c2b2b1c5633c861c238de239 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kuma_sentinel-0.0.1-py3-none-any.whl.
File metadata
- Download URL: kuma_sentinel-0.0.1-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
113090a071d053044b299dc0f6a1315a74d8a685f66445cd2c56de7ded191669
|
|
| MD5 |
a431fb7181ce14a36f517023ff9e875d
|
|
| BLAKE2b-256 |
645ef1402de2a9e57d528d64814eb6b1efd1132f8211deacf7735eaf5efcdc24
|
Provenance
The following attestation bundles were made for kuma_sentinel-0.0.1-py3-none-any.whl:
Publisher:
build-and-publish-to-pypi.yml on 0x6f677548/kuma-sentinel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kuma_sentinel-0.0.1-py3-none-any.whl -
Subject digest:
113090a071d053044b299dc0f6a1315a74d8a685f66445cd2c56de7ded191669 - Sigstore transparency entry: 833810042
- Sigstore integration time:
-
Permalink:
0x6f677548/kuma-sentinel@b10464a3b5ab7dc6c2b2b1c5633c861c238de239 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/0x6f677548
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish-to-pypi.yml@b10464a3b5ab7dc6c2b2b1c5633c861c238de239 -
Trigger Event:
release
-
Statement type: