# Momentry 監控系統配置文件
# 路徑: /Users/accusys/momentry_core_0.1/monitor/config/monitor_config.yaml

monitoring:
  enabled: true
  check_interval: 300  # 秒 (5分鐘)
  
  # 數據庫連接
  database:
    host: "localhost"
    port: 5432
    username: "accusys"
    password: ""  # 使用 psql 連接
    name: "momentry"

# ============================================================
# Layer 1: External 監控
# ============================================================
external:
  enabled: true
  check_interval: 60  # 秒
  targets:
    - name: "ddns"
      type: "ddns"
      host: "momentry.ddns.net"
      enabled: true
    - name: "gateway"
      type: "gateway"
      host: "192.168.110.1"
      enabled: true
    - name: "internet"
      type: "internet"
      host: "8.8.8.8"
      enabled: true

# ============================================================
# Layer 2: Service 監控
# ============================================================
service:
  enabled: true
  check_interval: 300  # 秒
  services:
    - name: "postgresql"
      type: "postgres"
      port: 5432
      host: "localhost"
      check_cmd: "pg_isready -h localhost -p 5432 -U accusys"
      timeout: 5
      enabled: true
      
    - name: "redis"
      type: "redis"
      port: 6379
      host: "localhost"
      password: "accusys"
      check_cmd: "redis-cli -a accusys ping"
      timeout: 5
      enabled: true
      
    - name: "mariadb"
      type: "mariadb"
      port: 3306
      host: "localhost"
      check_cmd: "mysql -u root -e 'SELECT 1'"
      timeout: 5
      enabled: true
      
    - name: "n8n"
      type: "http"
      port: 5678
      host: "localhost"
      check_url: "http://localhost:5678/"
      timeout: 10
      enabled: true
      
    - name: "caddy"
      type: "http"
      port: 2019
      host: "localhost"
      check_url: "http://localhost:2019/config/"
      timeout: 10
      enabled: true
      
    - name: "gitea"
      type: "http"
      port: 3000
      host: "localhost"
      check_url: "http://localhost:3000/"
      timeout: 10
      enabled: true
      
    - name: "sftpgo"
      type: "http"
      port: 8080
      host: "localhost"
      timeout: 10
      enabled: true
      
    - name: "ollama"
      type: "http"
      port: 11434
      host: "localhost"
      check_url: "http://localhost:11434/api/tags"
      timeout: 10
      enabled: true
      
    - name: "qdrant"
      type: "http"
      port: 6333
      host: "localhost"
      check_url: "http://localhost:6333/collections"
      timeout: 10
      enabled: true
      
    - name: "mongodb"
      type: "mongodb"
      port: 27017
      host: "localhost"
      timeout: 10
      enabled: true
      
    - name: "php"
      type: "process"
      process_name: "php-fpm"
      enabled: true

    - name: "node"
      type: "process"
      process_name: "node"
      enabled: true
      check_interval: 60
      version_lock: "22.x"
      locked_processes:
        - "n8n"
      description: "Node.js 運行環境 (n8n 專用)"

    - name: "python"
      type: "process"
      process_name: "python3"
      enabled: true
      check_interval: 60
      version_lock: "3.11.14"
      scripts:
        - "/Users/accusys/momentry_core_0.1/scripts/asr_processor.py"
        - "/Users/accusys/momentry_core_0.1/scripts/thumbnail_extractor.py"
      description: "Python 運行環境 (Momentry 腳本專用)"

    - name: "rustdesk_hbbs"
      type: "process"
      process_name: "hbbs"
      port: 21116
      enabled: true
      
    - name: "rustdesk_hbbr"
      type: "process"
      process_name: "hbbr"
      port: 21117
      enabled: true

# ============================================================
# Layer 3: n8n Workflow 監控
# ============================================================
workflow:
  enabled: true
  check_interval: 300  # 秒
  n8n:
    host: "http://localhost:5678"
    api_key: ""  # 從環境變數或 n8n 獲取
  idle_threshold_days: 30
  suggestions:
    - type: "disable_idle"
      threshold_days: 30
    - type: "delete_unused"
      threshold_days: 90
    - type: "optimize_failures"
      failure_rate_threshold: 0.2

# ============================================================
# Layer 4: WordPress Portal 監控
# ============================================================
portal:
  enabled: true
  check_interval: 300  # 秒
  wordpress:
    site_url: "https://wp.momentry.ddns.net"
    db_host: "localhost"
    db_name: "wordpress"
    db_user: "wp_user"
    db_password: "wp_password_123"
  page_monitoring:
    enabled: true
    pages:
      - url: "/"
        name: "homepage"
      - url: "/wp-login.php"
        name: "login_page"
    response_time_threshold_ms: 3000
  account_monitoring:
    enabled: true
    check_interval: 3600  # 小時
    alert_on_new_admin: true

# ============================================================
# Layer 5: Database 監控
# ============================================================
database:
  enabled: true
  check_interval: 300  # 秒
  
  postgres:
    enabled: true
    databases:
      - name: "momentry"
      - name: "gitea"
      - name: "n8n"
      - name: "video_register"
    schema_monitoring: true
    
  redis:
    enabled: true
    password: "accusys"
    alert_thresholds:
      memory_percent: 80
      connected_clients: 100
      
  qdrant:
    enabled: true
    collections_watch: ["*"]  # 監控所有
    
  mariadb:
    enabled: true
    databases:
      - name: "wordpress"
  
  mongodb:
    enabled: true
    databases:
      - name: "momentry"
      - name: "admin"

# ============================================================
# Layer 6: 使用者監控
# ============================================================
users:
  enabled: true
  check_interval: 60  # 秒
  
  session_tracking:
    enabled: true
    track_ssh: true
    track_web: true
    track_db: true
    track_sftp: true
    
  login_monitoring:
    enabled: true
    track_system: true
    track_wordpress: true
    track_n8n: true
    track_gitea: true
    
  sudo_tracking:
    enabled: true
    
  anomaly_detection:
    enabled: true
    rules:
      - type: "brute_force"
        threshold: 5
        window_seconds: 60
        severity: "critical"
      - type: "unusual_time"
        severity: "medium"
        allowed_hours: "08:00-22:00"
      - type: "idle_session"
        threshold_hours: 24
        severity: "low"

# ============================================================
# Layer 7: Storage 監控 (獨立配置)
# ============================================================
storage:
  enabled: false  # 獨立實現
  paths:
    hot: "/Users/accusys/momentry/data"
    warm: "/Volumes/RAID System/momentry/warm"
    cold: "/Volumes/Object Storage/momentry/archive"
    temp: "/Users/accusys/momentry/tmp"
    backup: "/Users/accusys/momentry/backup"
  clusters:
    - name: "family"
      path: "data/family"
      quota: "1TB"
    - name: "work"
      path: "data/work"
      quota: "2TB"
    - name: "wordpress"
      path: "data/wordpress"
      quota: "500GB"
    - name: "shared"
      path: "data/shared"
      quota: "1TB"
  migration:
    hot_to_warm_days: 7
    warm_to_cold_days: 90

# ============================================================
# Layer 7: 備份監控
# ============================================================
backup:
  enabled: true
  check_interval: 3600  # 秒 (每小時檢查一次)
  
  # 備份根目錄
  backup_root: "/Users/accusys/momentry/backup"
  
  # 服務列表
  services:
    - name: "postgresql"
      enabled: true
      backup_type: "database"
      method: "pg_dump"
      schedule: "daily"
      retention:
        daily: 7
        weekly: 4
        monthly: 12
        
    - name: "redis"
      enabled: true
      backup_type: "database"
      method: "rdb"
      schedule: "daily"
      retention:
        daily: 7
        weekly: 4
        
    - name: "mariadb"
      enabled: true
      backup_type: "database"
      method: "mysqldump"
      schedule: "daily"
      retention:
        daily: 7
        weekly: 4
        
    - name: "n8n"
      enabled: true
      backup_type: "full"
      method: "tar"
      schedule: "daily"
      retention:
        daily: 7
        weekly: 4
        
    - name: "qdrant"
      enabled: true
      backup_type: "database"
      method: "snapshot"
      schedule: "daily"
      retention:
        daily: 7
        weekly: 4
        
    - name: "gitea"
      enabled: true
      backup_type: "full"
      method: "gitea_dump"
      schedule: "weekly"
      retention:
        weekly: 4
        monthly: 12
        
    - name: "mongodb"
      enabled: true
      backup_type: "database"
      method: "mongodump"
      schedule: "daily"
      retention:
        daily: 7
        weekly: 4
        
    - name: "ollama"
      enabled: true
      backup_type: "config"
      method: "tar"
      schedule: "weekly"
      retention:
        weekly: 4
        monthly: 12
        
    - name: "caddy"
      enabled: true
      backup_type: "config"
      method: "file"
      schedule: "weekly"
      retention:
        weekly: 4
        
    - name: "sftpgo"
      enabled: true
      backup_type: "config"
      method: "file"
      schedule: "weekly"
      retention:
        weekly: 4
        
    - name: "php"
      enabled: true
      backup_type: "config"
      method: "file"
      schedule: "weekly"
      retention:
        weekly: 4
        
  # 溫冷轉移配置
  tiering:
    enabled: true
    tiering_interval: 86400  # 秒 (每天)
    rules:
      - from: "daily"
        to: "weekly"
        after_days: 7
      - from: "weekly"
        to: "monthly"
        after_days: 30
      - from: "monthly"
        to: "archive"
        after_days: 90
        
  # 存儲閾值
  thresholds:
    backup_age_warning_days: 7
    backup_age_critical_days: 14
    storage_percent_warning: 80
    storage_percent_critical: 90
    
  # 驗證
  verify:
    enabled: true
    verify_on_completion: true
    test_restore: false  # 僅測試還原，不實際執行

# ============================================================
# 通知配置
# ============================================================
notifications:
  enabled: true
  log_only: true  # 僅記錄，不發送
  
  # 日誌記錄
  log:
    enabled: true
    path: "/Users/accusys/momentry/log/monitor"
    
  # n8n webhook (預設不啟用)
  n8n:
    enabled: false
    webhook_url: "http://localhost:5678/webhook/monitor-alert"
    
  # Telegram (預設不啟用)
  telegram:
    enabled: false
    bot_token: ""
    chat_id: ""
    
  # Email (預設不啟用)
  email:
    enabled: false
    smtp_host: ""
    smtp_port: 587
    smtp_user: ""
    smtp_password: ""
    from_address: ""
    to_addresses: []

# ============================================================
# 數據保留
# ============================================================
retention:
  history_days: 30
  anomaly_days: 90
  session_days: 7
  login_days: 30

# ============================================================
# 報警閾值
# ============================================================
thresholds:
  service_response_time_ms: 3000
  database_memory_percent: 80
  disk_percent: 90
  cpu_percent: 90
  login_failures_per_user: 3
  brute_force_per_minute: 5
