{# Unified Hosts widget — monitor status + agent glance per host, links to the hub. #}
{% from "_macros.html" import metric_style %}
{% if hosts %}
{% for host in hosts %}
{% set ping = latest_pings.get(host.id) %}
{% set dns = latest_dns.get(host.id) %}
{% set ut = uptime.get(host.id, {}) %}
{% set a = agent.get(host.name, {}) %}
{% set down = host.ping_enabled and ping and ping.status.value != 'up' %}
{% set name_style = "flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-weight:500;" %}
{% if session.user_id %}
{{ host.name }}
{% else %}
{{ host.name }}
{% endif %}
{% set spark = cpu_sparks.get(host.name) %}
{% if spark %}{{ spark | safe }}{% endif %}
{# Monitors #}
{% if host.ping_enabled and ping and ping.response_time_ms is not none %}
ping {{ "%.0f"|format(ping.response_time_ms) }}ms
{% endif %}
{% if ut.get('24h') is not none %}
24h {{ "%.1f"|format(ut['24h']) }}%
{% endif %}
{# Agent glance — failing metric coloured amber/red (≥80/≥90) #}
{% if a %}
{% if a.get('cpu_pct') is not none %}cpu {{ "%.0f"|format(a.cpu_pct) }}%{% endif %}
{% if a.get('mem_used_pct') is not none %}mem {{ "%.0f"|format(a.mem_used_pct) }}%{% endif %}
{% if a.get('disk_root') is not none %}disk / {{ "%.0f"|format(a.disk_root) }}%{% endif %}
{% if not a.fresh %}stale{% endif %}
{% else %}
no agent
{% endif %}