From f926ff733c6240ae8b82f605bf0a497e10819067 Mon Sep 17 00:00:00 2001 From: poprhythm Date: Sun, 8 Feb 2026 20:18:58 +0000 Subject: [PATCH] Fix and complete Uptime Kuma monitor tagging Successfully tagged all 12 monitors with service categories: - Used add_monitor_tag API method instead of edit_monitor - All hardware/monitoring, application, and infrastructure monitors now tagged - Added verification and fix scripts for debugging New files: - check_tags.py: Verify tag assignments - fix_missing_tags.py: Add specific missing tags - test_single_tag.py: Debug single monitor tagging - TAG_SUMMARY.md: Complete documentation of all tags and assignments All monitors are now properly organized by service category. --- uptime-kuma/TAG_SUMMARY.md | 61 ++++++++++++++++++++++++++++++++ uptime-kuma/add_tags.py | 27 ++++++-------- uptime-kuma/check_tags.py | 45 ++++++++++++++++++++++++ uptime-kuma/fix_missing_tags.py | 55 +++++++++++++++++++++++++++++ uptime-kuma/test_single_tag.py | 62 +++++++++++++++++++++++++++++++++ 5 files changed, 233 insertions(+), 17 deletions(-) create mode 100644 uptime-kuma/TAG_SUMMARY.md create mode 100755 uptime-kuma/check_tags.py create mode 100755 uptime-kuma/fix_missing_tags.py create mode 100755 uptime-kuma/test_single_tag.py diff --git a/uptime-kuma/TAG_SUMMARY.md b/uptime-kuma/TAG_SUMMARY.md new file mode 100644 index 0000000..1775dbd --- /dev/null +++ b/uptime-kuma/TAG_SUMMARY.md @@ -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! diff --git a/uptime-kuma/add_tags.py b/uptime-kuma/add_tags.py index 7bc68ee..9fe7be3 100755 --- a/uptime-kuma/add_tags.py +++ b/uptime-kuma/add_tags.py @@ -85,27 +85,20 @@ def ensure_tags_exist(api): return tag_map def add_tags_to_monitor(api, monitor_id, tag_names, tag_map): - """Add tags to a monitor""" - # Get monitor details + """Add tags to a monitor using add_monitor_tag method""" + # Get monitor details for name monitor = api.get_monitor(monitor_id) - # Build tag list - tag_ids = [] + # Add each tag using the dedicated method for tag_name in tag_names: if tag_name in tag_map: - tag_ids.append({'tag_id': tag_map[tag_name], 'value': ''}) - - # Preserve existing tags and add new ones - existing_tag_ids = monitor.get('tags', []) - existing_tag_id_set = {tag['tag_id'] for tag in existing_tag_ids} - - for tag_info in tag_ids: - if tag_info['tag_id'] not in existing_tag_id_set: - existing_tag_ids.append(tag_info) - - # Update monitor with tags - monitor['tags'] = existing_tag_ids - api.edit_monitor(monitor_id, **monitor) + 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}") diff --git a/uptime-kuma/check_tags.py b/uptime-kuma/check_tags.py new file mode 100755 index 0000000..1029acd --- /dev/null +++ b/uptime-kuma/check_tags.py @@ -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() diff --git a/uptime-kuma/fix_missing_tags.py b/uptime-kuma/fix_missing_tags.py new file mode 100755 index 0000000..5baec48 --- /dev/null +++ b/uptime-kuma/fix_missing_tags.py @@ -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() diff --git a/uptime-kuma/test_single_tag.py b/uptime-kuma/test_single_tag.py new file mode 100755 index 0000000..2d068ed --- /dev/null +++ b/uptime-kuma/test_single_tag.py @@ -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()