# bench-client config.yaml
# Objectif: décrire précisément
# - les outils à utiliser (et exigences d'installation)
# - les informations à collecter
# - les benchmarks à exécuter
# - les paramètres (timeouts, limites, endpoints, debug)
#
# Le binaire (Go/Rust) charge ce fichier depuis HTTP(S), valide les bornes, applique des defaults sûrs,
# et peut fallback sur une config locale si indisponible.

config_version: 1
profile: default

backend:
  # URL finale du POST (le programme peut aussi accepter server_base_url + path)
  url: "http://10.0.0.50:8007/api/benchmark"
  # Auth: idéalement injecté par variable d'env sur le client; éviter de mettre le token dans la config distante.
  auth:
    mode: bearer_env
    env_var: "test_hardware_perf"
  http:
    timeout_s: 15
    retries: 2
    retry_backoff_s: 2
    tls:
      verify: true

remote_config:
  # Options de cache/ETag si le binaire gère le rafraîchissement
  cache_path: "/var/cache/bench-client/config.yaml"
  use_etag: true
  refresh_max_age_s: 86400

runtime:
  # Timeouts globaux de sécurité
  max_total_runtime_s: 480
  command_timeout_s: 30
  command_timeout_overrides:
    dmidecode_s: 20
    smartctl_s: 10
    lsblk_s: 10
    sysbench_cpu_s: 120
    sysbench_mem_s: 60
    fio_s: 120
    iperf3_s: 20
  temp_dir: "/tmp"
  locale: "C"
  path_prepend:
    - "/usr/sbin"
    - "/sbin"

logging:
  level: info          # trace|debug|info|warn|error
  progress: true       # affichage étapes (1/N) + items
  show_command_lines: false
  capture_raw_output: true   # remonte dans raw_info (attention taille)
  raw_output_max_kb: 5120
  save_payload_to_tmp: true
  payload_tmp_dir: "/tmp"
  payload_filename_prefix: "bench_payload_"
  interactive_pause_on_debug: true

payload:
  dir: "."
  prefix: "bench_payload_"
  always_save: true

device_identity:
  # device_identifier envoyé au backend
  prefer:
    - hostname
    - machine_id
  hostname_command: "hostname"
  machine_id_path: "/etc/machine-id"

dependencies:
  # Liste des programmes externes (installés par le script shell)
  # Le binaire doit pouvoir:
  # - détecter présence/version (optionnel)
  # - marquer chaque "feature" comme disponible ou non
  required_base:
    - name: "curl"
      purpose: "Téléchargements/diagnostics (souvent côté script)"
    - name: "jq"
      purpose: "Optionnel: debug/validation (souvent côté script, pas nécessaire au binaire)"
    - name: "lscpu"
      purpose: "Infos CPU"
    - name: "free"
      purpose: "Infos mémoire"
    - name: "lsblk"
      purpose: "Infos stockage/partitions"
    - name: "ip"
      purpose: "Interfaces réseau, adresses IP"
    - name: "bc"
      purpose: "Optionnel: calculs (si pas fait en code)"
    - name: "dmidecode"
      purpose: "Infos BIOS/carte mère/RAM/DMI"
      requires_root: true
    - name: "smartctl"
      package: "smartmontools"
      purpose: "Infos disques SMART"
      requires_root: true
    - name: "ethtool"
      purpose: "Vitesse réseau, Wake-on-LAN, driver"
      requires_root: true
    - name: "lspci"
      package: "pciutils"
      purpose: "Liste périphériques PCI (GPU/Audio/etc.)"
    - name: "lsusb"
      package: "usbutils"
      purpose: "Liste périphériques USB"
    - name: "aplay"
      package: "alsa-utils"
      purpose: "Inventaire audio ALSA"
    - name: "arecord"
      package: "alsa-utils"
      purpose: "Inventaire capture ALSA"
    - name: "pactl"
      package: "pulseaudio-utils"
      purpose: "Infos audio PulseAudio/PipeWire (si dispo)"
    - name: "iw"
      package: "iw"
      purpose: "SSID + bitrate Wi-Fi"
    - name: "loginctl"
      package: "systemd"
      purpose: "Type de session (x11/wayland/tty)"
    - name: "xrandr"
      package: "x11-xserver-utils"
      purpose: "Résolution écran (X11)"
    - name: "xdpyinfo"
      package: "x11-utils"
      purpose: "Résolution écran (fallback X11)"
    - name: "swaymsg"
      package: "sway"
      purpose: "Résolution écran (Wayland/Sway)"
    - name: "nvidia-smi"
      package: "nvidia-utils"
      purpose: "Infos GPU NVIDIA (si présent)"
    - name: "systemd-detect-virt"
      package: "systemd"
      purpose: "Détection virtualisation/proxmox"
    - name: "pveversion"
      package: "pve-manager"
      purpose: "Détection hôte Proxmox (si présent)"
  benchmark_tools:
    - name: "sysbench"
      purpose: "Bench CPU et mémoire"
    - name: "fio"
      purpose: "Bench disque"
    - name: "iperf3"
      purpose: "Bench réseau"
    - name: "ping"
      package: "iputils-ping"
      purpose: "Vérifier accessibilité iperf server"
    - name: "nc"
      package: "netcat-openbsd"
      purpose: "Tester port 5201 iperf3"

collection:
  # Liste des infos à récupérer, structurées comme dans ton script.
  system:
    enabled: true
    items:
      - hostname
      - os_id
      - os_version
      - kernel_version
      - architecture
      - session_type           # XDG_SESSION_TYPE / loginctl / DISPLAY / WAYLAND_DISPLAY
      - screen_resolution      # xrandr/xdpyinfo/swaymsg
      - last_boot_time         # who -b
      - uptime_seconds         # /proc/uptime
      - battery_percentage     # /sys/class/power_supply/BAT*/capacity
      - battery_status         # /sys/class/power_supply/BAT*/status
      - battery_health         # /sys/class/power_supply/BAT*/health ou uevent
      - virtualization         # systemd-detect-virt + proxmox hints
    virtualization_detection:
      enabled: true
      proxmox:
        detect_host_by:
          - pveversion
          - "/etc/pve"
        detect_guest_by:
          - systemd_detect_virt
          - qemu_guest_agent
          - dmidecode_manufacturer_product_matches: ["qemu", "proxmox"]
      capture:
        - is_proxmox_host
        - is_proxmox_guest
        - proxmox_version
        - virtualization_type

  cpu:
    enabled: true
    source:
      primary: lscpu
      supplement_dmidecode: true
    items:
      - vendor
      - model
      - cores_physical        # cores_per_socket * sockets
      - threads               # nproc
      - base_freq_ghz         # lscpu CPU MHz -> GHz
      - max_freq_ghz          # lscpu CPU max MHz -> GHz
      - cache_l1_kb
      - cache_l2_kb
      - cache_l3_kb
      - flags                 # CPU flags list
      - microarchitecture     # depuis dmidecode type 4 (Family) si manquant
    raw_capture:
      - lscpu_output

  ram:
    enabled: true
    sources:
      - free
      - dmidecode
    items:
      - total_mb
      - used_mb
      - free_mb
      - shared_mb
      - slots_total           # dmidecode -t 16
      - slots_used            # dmidecode -t 17
      - max_capacity_mb       # dmidecode -t 16 Maximum Capacity
      - ecc                   # dmidecode -t memory Error Correction Type
      - layout                # par slot: locator, size, type, speed, configured_speed, form_factor, type_detail, rank, manufacturer, part_number
    raw_capture:
      - dmidecode_full

  gpu:
    enabled: true
    sources:
      - lspci
      - nvidia_smi_optional
    items:
      - vendor                # NVIDIA/AMD/Intel/Unknown
      - model                 # lspci vga/3d ou nvidia-smi name
      - memory_dedicated_mb   # nvidia-smi (si dispo)
      - driver_version        # nvidia-smi (si dispo)

  motherboard_bios:
    enabled: true
    source: dmidecode
    items:
      - baseboard_manufacturer
      - baseboard_product_name
      - bios_vendor
      - bios_version
      - bios_release_date

  pci_devices:
    enabled: true
    source: lspci
    items:
      - slot
      - class
      - vendor
      - device

  usb_devices:
    enabled: true
    source: lsusb
    items:
      - bus
      - device
      - vendor_id
      - product_id
      - name

  audio:
    enabled: true
    sources:
      - lspci
      - alsa
      - pactl_optional
    items:
      hardware:
        - pci_audio_devices     # lspci audio
        - alsa_playback         # aplay -l
        - alsa_capture          # arecord -l
        - pcm_devices           # aplay -L
      software:
        - backend               # pipewire/pulseaudio/alsa
        - server_name
        - server_version
        - default_sink
        - default_source
        - sinks
        - sources

  storage:
    enabled: true
    sources:
      - lsblk
      - smartctl
    devices:
      enumerate_by: "lsblk_disks"   # lsblk -d -n -o NAME,TYPE
      include_removable: false
      items:
        - device                 # /dev/sda
        - model                  # smartctl -i
        - serial                 # smartctl -i
        - size                   # lsblk
        - type                   # rota -> ssd/hdd
        - interface              # tran
        - temperature_c          # smartctl -A
        - smart_health           # smartctl -H
    partitions:
      enabled: true
      source: lsblk_json
      items:
        - name
        - mount_point
        - fs_type
        - total_gb
        - used_gb
        - free_gb
    raw_capture:
      - lsblk_output

  network_shares:
    enabled: true
    source: "/proc/mounts"
    detect_fs_types:
      - nfs
      - nfs4
      - cifs
      - smbfs
      - fuse.cifs
      - fuse.smbfs
      - afp
      - afpfs
      - fuse.afpfs
      - sshfs
      - fuse.sshfs
      - ftpfs
      - curlftpfs
      - fuse.ftpfs
      - davfs
      - davfs2
      - fuse.webdavfs
    items:
      - protocol
      - source
      - mount_point
      - fs_type
      - options
      - total_gb
      - used_gb
      - free_gb

  network:
    enabled: true
    sources:
      - ip
      - ethtool
      - iw_optional
    interface_filter:
      # reprise logique script: UP|UNKNOWN sauf interfaces virtuelles connues
      include_states: ["UP", "UNKNOWN"]
      exclude_name_prefixes: ["lo", "docker", "br-", "veth", "tap", "fw"]
    items:
      - name
      - type                  # bridge|ethernet|wifi|unknown
      - mac
      - ip_address
      - speed_mbps            # ethtool speed ou iw tx bitrate
      - driver                # ethtool -i ou /sys/.../driver
      - ssid                  # iw dev link
      - wake_on_lan           # ethtool Wake-on

raw_info:
  enabled: true
  include:
    - lscpu
    - lsblk
    - dmidecode
  max_size_kb: 5120

benchmarks:
  enabled: true
  # Pondérations identiques à ton script (si résultat dispo)
  weights:
    cpu: 0.40
    memory: 0.20
    disk: 0.20
    network: 0.10
    gpu: 0.10

  cpu_sysbench:
    enabled: true
    tool: sysbench
    params:
      cpu_max_prime: 20000
      single_thread: 1
      multi_threads: "all"      # all -> nproc
    outputs:
      - events_per_sec_single
      - events_per_sec_multi
      - duration_s
      - score_single
      - score_multi
      - score_global

  memory_sysbench:
    enabled: true
    tool: sysbench
    params:
      total_size: "1G"
    outputs:
      - throughput_mib_s
      - score

  disk_fio:
    enabled: true
    tool: fio
    safety:
      # Empêcher un bench destructif ou trop long
      max_runtime_s: 60
      max_size: "1G"
      direct: 1
    params:
      name: "bench"
      ioengine: "libaio"
      rw: "randrw"
      bs: "4k"
      size: "500M"
      numjobs: 1
      runtime_s: 30
      time_based: true
      output_format: "json"
    outputs:
      - read_mb_s
      - write_mb_s
      - iops_read
      - iops_write
      - latency_ms
      - score

  network_iperf3:
    enabled: true
    tool: iperf3
    server: "10.0.0.50"
    port: 5201
    prechecks:
      ping:
        enabled: true
        count: 1
        timeout_s: 1
      port_check:
        enabled: true
        tool: nc
        timeout_s: 2
    params:
      duration_s: 10
      bidir: true
      json: true
    outputs:
      - upload_mbps
      - download_mbps
      - ping_ms
      - score
      # placeholders (comme ton script)
      - jitter_ms
      - packet_loss_percent

  gpu:
    enabled: false
    note: "GPU bench non implémenté dans le script d'origine (placeholder)."

payload_mapping:
  # Le binaire peut mapper ses structures internes vers le schéma backend actuel.
  # Utile si ton backend attend des champs précis.
  device_identifier: "system.hostname"
  bench_script_version_field: "bench_client_version"
  include_sections:
    - hardware
    - results
    - raw_info

limits:
  # Bornes générales de sécurité (validation côté client)
  max_payload_kb: 1024
  max_raw_info_kb: 5120
  max_fio_runtime_s: 60
  max_fio_size_bytes: 1073741824      # 1 GiB
  max_sysbench_cpu_prime: 50000
  max_iperf_duration_s: 30

features:
  # Permet d'activer/désactiver rapidement des blocs selon machines
  enable_screen_resolution_detection: true
  enable_battery_detection: true
  enable_network_share_detection: true
  enable_audio_detection: true
  enable_proxmox_detection: true
