#!/usr/bin/env python3 """ Create scheduled Fleet Health Check job in DaemonControl. This job runs every 5 minutes and checks: - Docker containers - WireGuard tunnel - Backup status - Disk space Results are stored in database and visible in Fleet tab. """ import sys from pathlib import Path from datetime import datetime # Add project root to path project_root = Path(__file__).parent.parent sys.path.insert(0, str(project_root)) from core import DatabaseManager def create_healthcheck_job(): """Create Fleet Health Check job""" db = DatabaseManager() now = datetime.now().isoformat() # Create job with db.get_connection() as conn: cursor = conn.cursor() # Check if already exists cursor.execute("SELECT id FROM jobs WHERE name = ?", ('Fleet Health Check',)) existing = cursor.fetchone() if existing: print("❌ Fleet Health Check job already exists (ID: {})".format(existing['id'])) print(" To recreate, delete it first from the Jobs tab in the GUI") return # Create Python script that runs the health check healthcheck_script = project_root / 'scripts' / 'fleet_healthcheck_runner.py' # Create job cursor.execute(""" INSERT INTO jobs ( name, job_type, executable_path, working_directory, timeout, enabled, description, created_at, updated_at ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( 'Fleet Health Check', 'script', # Run as script str(healthcheck_script), str(project_root), 300, # 5 min timeout 1, # Enabled 'Monitors Docker, tunnel, backup, disk every 5 minutes', now, now )) job_id = cursor.lastrowid # Create schedule (every 5 minutes) cursor.execute(""" INSERT INTO schedules ( job_id, cron_expression, enabled, created_at, updated_at ) VALUES (?, ?, ?, ?, ?) """, ( job_id, '*/5 * * * *', # Every 5 minutes 1, now, now )) print("✅ Fleet Health Check job created successfully!") print(f" Job ID: {job_id}") print(" Schedule: Every 5 minutes (*/5 * * * *)") print(" Status: Enabled") print() print("📊 The job will:") print(" - Monitor Docker containers") print(" - Check WireGuard tunnel") print(" - Verify backup status") print(" - Check disk space") print() print("🎯 Next steps:") print(" 1. The daemon will run this job automatically every 5 minutes") print(" 2. View results in the Fleet tab of the GUI") print(" 3. Execution history appears in the History tab") print() print("💡 To create the runner script:") print(f" python3 scripts/create_healthcheck_runner.py") if __name__ == '__main__': create_healthcheck_job()