Compare commits
4
Commits
f46d493ca2
...
a6c4302c00
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6c4302c00 | ||
|
|
f926ff733c | ||
|
|
aefe76478a | ||
|
|
3a990fc686 |
@@ -0,0 +1,256 @@
|
|||||||
|
# Uptime Kuma API Documentation
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Uptime Kuma provides a Socket.IO-based API for programmatic monitor management. The REST API does **not** support monitor CRUD operations - you must use the Socket.IO API via the `uptime-kuma-api` Python package.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
### 1. Install Python Package
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install uptime-kuma-api
|
||||||
|
```
|
||||||
|
|
||||||
|
**Requirements:** Python 3.7+
|
||||||
|
|
||||||
|
### 2. Create API Credentials
|
||||||
|
|
||||||
|
#### Option A: API Key (Recommended)
|
||||||
|
|
||||||
|
1. Access Uptime Kuma web UI: https://uptime.kolpacksoftware.com
|
||||||
|
2. Navigate to **Settings → API Keys**
|
||||||
|
3. Click **Generate** to create a new API key
|
||||||
|
4. Set a descriptive name (e.g., "CLI Management")
|
||||||
|
5. Set expiry (or "Never expire")
|
||||||
|
6. **Copy the key immediately** (shown only once)
|
||||||
|
7. Store securely in environment variable:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_API_KEY="uk1_your_api_key_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Important:** Once the first API key is created, basic authentication is permanently disabled for supported endpoints.
|
||||||
|
|
||||||
|
#### Option B: Username/Password
|
||||||
|
|
||||||
|
Use existing Uptime Kuma login credentials:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_USERNAME="your_username"
|
||||||
|
export UPTIME_KUMA_PASSWORD="your_password"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Make Script Executable
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x /home/poprhythm/docker-infrastructure/uptime-kuma/manage_monitors.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### List All Monitors
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py list
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
```
|
||||||
|
ID Name Type URL
|
||||||
|
------------------------------------------------------------------------------------------------
|
||||||
|
1 Example Service http https://example.com
|
||||||
|
2 Database Health tcp 192.168.1.100:5432
|
||||||
|
3 Gateway Ping ping 192.168.1.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add a Monitor
|
||||||
|
|
||||||
|
**HTTP/HTTPS Monitor:**
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py add --name "My Service" --url "https://myservice.com" --type http
|
||||||
|
```
|
||||||
|
|
||||||
|
**TCP Port Monitor:**
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py add --name "PostgreSQL" --url "192.168.1.100:5432" --type tcp
|
||||||
|
```
|
||||||
|
|
||||||
|
**Ping Monitor:**
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py add --name "Router" --url "192.168.1.1" --type ping
|
||||||
|
```
|
||||||
|
|
||||||
|
**Custom Interval (default is 60 seconds):**
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py add --name "Critical Service" --url "https://critical.com" --interval 30
|
||||||
|
```
|
||||||
|
|
||||||
|
### Update a Monitor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Update name
|
||||||
|
./manage_monitors.py update --id 123 --name "New Name"
|
||||||
|
|
||||||
|
# Update URL
|
||||||
|
./manage_monitors.py update --id 123 --url "https://newurl.com"
|
||||||
|
|
||||||
|
# Update interval
|
||||||
|
./manage_monitors.py update --id 123 --interval 300
|
||||||
|
|
||||||
|
# Update multiple fields
|
||||||
|
./manage_monitors.py update --id 123 --name "Updated" --url "https://updated.com" --interval 120
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete a Monitor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py delete --id 123
|
||||||
|
```
|
||||||
|
|
||||||
|
## Monitor Types
|
||||||
|
|
||||||
|
| Type | Description | URL Format |
|
||||||
|
|------|-------------|------------|
|
||||||
|
| `http` | HTTP/HTTPS endpoint | `https://example.com` or `http://example.com` |
|
||||||
|
| `tcp` | TCP port check | `hostname:port` or `ip:port` |
|
||||||
|
| `ping` | ICMP ping | `hostname` or `ip` |
|
||||||
|
| `dns` | DNS resolution | `example.com` |
|
||||||
|
| `docker` | Docker container | Container name or ID |
|
||||||
|
|
||||||
|
## Authentication
|
||||||
|
|
||||||
|
The script checks for credentials in the following order:
|
||||||
|
|
||||||
|
1. `UPTIME_KUMA_API_KEY` environment variable (preferred)
|
||||||
|
2. `UPTIME_KUMA_USERNAME` and `UPTIME_KUMA_PASSWORD` environment variables
|
||||||
|
|
||||||
|
To persist credentials, add to your shell profile (`~/.bashrc` or `~/.zshrc`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_API_KEY="uk1_your_api_key_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### "No credentials provided" Error
|
||||||
|
|
||||||
|
**Problem:** Script cannot find API credentials.
|
||||||
|
|
||||||
|
**Solution:** Set environment variables before running:
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_API_KEY="uk1_your_key"
|
||||||
|
./manage_monitors.py list
|
||||||
|
```
|
||||||
|
|
||||||
|
### Connection Refused
|
||||||
|
|
||||||
|
**Problem:** Cannot connect to Uptime Kuma instance.
|
||||||
|
|
||||||
|
**Solution:**
|
||||||
|
1. Verify service is running: `docker ps | grep uptime-kuma`
|
||||||
|
2. Check URL in script matches web UI access
|
||||||
|
3. Ensure SSL certificate is valid (or use `verify=False` in script for self-signed)
|
||||||
|
|
||||||
|
### "Monitor not found" Error
|
||||||
|
|
||||||
|
**Problem:** Monitor ID doesn't exist.
|
||||||
|
|
||||||
|
**Solution:** Run `./manage_monitors.py list` to see all valid monitor IDs.
|
||||||
|
|
||||||
|
### Import Error: uptime_kuma_api
|
||||||
|
|
||||||
|
**Problem:** Python package not installed.
|
||||||
|
|
||||||
|
**Solution:**
|
||||||
|
```bash
|
||||||
|
pip3 install uptime-kuma-api
|
||||||
|
# Or with sudo if needed:
|
||||||
|
sudo pip3 install uptime-kuma-api
|
||||||
|
```
|
||||||
|
|
||||||
|
## Advanced Usage
|
||||||
|
|
||||||
|
### Using as a Python Module
|
||||||
|
|
||||||
|
```python
|
||||||
|
from uptime_kuma_api import UptimeKumaApi, MonitorType
|
||||||
|
|
||||||
|
# Connect
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com")
|
||||||
|
api.login_by_token("uk1_your_api_key")
|
||||||
|
|
||||||
|
# Get all monitors
|
||||||
|
monitors = api.get_monitors()
|
||||||
|
|
||||||
|
# Add monitor
|
||||||
|
api.add_monitor(
|
||||||
|
type=MonitorType.HTTP,
|
||||||
|
name="My Service",
|
||||||
|
url="https://example.com",
|
||||||
|
interval=60
|
||||||
|
)
|
||||||
|
|
||||||
|
# Edit monitor
|
||||||
|
monitor = api.get_monitor(1)
|
||||||
|
monitor['name'] = "Updated Name"
|
||||||
|
api.edit_monitor(1, **monitor)
|
||||||
|
|
||||||
|
# Delete monitor
|
||||||
|
api.delete_monitor(1)
|
||||||
|
|
||||||
|
# Always disconnect
|
||||||
|
api.disconnect()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tag Management
|
||||||
|
|
||||||
|
Tags help organize monitors by category. See [TAG_MANAGEMENT.md](TAG_MANAGEMENT.md) for comprehensive tag documentation.
|
||||||
|
|
||||||
|
### Quick Tag Commands
|
||||||
|
|
||||||
|
**Tag a new monitor:**
|
||||||
|
```bash
|
||||||
|
# After creating a monitor, tag it quickly
|
||||||
|
./tag_monitor.sh MONITOR_ID TAG_ID [TAG_ID...]
|
||||||
|
|
||||||
|
# Example: Tag monitor 15 as application + web
|
||||||
|
./tag_monitor.sh 15 3 4
|
||||||
|
```
|
||||||
|
|
||||||
|
**View all tags:**
|
||||||
|
```bash
|
||||||
|
./check_tags.py
|
||||||
|
```
|
||||||
|
|
||||||
|
**Common Tag IDs:**
|
||||||
|
- 1=hardware, 2=monitoring, 3=application, 4=web, 5=database
|
||||||
|
- 6=media, 7=infrastructure, 8=storage, 9=virtualization, 10=vm
|
||||||
|
|
||||||
|
**Full workflow for adding a tagged monitor:**
|
||||||
|
```bash
|
||||||
|
# 1. Add monitor and note the ID
|
||||||
|
./manage_monitors.py add --name "New Service" --url "https://example.com"
|
||||||
|
./manage_monitors.py list | grep "New Service"
|
||||||
|
|
||||||
|
# 2. Tag it
|
||||||
|
./tag_monitor.sh 16 3 4 # application + web
|
||||||
|
|
||||||
|
# 3. Verify
|
||||||
|
./check_tags.py | grep "New Service"
|
||||||
|
```
|
||||||
|
|
||||||
|
For detailed tagging strategies and workflows, see **[TAG_MANAGEMENT.md](TAG_MANAGEMENT.md)**.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Uptime Kuma API Keys Documentation](https://github.com/louislam/uptime-kuma/wiki/API-Keys)
|
||||||
|
- [Uptime Kuma API Documentation](https://github.com/louislam/uptime-kuma/wiki/API-Documentation)
|
||||||
|
- [uptime-kuma-api Python Package](https://github.com/lucasheld/uptime-kuma-api)
|
||||||
|
- [uptime-kuma-api Documentation](https://uptime-kuma-api.readthedocs.io/)
|
||||||
|
|
||||||
|
## Web UI Access
|
||||||
|
|
||||||
|
- **URL:** https://uptime.kolpacksoftware.com
|
||||||
|
- **Settings:** Click gear icon → API Keys
|
||||||
|
- **Monitor Management:** Dashboard → Add/Edit monitors via UI
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
# Uptime Kuma Management
|
||||||
|
|
||||||
|
Complete documentation for managing Uptime Kuma monitors and tags via CLI and API.
|
||||||
|
|
||||||
|
## Quick Reference
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
```bash
|
||||||
|
# Set credentials (add to ~/.bashrc for persistence)
|
||||||
|
export UPTIME_KUMA_USERNAME="poprhythm"
|
||||||
|
export UPTIME_KUMA_PASSWORD="your_password"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# List all monitors
|
||||||
|
./manage_monitors.py list
|
||||||
|
|
||||||
|
# Add a monitor
|
||||||
|
./manage_monitors.py add --name "Service" --url "https://example.com"
|
||||||
|
|
||||||
|
# Update a monitor
|
||||||
|
./manage_monitors.py update --id 123 --interval 120
|
||||||
|
|
||||||
|
# Delete a monitor
|
||||||
|
./manage_monitors.py delete --id 123
|
||||||
|
|
||||||
|
# Tag a monitor
|
||||||
|
./tag_monitor.sh 123 3 4 # Tag as application + web
|
||||||
|
|
||||||
|
# View all tags
|
||||||
|
./check_tags.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation Files
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|------|---------|
|
||||||
|
| **[SETUP.md](SETUP.md)** | Initial setup and installation |
|
||||||
|
| **[API.md](API.md)** | Complete API usage and examples |
|
||||||
|
| **[TAG_MANAGEMENT.md](TAG_MANAGEMENT.md)** | Comprehensive tag management guide |
|
||||||
|
| **[TAG_SUMMARY.md](TAG_SUMMARY.md)** | Current tag schema and assignments |
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
| Script | Purpose |
|
||||||
|
|--------|---------|
|
||||||
|
| `manage_monitors.py` | Main CLI for monitor CRUD operations |
|
||||||
|
| `tag_monitor.sh` | Quick script to tag monitors |
|
||||||
|
| `check_tags.py` | View current tag assignments |
|
||||||
|
| `add_tags.py` | Bulk tag assignment (requires editing) |
|
||||||
|
| `fix_missing_tags.py` | Add specific tags to specific monitors |
|
||||||
|
|
||||||
|
## Complete Workflow: Adding a New Monitor
|
||||||
|
|
||||||
|
### Step 1: Add the Monitor
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py add \
|
||||||
|
--name "New Service" \
|
||||||
|
--url "https://newservice.com" \
|
||||||
|
--type http \
|
||||||
|
--interval 60
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: Get Monitor ID
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py list | grep "New Service"
|
||||||
|
# Output: 16 New Service http https://newservice.com
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 3: Tag the Monitor
|
||||||
|
```bash
|
||||||
|
# Choose appropriate tags based on service type:
|
||||||
|
# - Web service: 3 (application) + 4 (web)
|
||||||
|
# - Database: 3 (application) + 5 (database)
|
||||||
|
# - Storage: 7 (infrastructure) + 8 (storage)
|
||||||
|
# - VM: 7 (infrastructure) + 10 (vm)
|
||||||
|
|
||||||
|
./tag_monitor.sh 16 3 4
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 4: Verify
|
||||||
|
```bash
|
||||||
|
./check_tags.py | grep "New Service"
|
||||||
|
# Should show the monitor with its tags
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tag Reference
|
||||||
|
|
||||||
|
| ID | Tag | Use For |
|
||||||
|
|----|-----|---------|
|
||||||
|
| 1 | hardware | Physical hardware monitoring |
|
||||||
|
| 2 | monitoring | Monitoring systems |
|
||||||
|
| 3 | application | Software applications |
|
||||||
|
| 4 | web | Web services |
|
||||||
|
| 5 | database | Database systems |
|
||||||
|
| 6 | media | Media servers |
|
||||||
|
| 7 | infrastructure | Core infrastructure |
|
||||||
|
| 8 | storage | Storage systems |
|
||||||
|
| 9 | virtualization | Virtualization platforms |
|
||||||
|
| 10 | vm | Virtual machines |
|
||||||
|
|
||||||
|
## Monitor Types
|
||||||
|
|
||||||
|
| Type | Example URL | Use For |
|
||||||
|
|------|-------------|---------|
|
||||||
|
| `http` | `https://example.com` | HTTP/HTTPS endpoints |
|
||||||
|
| `tcp` | `hostname:port` | TCP port checks |
|
||||||
|
| `ping` | `192.168.1.1` | ICMP ping |
|
||||||
|
| `dns` | `example.com` | DNS resolution |
|
||||||
|
| `docker` | Container name | Docker container health |
|
||||||
|
|
||||||
|
## Common Tagging Patterns
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Web application
|
||||||
|
./manage_monitors.py add --name "GitLab" --url "https://gitlab.example.com"
|
||||||
|
./tag_monitor.sh NEW_ID 3 4 # application + web
|
||||||
|
|
||||||
|
# Database
|
||||||
|
./manage_monitors.py add --name "PostgreSQL" --url "db.example.com:5432" --type tcp
|
||||||
|
./tag_monitor.sh NEW_ID 3 5 # application + database
|
||||||
|
|
||||||
|
# Storage/NAS
|
||||||
|
./manage_monitors.py add --name "Storage" --url "nas.example.com" --type ping
|
||||||
|
./tag_monitor.sh NEW_ID 7 8 # infrastructure + storage
|
||||||
|
|
||||||
|
# Virtual Machine
|
||||||
|
./manage_monitors.py add --name "VM Host" --url "vm.example.com" --type ping
|
||||||
|
./tag_monitor.sh NEW_ID 7 10 # infrastructure + vm
|
||||||
|
|
||||||
|
# Hardware monitoring
|
||||||
|
./manage_monitors.py add --name "Server Fan" --url "..." --type mqtt
|
||||||
|
./tag_monitor.sh NEW_ID 1 2 # hardware + monitoring
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Authentication Issues
|
||||||
|
```bash
|
||||||
|
# Check credentials are set
|
||||||
|
echo $UPTIME_KUMA_USERNAME
|
||||||
|
echo $UPTIME_KUMA_PASSWORD
|
||||||
|
|
||||||
|
# If not set, export them
|
||||||
|
export UPTIME_KUMA_USERNAME="poprhythm"
|
||||||
|
export UPTIME_KUMA_PASSWORD="your_password"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Monitor Not Found
|
||||||
|
```bash
|
||||||
|
# List all monitors to verify ID
|
||||||
|
./manage_monitors.py list
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tag Already Exists
|
||||||
|
This is normal if you try to add a tag that's already assigned. It can be ignored.
|
||||||
|
|
||||||
|
### SSL Certificate Warnings
|
||||||
|
These warnings are expected for self-signed certificates and can be ignored. The scripts use `ssl_verify=False` to handle this.
|
||||||
|
|
||||||
|
## Web UI
|
||||||
|
|
||||||
|
Access the web interface at: **https://uptime.kolpacksoftware.com**
|
||||||
|
|
||||||
|
- Filter by tags
|
||||||
|
- View status pages
|
||||||
|
- Manage notifications
|
||||||
|
- Configure settings
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Always tag new monitors** immediately after creation
|
||||||
|
2. **Use 2-3 tags** per monitor for better organization
|
||||||
|
3. **Document custom tags** if you add new tag types
|
||||||
|
4. **Run audits** periodically with `check_tags.py`
|
||||||
|
5. **Set credentials** persistently in your shell profile
|
||||||
|
6. **Use descriptive names** for monitors (include service purpose)
|
||||||
|
7. **Group related services** using consistent tagging
|
||||||
|
|
||||||
|
## Getting Help
|
||||||
|
|
||||||
|
- **Setup issues**: See [SETUP.md](SETUP.md)
|
||||||
|
- **API questions**: See [API.md](API.md)
|
||||||
|
- **Tag management**: See [TAG_MANAGEMENT.md](TAG_MANAGEMENT.md)
|
||||||
|
- **Current tags**: See [TAG_SUMMARY.md](TAG_SUMMARY.md)
|
||||||
|
- **Uptime Kuma docs**: https://github.com/louislam/uptime-kuma/wiki
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
### Regular Tasks
|
||||||
|
|
||||||
|
**Weekly:**
|
||||||
|
- Review untagged monitors: `./check_tags.py | grep "No tags"`
|
||||||
|
- Verify critical monitors are up
|
||||||
|
|
||||||
|
**Monthly:**
|
||||||
|
- Review and update monitor intervals
|
||||||
|
- Clean up old/unused monitors
|
||||||
|
- Verify tag schema still makes sense
|
||||||
|
|
||||||
|
**As Needed:**
|
||||||
|
- Update documentation when adding new tag types
|
||||||
|
- Adjust check intervals based on service criticality
|
||||||
|
- Review and optimize notification rules
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
# Uptime Kuma API Setup Guide
|
||||||
|
|
||||||
|
## Prerequisites Installation
|
||||||
|
|
||||||
|
The management script requires Python 3.7+ and the `uptime-kuma-api` package.
|
||||||
|
|
||||||
|
### Step 1: Install pip (if not already installed)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install python3-pip -y
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: Install uptime-kuma-api Package
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install uptime-kuma-api
|
||||||
|
# Or if pip3 is not in PATH:
|
||||||
|
python3 -m pip install uptime-kuma-api
|
||||||
|
```
|
||||||
|
|
||||||
|
**Verify installation:**
|
||||||
|
```bash
|
||||||
|
python3 -c "import uptime_kuma_api; print('Package installed successfully')"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Authentication Setup
|
||||||
|
|
||||||
|
You must configure API credentials before using the management script.
|
||||||
|
|
||||||
|
### Option A: API Key (Recommended)
|
||||||
|
|
||||||
|
1. **Access Uptime Kuma web UI:**
|
||||||
|
- URL: https://uptime.kolpacksoftware.com
|
||||||
|
- Log in with your credentials
|
||||||
|
|
||||||
|
2. **Generate API Key:**
|
||||||
|
- Click the gear icon (Settings)
|
||||||
|
- Navigate to **API Keys** section
|
||||||
|
- Click **Generate**
|
||||||
|
- Set a descriptive name (e.g., "CLI Management")
|
||||||
|
- Set expiry (or "Never expire")
|
||||||
|
- **IMPORTANT:** Copy the key immediately - it's only shown once!
|
||||||
|
|
||||||
|
3. **Configure Environment Variable:**
|
||||||
|
|
||||||
|
Add to `~/.bashrc` or `~/.zshrc`:
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_API_KEY="uk1_your_api_key_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
Or set temporarily:
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_API_KEY="uk1_your_api_key_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
Apply changes:
|
||||||
|
```bash
|
||||||
|
source ~/.bashrc # or source ~/.zshrc
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option B: Username/Password
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_USERNAME="your_username"
|
||||||
|
export UPTIME_KUMA_PASSWORD="your_password"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** Once you create the first API key, username/password authentication is permanently disabled for API endpoints. API keys are more secure and recommended.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
### Test 1: Check Script is Executable
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/poprhythm/docker-infrastructure
|
||||||
|
ls -l uptime-kuma/manage_monitors.py
|
||||||
|
# Should show -rwxr-xr-x (executable permissions)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test 2: List Existing Monitors
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/poprhythm/docker-infrastructure
|
||||||
|
./uptime-kuma/manage_monitors.py list
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected output:**
|
||||||
|
```
|
||||||
|
ID Name Type URL
|
||||||
|
------------------------------------------------------------------------------------------------
|
||||||
|
1 Example Service http https://example.com
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test 3: Add a Test Monitor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./uptime-kuma/manage_monitors.py add --name "Test Monitor" --url "https://httpbin.org/status/200" --type http --interval 300
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test 4: Delete the Test Monitor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Find the ID from the list command
|
||||||
|
./uptime-kuma/manage_monitors.py list
|
||||||
|
|
||||||
|
# Delete it (replace 999 with actual ID)
|
||||||
|
./uptime-kuma/manage_monitors.py delete --id 999
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test 5: Verify in Web UI
|
||||||
|
|
||||||
|
1. Access https://uptime.kolpacksoftware.com
|
||||||
|
2. Check that the test monitor was created and deleted
|
||||||
|
3. Verify existing monitors match the CLI list output
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### "No credentials provided" Error
|
||||||
|
|
||||||
|
**Cause:** Environment variables not set.
|
||||||
|
|
||||||
|
**Fix:**
|
||||||
|
```bash
|
||||||
|
# Check current environment
|
||||||
|
echo $UPTIME_KUMA_API_KEY
|
||||||
|
|
||||||
|
# If empty, set it:
|
||||||
|
export UPTIME_KUMA_API_KEY="uk1_your_key"
|
||||||
|
```
|
||||||
|
|
||||||
|
### "ModuleNotFoundError: No module named 'uptime_kuma_api'"
|
||||||
|
|
||||||
|
**Cause:** Package not installed or installed for wrong Python version.
|
||||||
|
|
||||||
|
**Fix:**
|
||||||
|
```bash
|
||||||
|
# Install for your Python 3
|
||||||
|
python3 -m pip install --user uptime-kuma-api
|
||||||
|
|
||||||
|
# Or system-wide (requires sudo)
|
||||||
|
sudo python3 -m pip install uptime-kuma-api
|
||||||
|
```
|
||||||
|
|
||||||
|
### Connection Errors
|
||||||
|
|
||||||
|
**Cause:** Uptime Kuma service not running or URL incorrect.
|
||||||
|
|
||||||
|
**Fix:**
|
||||||
|
```bash
|
||||||
|
# Check service is running
|
||||||
|
docker ps | grep uptime-kuma
|
||||||
|
|
||||||
|
# Test web UI access
|
||||||
|
curl -k https://uptime.kolpacksoftware.com
|
||||||
|
|
||||||
|
# If needed, start the service
|
||||||
|
cd /home/poprhythm/docker-infrastructure/uptime-kuma
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### SSL Certificate Errors
|
||||||
|
|
||||||
|
**Cause:** Self-signed certificate or certificate validation issues.
|
||||||
|
|
||||||
|
**Fix:** If using self-signed certificates, you may need to modify the script to disable SSL verification (not recommended for production).
|
||||||
|
|
||||||
|
## Next Steps
|
||||||
|
|
||||||
|
1. ✅ Install prerequisites (`python3-pip`, `uptime-kuma-api`)
|
||||||
|
2. ✅ Create API key in web UI
|
||||||
|
3. ✅ Set environment variable
|
||||||
|
4. ✅ Test with `./manage_monitors.py list`
|
||||||
|
5. 📖 Read [API.md](API.md) for full usage documentation
|
||||||
|
|
||||||
|
## Quick Reference
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Set credentials (add to ~/.bashrc for persistence)
|
||||||
|
export UPTIME_KUMA_API_KEY="uk1_your_api_key"
|
||||||
|
|
||||||
|
# Common commands
|
||||||
|
cd /home/poprhythm/docker-infrastructure
|
||||||
|
./uptime-kuma/manage_monitors.py list
|
||||||
|
./uptime-kuma/manage_monitors.py add --name "Service" --url "https://example.com"
|
||||||
|
./uptime-kuma/manage_monitors.py update --id 123 --interval 120
|
||||||
|
./uptime-kuma/manage_monitors.py delete --id 123
|
||||||
|
```
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
# Tag Management Guide
|
||||||
|
|
||||||
|
This guide covers managing tags and tag assignments in Uptime Kuma.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Tags help organize and categorize monitors. Each monitor can have multiple tags, and you can filter monitors by tags in the web UI.
|
||||||
|
|
||||||
|
## Current Tag Schema
|
||||||
|
|
||||||
|
### Service Categories
|
||||||
|
|
||||||
|
| Tag Name | Color | Use For |
|
||||||
|
|----------|-------|---------|
|
||||||
|
| `hardware` | 🔴 Red | Physical hardware (fans, sensors) |
|
||||||
|
| `monitoring` | 🟠 Orange | Monitoring systems and health checks |
|
||||||
|
| `application` | 🔵 Blue | Software applications and services |
|
||||||
|
| `web` | 🔷 Cyan | Web services and HTTP endpoints |
|
||||||
|
| `database` | 🟣 Purple | Database systems |
|
||||||
|
| `media` | 🌸 Pink | Media servers (Plex, etc.) |
|
||||||
|
| `infrastructure` | 🟢 Green | Core infrastructure components |
|
||||||
|
| `storage` | 🟢 Light Green | Storage systems (NAS, file servers) |
|
||||||
|
| `virtualization` | 🟦 Teal | Virtualization platforms (Proxmox) |
|
||||||
|
| `vm` | 🔹 Blue Grey | Virtual machines |
|
||||||
|
|
||||||
|
## Common Workflows
|
||||||
|
|
||||||
|
### Adding a New Monitor with Tags
|
||||||
|
|
||||||
|
**Step 1: Add the monitor**
|
||||||
|
```bash
|
||||||
|
export UPTIME_KUMA_USERNAME="your_username"
|
||||||
|
export UPTIME_KUMA_PASSWORD="your_password"
|
||||||
|
|
||||||
|
./manage_monitors.py add --name "New Service" --url "https://newservice.com" --type http
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 2: Note the monitor ID from the output or list**
|
||||||
|
```bash
|
||||||
|
./manage_monitors.py list
|
||||||
|
# Note the ID of your new monitor (e.g., 15)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 3: Add tags using Python API**
|
||||||
|
```python
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com", ssl_verify=False)
|
||||||
|
api.login("username", "password")
|
||||||
|
|
||||||
|
# Add tags to monitor
|
||||||
|
api.add_monitor_tag(tag_id=3, monitor_id=15, value='') # application
|
||||||
|
api.add_monitor_tag(tag_id=4, monitor_id=15, value='') # web
|
||||||
|
|
||||||
|
api.disconnect()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Quick Tag Script
|
||||||
|
|
||||||
|
Create a simple script to tag a new monitor:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
# tag_monitor.sh - Quick script to tag a monitor
|
||||||
|
# Usage: ./tag_monitor.sh MONITOR_ID TAG_ID [TAG_ID...]
|
||||||
|
|
||||||
|
MONITOR_ID=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
python3 << EOF
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
import os
|
||||||
|
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com", ssl_verify=False)
|
||||||
|
api.login(os.getenv('UPTIME_KUMA_USERNAME'), os.getenv('UPTIME_KUMA_PASSWORD'))
|
||||||
|
|
||||||
|
for tag_id in [${@}]:
|
||||||
|
try:
|
||||||
|
api.add_monitor_tag(tag_id=tag_id, monitor_id=${MONITOR_ID}, value='')
|
||||||
|
print(f"✓ Added tag {tag_id} to monitor ${MONITOR_ID}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"✗ Failed: {e}")
|
||||||
|
|
||||||
|
api.disconnect()
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
**Usage:**
|
||||||
|
```bash
|
||||||
|
# Tag monitor 15 as application + web
|
||||||
|
export UPTIME_KUMA_USERNAME="poprhythm"
|
||||||
|
export UPTIME_KUMA_PASSWORD="your_password"
|
||||||
|
./tag_monitor.sh 15 3 4
|
||||||
|
```
|
||||||
|
|
||||||
|
### Viewing Tags on a Monitor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./check_tags.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Or check a specific monitor:
|
||||||
|
```python
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com", ssl_verify=False)
|
||||||
|
api.login("username", "password")
|
||||||
|
|
||||||
|
monitor = api.get_monitor(15)
|
||||||
|
print(f"Tags: {monitor.get('tags', [])}")
|
||||||
|
|
||||||
|
api.disconnect()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Removing a Tag from a Monitor
|
||||||
|
|
||||||
|
```python
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com", ssl_verify=False)
|
||||||
|
api.login("username", "password")
|
||||||
|
|
||||||
|
# Remove tag_id 3 from monitor 15
|
||||||
|
api.delete_monitor_tag(tag_id=3, monitor_id=15, value='')
|
||||||
|
|
||||||
|
api.disconnect()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding New Tag Types
|
||||||
|
|
||||||
|
If you need to create a new tag:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com", ssl_verify=False)
|
||||||
|
api.login("username", "password")
|
||||||
|
|
||||||
|
# Create a new tag
|
||||||
|
result = api.add_tag(name="production", color="#FF5722")
|
||||||
|
print(f"Created tag with ID: {result['id']}")
|
||||||
|
|
||||||
|
api.disconnect()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tag Assignment Patterns
|
||||||
|
|
||||||
|
### By Service Type
|
||||||
|
- **Web Services**: `application` + `web`
|
||||||
|
- **Databases**: `application` + `database`
|
||||||
|
- **Media Servers**: `application` + `media`
|
||||||
|
- **Storage Systems**: `infrastructure` + `storage`
|
||||||
|
- **Virtual Machines**: `infrastructure` + `vm`
|
||||||
|
- **Hardware Monitoring**: `hardware` + `monitoring`
|
||||||
|
- **Virtualization Platforms**: `infrastructure` + `virtualization`
|
||||||
|
|
||||||
|
### By Environment (if needed)
|
||||||
|
You can create additional tags for environments:
|
||||||
|
```python
|
||||||
|
api.add_tag(name="production", color="#4CAF50")
|
||||||
|
api.add_tag(name="staging", color="#FFC107")
|
||||||
|
api.add_tag(name="development", color="#2196F3")
|
||||||
|
```
|
||||||
|
|
||||||
|
### By Priority (if needed)
|
||||||
|
```python
|
||||||
|
api.add_tag(name="critical", color="#F44336")
|
||||||
|
api.add_tag(name="high", color="#FF9800")
|
||||||
|
api.add_tag(name="normal", color="#4CAF50")
|
||||||
|
api.add_tag(name="low", color="#9E9E9E")
|
||||||
|
```
|
||||||
|
|
||||||
|
## Complete Example: Adding a New Service
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Add the monitor
|
||||||
|
./manage_monitors.py add \
|
||||||
|
--name "GitLab" \
|
||||||
|
--url "https://gitlab.example.com" \
|
||||||
|
--type http \
|
||||||
|
--interval 60
|
||||||
|
|
||||||
|
# 2. List to get the ID
|
||||||
|
./manage_monitors.py list | grep GitLab
|
||||||
|
# Output: 16 GitLab http https://gitlab.example.com
|
||||||
|
|
||||||
|
# 3. Tag it (using Python one-liner)
|
||||||
|
python3 -c "
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
import os
|
||||||
|
api = UptimeKumaApi('https://uptime.kolpacksoftware.com', ssl_verify=False)
|
||||||
|
api.login(os.getenv('UPTIME_KUMA_USERNAME'), os.getenv('UPTIME_KUMA_PASSWORD'))
|
||||||
|
api.add_monitor_tag(tag_id=3, monitor_id=16, value='') # application
|
||||||
|
api.add_monitor_tag(tag_id=4, monitor_id=16, value='') # web
|
||||||
|
api.disconnect()
|
||||||
|
print('Tagged successfully!')
|
||||||
|
"
|
||||||
|
|
||||||
|
# 4. Verify
|
||||||
|
./check_tags.py | grep GitLab
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tag Reference Quick Lookup
|
||||||
|
|
||||||
|
| Tag ID | Tag Name | Common Use |
|
||||||
|
|--------|----------|------------|
|
||||||
|
| 1 | hardware | Server fans, sensors |
|
||||||
|
| 2 | monitoring | Health checks |
|
||||||
|
| 3 | application | Any software service |
|
||||||
|
| 4 | web | HTTP/HTTPS services |
|
||||||
|
| 5 | database | PostgreSQL, MySQL, CouchDB, etc. |
|
||||||
|
| 6 | media | Plex, Jellyfin, etc. |
|
||||||
|
| 7 | infrastructure | Core systems |
|
||||||
|
| 8 | storage | NAS, file servers |
|
||||||
|
| 9 | virtualization | Proxmox, ESXi |
|
||||||
|
| 10 | vm | Virtual machine instances |
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Consistent Naming**: Use lowercase for tag names
|
||||||
|
2. **Multiple Tags**: Apply 2-3 relevant tags per monitor for better organization
|
||||||
|
3. **Color Coding**: Use similar colors for related tags (all infrastructure tags are shades of green)
|
||||||
|
4. **Document Custom Tags**: If you add custom tags, document them in this file
|
||||||
|
5. **Tag on Creation**: Always tag new monitors immediately after creation
|
||||||
|
6. **Regular Audits**: Run `check_tags.py` periodically to find untagged monitors
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### "Tag already exists" Error
|
||||||
|
This means the tag is already assigned to the monitor. You can safely ignore this.
|
||||||
|
|
||||||
|
### "Monitor not found"
|
||||||
|
Double-check the monitor ID with `./manage_monitors.py list`.
|
||||||
|
|
||||||
|
### Session Timeout
|
||||||
|
If you're tagging many monitors, you may need to reconnect. The API session can timeout after several minutes of inactivity.
|
||||||
|
|
||||||
|
### View All Tags
|
||||||
|
```python
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com", ssl_verify=False)
|
||||||
|
api.login("username", "password")
|
||||||
|
tags = api.get_tags()
|
||||||
|
for tag in tags:
|
||||||
|
print(f"ID {tag['id']}: {tag['name']} ({tag['color']})")
|
||||||
|
api.disconnect()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Scripts Available
|
||||||
|
|
||||||
|
- `check_tags.py` - View all monitor tag assignments
|
||||||
|
- `add_tags.py` - Bulk tag assignment (requires editing for new monitors)
|
||||||
|
- `fix_missing_tags.py` - Add specific tags to specific monitors
|
||||||
|
- `TAG_SUMMARY.md` - Current tag schema documentation
|
||||||
|
|
||||||
|
## Web UI Management
|
||||||
|
|
||||||
|
For one-off changes, the web UI is often easier:
|
||||||
|
1. Go to https://uptime.kolpacksoftware.com
|
||||||
|
2. Click on a monitor to edit it
|
||||||
|
3. Scroll to the "Tags" section
|
||||||
|
4. Add/remove tags as needed
|
||||||
|
5. Click "Save"
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
# Uptime Kuma Monitor Tags Summary
|
||||||
|
|
||||||
|
## All Tags Created
|
||||||
|
|
||||||
|
| Tag ID | Tag Name | Color | Category |
|
||||||
|
|--------|----------|-------|----------|
|
||||||
|
| 1 | hardware | 🔴 Red | Physical hardware monitoring |
|
||||||
|
| 2 | monitoring | 🟠 Orange | Monitoring systems |
|
||||||
|
| 3 | application | 🔵 Blue | Software applications |
|
||||||
|
| 4 | web | 🔷 Cyan | Web services |
|
||||||
|
| 5 | database | 🟣 Purple | Database systems |
|
||||||
|
| 6 | media | 🌸 Pink | Media servers |
|
||||||
|
| 7 | infrastructure | 🟢 Green | Core infrastructure |
|
||||||
|
| 8 | storage | 🟢 Light Green | Storage systems |
|
||||||
|
| 9 | virtualization | 🟦 Teal | Virtualization platforms |
|
||||||
|
| 10 | vm | 🔹 Blue Grey | Virtual machines |
|
||||||
|
|
||||||
|
## Monitor Tag Assignments
|
||||||
|
|
||||||
|
### Hardware/Monitoring (4 monitors)
|
||||||
|
| ID | Monitor Name | Tags |
|
||||||
|
|----|--------------|------|
|
||||||
|
| 1 | Server Fan Online | `hardware` `monitoring` |
|
||||||
|
| 2 | Server Front Fan Stalled | `hardware` `monitoring` |
|
||||||
|
| 3 | Server Back Fan Stalled | `hardware` `monitoring` |
|
||||||
|
| 4 | Server Fan | `hardware` `monitoring` |
|
||||||
|
|
||||||
|
### Applications (3 monitors)
|
||||||
|
| ID | Monitor Name | Tags |
|
||||||
|
|----|--------------|------|
|
||||||
|
| 5 | TSA Chapter Organizer RMS | `application` `web` |
|
||||||
|
| 6 | couchdb | `application` `database` |
|
||||||
|
| 7 | Plex | `application` `media` |
|
||||||
|
|
||||||
|
### Infrastructure (5 monitors)
|
||||||
|
| ID | Monitor Name | Tags |
|
||||||
|
|----|--------------|------|
|
||||||
|
| 8 | unraid | `infrastructure` `storage` |
|
||||||
|
| 10 | pallas VM | `infrastructure` `vm` |
|
||||||
|
| 11 | NAS | `infrastructure` `storage` |
|
||||||
|
| 13 | Proxmox | `infrastructure` `virtualization` |
|
||||||
|
| 14 | dev-win10 VM | `infrastructure` `vm` |
|
||||||
|
|
||||||
|
## Using Tags in Uptime Kuma
|
||||||
|
|
||||||
|
1. **Filter by Tag**: In the web UI, click on a tag to filter monitors
|
||||||
|
2. **View All Tags**: Navigate to Settings → Tags to manage
|
||||||
|
3. **Add/Edit Tags**: Click on a monitor → Edit → Tags section
|
||||||
|
4. **Status Pages**: Create status pages filtered by specific tags
|
||||||
|
|
||||||
|
## Scripts Available
|
||||||
|
|
||||||
|
- `add_tags.py` - Create tags and assign them to monitors
|
||||||
|
- `check_tags.py` - Verify current tag assignments
|
||||||
|
- `fix_missing_tags.py` - Add missing tags to specific monitors
|
||||||
|
|
||||||
|
## Web UI
|
||||||
|
|
||||||
|
Access Uptime Kuma at: https://uptime.kolpacksoftware.com
|
||||||
|
|
||||||
|
All tags are now visible and active in the web interface!
|
||||||
Executable
+128
@@ -0,0 +1,128 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Add service category tags to Uptime Kuma monitors
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
UPTIME_KUMA_URL = "https://uptime.kolpacksoftware.com"
|
||||||
|
USERNAME = os.getenv('UPTIME_KUMA_USERNAME')
|
||||||
|
PASSWORD = os.getenv('UPTIME_KUMA_PASSWORD')
|
||||||
|
|
||||||
|
# Service category mappings
|
||||||
|
MONITOR_TAGS = {
|
||||||
|
# Hardware/Monitoring
|
||||||
|
1: ['hardware', 'monitoring'], # Server Fan Online
|
||||||
|
2: ['hardware', 'monitoring'], # Server Front Fan Stalled
|
||||||
|
3: ['hardware', 'monitoring'], # Server Back Fan Stalled
|
||||||
|
4: ['hardware', 'monitoring'], # Server Fan (group)
|
||||||
|
|
||||||
|
# Applications
|
||||||
|
5: ['application', 'web'], # TSA Chapter Organizer RMS
|
||||||
|
6: ['database', 'application'], # couchdb
|
||||||
|
7: ['media', 'application'], # Plex
|
||||||
|
|
||||||
|
# Infrastructure
|
||||||
|
8: ['infrastructure', 'storage'], # unraid
|
||||||
|
13: ['infrastructure', 'virtualization'], # Proxmox
|
||||||
|
|
||||||
|
# Network/Hosts
|
||||||
|
10: ['infrastructure', 'vm'], # pallas VM
|
||||||
|
11: ['infrastructure', 'storage'], # NAS
|
||||||
|
14: ['infrastructure', 'vm'], # dev-win10 VM
|
||||||
|
}
|
||||||
|
|
||||||
|
def connect():
|
||||||
|
"""Connect to Uptime Kuma API"""
|
||||||
|
api = UptimeKumaApi(UPTIME_KUMA_URL, ssl_verify=False)
|
||||||
|
|
||||||
|
if USERNAME and PASSWORD:
|
||||||
|
api.login(USERNAME, PASSWORD)
|
||||||
|
else:
|
||||||
|
print("Error: Set UPTIME_KUMA_USERNAME and UPTIME_KUMA_PASSWORD")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
return api
|
||||||
|
|
||||||
|
def ensure_tags_exist(api):
|
||||||
|
"""Create all needed tags upfront"""
|
||||||
|
tag_colors = {
|
||||||
|
'hardware': '#F44336', # Red
|
||||||
|
'monitoring': '#FF9800', # Orange
|
||||||
|
'application': '#2196F3', # Blue
|
||||||
|
'web': '#00BCD4', # Cyan
|
||||||
|
'database': '#9C27B0', # Purple
|
||||||
|
'media': '#E91E63', # Pink
|
||||||
|
'infrastructure': '#4CAF50', # Green
|
||||||
|
'storage': '#8BC34A', # Light Green
|
||||||
|
'virtualization': '#009688', # Teal
|
||||||
|
'vm': '#607D8B', # Blue Grey
|
||||||
|
}
|
||||||
|
|
||||||
|
existing_tags = api.get_tags()
|
||||||
|
# Tags might have 'id' or 'tag_id'
|
||||||
|
existing_tag_names = {tag['name']: (tag.get('tag_id') or tag.get('id')) for tag in existing_tags}
|
||||||
|
tag_map = {}
|
||||||
|
|
||||||
|
print("Ensuring all tags exist...")
|
||||||
|
for tag_name, color in tag_colors.items():
|
||||||
|
if tag_name in existing_tag_names:
|
||||||
|
tag_map[tag_name] = existing_tag_names[tag_name]
|
||||||
|
print(f" ✓ Tag '{tag_name}' already exists (ID: {tag_map[tag_name]})")
|
||||||
|
else:
|
||||||
|
result = api.add_tag(name=tag_name, color=color)
|
||||||
|
# The result might be the tag dict itself or contain it
|
||||||
|
if isinstance(result, dict):
|
||||||
|
tag_id = result.get('tag_id') or result.get('id')
|
||||||
|
else:
|
||||||
|
tag_id = result
|
||||||
|
tag_map[tag_name] = tag_id
|
||||||
|
print(f" + Created tag '{tag_name}' (ID: {tag_map[tag_name]})")
|
||||||
|
|
||||||
|
return tag_map
|
||||||
|
|
||||||
|
def add_tags_to_monitor(api, monitor_id, tag_names, tag_map):
|
||||||
|
"""Add tags to a monitor using add_monitor_tag method"""
|
||||||
|
# Get monitor details for name
|
||||||
|
monitor = api.get_monitor(monitor_id)
|
||||||
|
|
||||||
|
# Add each tag using the dedicated method
|
||||||
|
for tag_name in tag_names:
|
||||||
|
if tag_name in tag_map:
|
||||||
|
tag_id = tag_map[tag_name]
|
||||||
|
try:
|
||||||
|
api.add_monitor_tag(tag_id=tag_id, monitor_id=monitor_id, value='')
|
||||||
|
except Exception as e:
|
||||||
|
# Tag might already be assigned, that's okay
|
||||||
|
if 'already exists' not in str(e).lower():
|
||||||
|
raise
|
||||||
|
|
||||||
|
print(f" ✓ Monitor {monitor_id} ({monitor['name']}): Added tags {tag_names}")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
api = connect()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# First, ensure all tags exist
|
||||||
|
tag_map = ensure_tags_exist(api)
|
||||||
|
|
||||||
|
print("\nAdding tags to monitors...\n")
|
||||||
|
|
||||||
|
for monitor_id, tags in MONITOR_TAGS.items():
|
||||||
|
try:
|
||||||
|
add_tags_to_monitor(api, monitor_id, tags, tag_map)
|
||||||
|
except Exception as e:
|
||||||
|
print(f" ✗ Failed to tag monitor {monitor_id}: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
print("\n✅ Tag assignment complete!")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
api.disconnect()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Check current tag assignments on monitors
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
UPTIME_KUMA_URL = "https://uptime.kolpacksoftware.com"
|
||||||
|
USERNAME = os.getenv('UPTIME_KUMA_USERNAME')
|
||||||
|
PASSWORD = os.getenv('UPTIME_KUMA_PASSWORD')
|
||||||
|
|
||||||
|
def connect():
|
||||||
|
api = UptimeKumaApi(UPTIME_KUMA_URL, ssl_verify=False)
|
||||||
|
if USERNAME and PASSWORD:
|
||||||
|
api.login(USERNAME, PASSWORD)
|
||||||
|
else:
|
||||||
|
print("Error: Set UPTIME_KUMA_USERNAME and UPTIME_KUMA_PASSWORD")
|
||||||
|
sys.exit(1)
|
||||||
|
return api
|
||||||
|
|
||||||
|
def main():
|
||||||
|
api = connect()
|
||||||
|
|
||||||
|
try:
|
||||||
|
monitors = api.get_monitors()
|
||||||
|
|
||||||
|
print("Current Monitor Tags:\n")
|
||||||
|
for monitor in monitors:
|
||||||
|
tags = monitor.get('tags', [])
|
||||||
|
tag_names = [f"ID:{tag.get('tag_id', tag.get('id'))}" for tag in tags] if tags else ['No tags']
|
||||||
|
print(f"Monitor {monitor['id']} ({monitor['name']}): {', '.join(tag_names)}")
|
||||||
|
|
||||||
|
print("\n\nAvailable Tags:\n")
|
||||||
|
all_tags = api.get_tags()
|
||||||
|
for tag in all_tags:
|
||||||
|
tag_id = tag.get('tag_id') or tag.get('id')
|
||||||
|
print(f" ID {tag_id}: {tag['name']} ({tag.get('color', 'no color')})")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
api.disconnect()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Executable
+55
@@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Fix missing tags on specific monitors"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
UPTIME_KUMA_URL = "https://uptime.kolpacksoftware.com"
|
||||||
|
USERNAME = os.getenv('UPTIME_KUMA_USERNAME')
|
||||||
|
PASSWORD = os.getenv('UPTIME_KUMA_PASSWORD')
|
||||||
|
|
||||||
|
# Missing tags to add
|
||||||
|
MISSING_TAGS = {
|
||||||
|
1: [2], # Server Fan Online: add monitoring
|
||||||
|
2: [2], # Server Front Fan Stalled: add monitoring
|
||||||
|
11: [7, 8], # NAS: add infrastructure, storage
|
||||||
|
14: [7, 10], # dev-win10 VM: add infrastructure, vm
|
||||||
|
}
|
||||||
|
|
||||||
|
def connect():
|
||||||
|
api = UptimeKumaApi(UPTIME_KUMA_URL, ssl_verify=False)
|
||||||
|
if USERNAME and PASSWORD:
|
||||||
|
api.login(USERNAME, PASSWORD)
|
||||||
|
else:
|
||||||
|
print("Error: Set credentials")
|
||||||
|
sys.exit(1)
|
||||||
|
return api
|
||||||
|
|
||||||
|
def main():
|
||||||
|
api = connect()
|
||||||
|
|
||||||
|
try:
|
||||||
|
print("Adding missing tags...\n")
|
||||||
|
|
||||||
|
for monitor_id, tag_ids in MISSING_TAGS.items():
|
||||||
|
monitor = api.get_monitor(monitor_id)
|
||||||
|
print(f"Monitor {monitor_id} ({monitor['name']}):")
|
||||||
|
|
||||||
|
for tag_id in tag_ids:
|
||||||
|
try:
|
||||||
|
api.add_monitor_tag(tag_id=tag_id, monitor_id=monitor_id, value='')
|
||||||
|
print(f" ✓ Added tag ID {tag_id}")
|
||||||
|
except Exception as e:
|
||||||
|
if 'already' in str(e).lower():
|
||||||
|
print(f" - Tag ID {tag_id} already exists")
|
||||||
|
else:
|
||||||
|
print(f" ✗ Failed to add tag ID {tag_id}: {e}")
|
||||||
|
|
||||||
|
print("\n✅ Complete!")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
api.disconnect()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Executable
+156
@@ -0,0 +1,156 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Uptime Kuma Monitor Management Script
|
||||||
|
Usage examples:
|
||||||
|
./manage_monitors.py list
|
||||||
|
./manage_monitors.py add --name "My Service" --url "https://example.com" --type http
|
||||||
|
./manage_monitors.py delete --id 123
|
||||||
|
./manage_monitors.py update --id 123 --name "Updated Name"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from uptime_kuma_api import UptimeKumaApi, MonitorType
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
UPTIME_KUMA_URL = "https://uptime.kolpacksoftware.com"
|
||||||
|
# Set one of these (or use environment variables):
|
||||||
|
API_KEY = os.getenv('UPTIME_KUMA_API_KEY') # Set via UPTIME_KUMA_API_KEY env var
|
||||||
|
USERNAME = os.getenv('UPTIME_KUMA_USERNAME') # Or use UPTIME_KUMA_USERNAME
|
||||||
|
PASSWORD = os.getenv('UPTIME_KUMA_PASSWORD') # And UPTIME_KUMA_PASSWORD
|
||||||
|
|
||||||
|
def connect():
|
||||||
|
"""Connect to Uptime Kuma API"""
|
||||||
|
# Disable SSL verification for self-signed certificates
|
||||||
|
api = UptimeKumaApi(UPTIME_KUMA_URL, ssl_verify=False)
|
||||||
|
|
||||||
|
if API_KEY:
|
||||||
|
# API key authentication (preferred)
|
||||||
|
api.login_by_token(API_KEY)
|
||||||
|
elif USERNAME and PASSWORD:
|
||||||
|
# Username/password authentication
|
||||||
|
api.login(USERNAME, PASSWORD)
|
||||||
|
else:
|
||||||
|
print("Error: No credentials provided. Set UPTIME_KUMA_API_KEY or UPTIME_KUMA_USERNAME/PASSWORD environment variables.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
return api
|
||||||
|
|
||||||
|
def list_monitors(api):
|
||||||
|
"""List all monitors"""
|
||||||
|
monitors = api.get_monitors()
|
||||||
|
if not monitors:
|
||||||
|
print("No monitors found")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"{'ID':<6} {'Name':<30} {'Type':<10} {'URL/Hostname':<50}")
|
||||||
|
print("-" * 96)
|
||||||
|
for monitor in monitors:
|
||||||
|
url = monitor.get('url') or monitor.get('hostname', 'N/A')
|
||||||
|
if url is None:
|
||||||
|
url = 'N/A'
|
||||||
|
print(f"{monitor['id']:<6} {monitor['name']:<30} {str(monitor['type']):<10} {url:<50}")
|
||||||
|
|
||||||
|
def add_monitor(api, name, url, monitor_type='http', interval=60, ignore_tls=False):
|
||||||
|
"""Add a new monitor"""
|
||||||
|
type_map = {
|
||||||
|
'http': MonitorType.HTTP,
|
||||||
|
'https': MonitorType.HTTP,
|
||||||
|
'tcp': MonitorType.PORT,
|
||||||
|
'ping': MonitorType.PING,
|
||||||
|
'dns': MonitorType.DNS,
|
||||||
|
'docker': MonitorType.DOCKER,
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor_type_value = type_map.get(monitor_type.lower(), MonitorType.HTTP)
|
||||||
|
|
||||||
|
# Different monitor types use different parameters
|
||||||
|
if monitor_type.lower() == 'ping':
|
||||||
|
result = api.add_monitor(
|
||||||
|
type=monitor_type_value,
|
||||||
|
name=name,
|
||||||
|
hostname=url,
|
||||||
|
interval=interval
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
kwargs = {
|
||||||
|
'type': monitor_type_value,
|
||||||
|
'name': name,
|
||||||
|
'url': url,
|
||||||
|
'interval': interval
|
||||||
|
}
|
||||||
|
# Add SSL ignore for HTTPS URLs
|
||||||
|
if ignore_tls or (url.startswith('https://') and monitor_type.lower() in ['http', 'https']):
|
||||||
|
kwargs['ignoreTls'] = True
|
||||||
|
result = api.add_monitor(**kwargs)
|
||||||
|
print(f"Monitor added successfully: ID {result['monitorID']}")
|
||||||
|
|
||||||
|
def delete_monitor(api, monitor_id):
|
||||||
|
"""Delete a monitor"""
|
||||||
|
api.delete_monitor(monitor_id)
|
||||||
|
print(f"Monitor {monitor_id} deleted successfully")
|
||||||
|
|
||||||
|
def update_monitor(api, monitor_id, **kwargs):
|
||||||
|
"""Update a monitor"""
|
||||||
|
# Get existing monitor
|
||||||
|
monitor = api.get_monitor(monitor_id)
|
||||||
|
|
||||||
|
# Update fields
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if value is not None:
|
||||||
|
monitor[key] = value
|
||||||
|
|
||||||
|
api.edit_monitor(monitor_id, **monitor)
|
||||||
|
print(f"Monitor {monitor_id} updated successfully")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description='Manage Uptime Kuma monitors')
|
||||||
|
subparsers = parser.add_subparsers(dest='command', help='Commands')
|
||||||
|
|
||||||
|
# List command
|
||||||
|
subparsers.add_parser('list', help='List all monitors')
|
||||||
|
|
||||||
|
# Add command
|
||||||
|
add_parser = subparsers.add_parser('add', help='Add a monitor')
|
||||||
|
add_parser.add_argument('--name', required=True, help='Monitor name')
|
||||||
|
add_parser.add_argument('--url', required=True, help='URL to monitor')
|
||||||
|
add_parser.add_argument('--type', default='http', help='Monitor type (http, tcp, ping, dns, docker)')
|
||||||
|
add_parser.add_argument('--interval', type=int, default=60, help='Check interval in seconds')
|
||||||
|
add_parser.add_argument('--ignore-tls', action='store_true', help='Ignore TLS/SSL certificate errors')
|
||||||
|
|
||||||
|
# Delete command
|
||||||
|
delete_parser = subparsers.add_parser('delete', help='Delete a monitor')
|
||||||
|
delete_parser.add_argument('--id', type=int, required=True, help='Monitor ID')
|
||||||
|
|
||||||
|
# Update command
|
||||||
|
update_parser = subparsers.add_parser('update', help='Update a monitor')
|
||||||
|
update_parser.add_argument('--id', type=int, required=True, help='Monitor ID')
|
||||||
|
update_parser.add_argument('--name', help='New name')
|
||||||
|
update_parser.add_argument('--url', help='New URL')
|
||||||
|
update_parser.add_argument('--interval', type=int, help='New interval')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if not args.command:
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Connect to API
|
||||||
|
api = connect()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if args.command == 'list':
|
||||||
|
list_monitors(api)
|
||||||
|
elif args.command == 'add':
|
||||||
|
ignore_tls = getattr(args, 'ignore_tls', False)
|
||||||
|
add_monitor(api, args.name, args.url, args.type, args.interval, ignore_tls)
|
||||||
|
elif args.command == 'delete':
|
||||||
|
delete_monitor(api, args.id)
|
||||||
|
elif args.command == 'update':
|
||||||
|
update_monitor(api, args.id, name=args.name, url=args.url, interval=args.interval)
|
||||||
|
finally:
|
||||||
|
api.disconnect()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Executable
+71
@@ -0,0 +1,71 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Quick script to add tags to a monitor
|
||||||
|
# Usage: ./tag_monitor.sh MONITOR_ID TAG_ID [TAG_ID...]
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# ./tag_monitor.sh 15 3 4 # Tag monitor 15 as application + web
|
||||||
|
# ./tag_monitor.sh 20 7 8 # Tag monitor 20 as infrastructure + storage
|
||||||
|
# ./tag_monitor.sh 25 1 2 # Tag monitor 25 as hardware + monitoring
|
||||||
|
#
|
||||||
|
# Tag IDs:
|
||||||
|
# 1=hardware 2=monitoring 3=application 4=web 5=database
|
||||||
|
# 6=media 7=infrastructure 8=storage 9=virtualization 10=vm
|
||||||
|
|
||||||
|
if [ $# -lt 2 ]; then
|
||||||
|
echo "Usage: $0 MONITOR_ID TAG_ID [TAG_ID...]"
|
||||||
|
echo ""
|
||||||
|
echo "Tag IDs:"
|
||||||
|
echo " 1=hardware 2=monitoring 3=application 4=web 5=database"
|
||||||
|
echo " 6=media 7=infrastructure 8=storage 9=virtualization 10=vm"
|
||||||
|
echo ""
|
||||||
|
echo "Examples:"
|
||||||
|
echo " $0 15 3 4 # Tag monitor 15 as application + web"
|
||||||
|
echo " $0 20 7 8 # Tag monitor 20 as infrastructure + storage"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
MONITOR_ID=$1
|
||||||
|
shift
|
||||||
|
TAG_IDS="$@"
|
||||||
|
|
||||||
|
# Check for credentials
|
||||||
|
if [ -z "$UPTIME_KUMA_USERNAME" ] || [ -z "$UPTIME_KUMA_PASSWORD" ]; then
|
||||||
|
echo "Error: Set UPTIME_KUMA_USERNAME and UPTIME_KUMA_PASSWORD environment variables"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Convert tag IDs to Python list format
|
||||||
|
TAG_LIST=$(echo "$TAG_IDS" | sed 's/ /, /g')
|
||||||
|
|
||||||
|
python3 << EOF
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
api = UptimeKumaApi("https://uptime.kolpacksoftware.com", ssl_verify=False)
|
||||||
|
|
||||||
|
try:
|
||||||
|
api.login(os.getenv('UPTIME_KUMA_USERNAME'), os.getenv('UPTIME_KUMA_PASSWORD'))
|
||||||
|
|
||||||
|
# Get monitor name for display
|
||||||
|
monitor = api.get_monitor(${MONITOR_ID})
|
||||||
|
print(f"Tagging monitor ${MONITOR_ID} ({monitor['name']})...")
|
||||||
|
|
||||||
|
for tag_id in [${TAG_LIST}]:
|
||||||
|
try:
|
||||||
|
api.add_monitor_tag(tag_id=tag_id, monitor_id=${MONITOR_ID}, value='')
|
||||||
|
print(f" ✓ Added tag ID {tag_id}")
|
||||||
|
except Exception as e:
|
||||||
|
if 'already' in str(e).lower():
|
||||||
|
print(f" - Tag ID {tag_id} already assigned")
|
||||||
|
else:
|
||||||
|
print(f" ✗ Failed to add tag ID {tag_id}: {e}")
|
||||||
|
|
||||||
|
print("✅ Done!")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
finally:
|
||||||
|
api.disconnect()
|
||||||
|
EOF
|
||||||
Executable
+62
@@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Test tagging a single monitor to debug the issue
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
|
UPTIME_KUMA_URL = "https://uptime.kolpacksoftware.com"
|
||||||
|
USERNAME = os.getenv('UPTIME_KUMA_USERNAME')
|
||||||
|
PASSWORD = os.getenv('UPTIME_KUMA_PASSWORD')
|
||||||
|
|
||||||
|
def connect():
|
||||||
|
api = UptimeKumaApi(UPTIME_KUMA_URL, ssl_verify=False)
|
||||||
|
if USERNAME and PASSWORD:
|
||||||
|
api.login(USERNAME, PASSWORD)
|
||||||
|
else:
|
||||||
|
print("Error: Set credentials")
|
||||||
|
sys.exit(1)
|
||||||
|
return api
|
||||||
|
|
||||||
|
def main():
|
||||||
|
api = connect()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Test with monitor 1
|
||||||
|
monitor_id = 1
|
||||||
|
print(f"Testing with monitor {monitor_id}...")
|
||||||
|
|
||||||
|
# Get current monitor data
|
||||||
|
monitor = api.get_monitor(monitor_id)
|
||||||
|
print(f"\nCurrent monitor data keys: {list(monitor.keys())}")
|
||||||
|
print(f"Current tags: {monitor.get('tags', [])}")
|
||||||
|
|
||||||
|
# Try to add tags - method 1: using tag list
|
||||||
|
print("\n--- Attempting to add tags ---")
|
||||||
|
monitor['tags'] = [
|
||||||
|
{'tag_id': 1, 'value': ''}, # hardware
|
||||||
|
{'tag_id': 2, 'value': ''} # monitoring
|
||||||
|
]
|
||||||
|
|
||||||
|
print(f"Tags to add: {monitor['tags']}")
|
||||||
|
|
||||||
|
# Update the monitor
|
||||||
|
result = api.edit_monitor(monitor_id, **monitor)
|
||||||
|
print(f"Edit result: {result}")
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
updated_monitor = api.get_monitor(monitor_id)
|
||||||
|
print(f"\nAfter update, tags: {updated_monitor.get('tags', [])}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
finally:
|
||||||
|
api.disconnect()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user