Update infrastructure health reporting and appliance alerts

master
Carlo Costanzo 1 week ago
parent 9a656563c4
commit e154b4fc2f

@ -36,6 +36,37 @@
}) %}
{%- endmacro %}
{% macro scheduled_job_health(health, security_status, returns) -%}
{# Private application maintenance has a dedicated Security & Updates surface.
Do not duplicate its advisory row; retain it if that surface is unavailable.
Errors, unrelated jobs and missing/truncated telemetry remain visible. #}
{% set raw = health.get('issues', []) if health is mapping else [] %}
{% set rows = raw | select('mapping') | list if raw is sequence and raw is not string and raw is not mapping else [] %}
{% set ns = namespace(rows=[], removed=0) %}
{% for row in rows %}
{% if row.get('id') == 'app_maintenance' and row.get('severity') == 'warning' and
security_status in ['review', 'needs_attention', 'coverage_unknown', 'waiting_vendor_patch'] %}
{% set ns.removed = ns.removed + 1 %}
{% else %}
{% set ns.rows = ns.rows + [row] %}
{% endif %}
{% endfor %}
{% if ns.removed %}
{% set errors = [health.get('errorCount', 0) | int(0), 1 if health.get('status') == 'error' else 0] | max %}
{% set count = [[health.get('issueCount', 0) | int(0), rows | count] | max - ns.removed, errors] | max %}
{% set warnings = [health.get('warningCount', 0) | int(0) - ns.removed, count - errors, 0] | max %}
{% set labels = ns.rows[:3] | map(attribute='label') | list %}
{% set remaining = [count - labels | count, 0] | max %}
{% set summary = 'No scheduled jobs need attention' if count == 0 else
count ~ ' scheduled job' ~ ('s' if count != 1 else '') ~ ' need' ~ ('' if count != 1 else 's') ~ ' attention: ' ~
(labels | join(', ') if labels else 'details unavailable') ~ (', +' ~ remaining ~ ' more' if remaining and labels else '') %}
{% do returns(dict(health, ok=count == 0, status='error' if errors else 'warning' if count else 'ok',
issueCount=count, errorCount=errors, warningCount=warnings, issues=ns.rows, summary=summary)) %}
{% else %}
{% do returns(health) %}
{% endif %}
{%- endmacro %}
{% macro scheduled_job_issues(returns) -%}
{# One row per reported job; retain a visible fallback for missing/truncated telemetry. #}
{% set entity_id = 'sensor.bearclaw_scheduled_job_health' %}

@ -19,6 +19,7 @@
# Notes: Status telemetry polling expects !secret bearclaw_status_url (token header stays !secret bearclaw_token).
# Notes: Status telemetry includes the latest 12 dispatches in the rolling 24-hour window for the Joanna Activity drill-down.
# Notes: Status telemetry exposes compact scheduled-job warning/error health for the Systems dashboard.
# Notes: Maintenance advisories use Security & Updates once; other job errors and unavailable telemetry remain visible.
# Notes: Critical appliance updates open one operator-only Repair; vendor waits stay amber and never dispatch self-updates.
# Notes: The copyable Codex security prompt contains aggregate context and retrieves fresh private evidence when used.
# Notes: Status telemetry distinguishes the compact BearClaw working-memory index from the federated OneNote KB.
@ -239,26 +240,33 @@ template:
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') %}
{{ health is mapping and health.get('status') in ['ok', 'warning', 'error'] }}
state: >-
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true) %}
{% from 'infrastructure_health.jinja' import scheduled_job_health %}
{% set health = (scheduled_job_health | as_function)(state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true), states('sensor.joanna_security_updates')) %}
{{ health.get('status', 'unknown') }}
attributes:
issue_count: >-
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true) %}
{% from 'infrastructure_health.jinja' import scheduled_job_health %}
{% set health = (scheduled_job_health | as_function)(state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true), states('sensor.joanna_security_updates')) %}
{{ health.get('issueCount', 0) | int(0) }}
error_count: >-
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true) %}
{% from 'infrastructure_health.jinja' import scheduled_job_health %}
{% set health = (scheduled_job_health | as_function)(state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true), states('sensor.joanna_security_updates')) %}
{{ health.get('errorCount', 0) | int(0) }}
warning_count: >-
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true) %}
{% from 'infrastructure_health.jinja' import scheduled_job_health %}
{% set health = (scheduled_job_health | as_function)(state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true), states('sensor.joanna_security_updates')) %}
{{ health.get('warningCount', 0) | int(0) }}
summary: >-
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true) %}
{% from 'infrastructure_health.jinja' import scheduled_job_health %}
{% set health = (scheduled_job_health | as_function)(state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true), states('sensor.joanna_security_updates')) %}
{{ health.get('summary', 'Scheduled-job health unavailable') }}
issues: >-
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true) %}
{% from 'infrastructure_health.jinja' import scheduled_job_health %}
{% set health = (scheduled_job_health | as_function)(state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true), states('sensor.joanna_security_updates')) %}
{{ health.get('issues', []) }}
generated_at: >-
{% set health = state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true) %}
{% from 'infrastructure_health.jinja' import scheduled_job_health %}
{% set health = (scheduled_job_health | as_function)(state_attr('sensor.bearclaw_status_telemetry', 'scheduledJobsHealth') | default({}, true), states('sensor.joanna_security_updates')) %}
{{ health.get('generatedAt') }}
- name: Joanna OneNote Health

@ -1131,6 +1131,7 @@ automation:
- alias: "Docker Host Disk Pressure Monitor"
id: docker_host_disk_pressure_monitor
description: "Track Docker host root disk pressure from normalized Glances sensors and dispatch Joanna on band changes."
# Persist each pressure transition before requesting external remediation.
mode: queued
trigger:
- platform: time_pattern
@ -1199,7 +1200,13 @@ automation:
description: >-
{{ host_name }} root disk usage is critically high.
Free space or expand the host filesystem before Docker workloads fail.
- service: input_text.set_value
target:
entity_id: "{{ band_entity }}"
data:
value: "critical"
- service: script.joanna_dispatch
continue_on_error: true
data:
trigger_context: "HA automation docker_host_disk_pressure_monitor (Docker Host Disk Pressure Monitor - Critical)"
source: "home_assistant_automation.docker_host_disk_pressure_monitor.critical"
@ -1230,18 +1237,19 @@ automation:
message: >-
{{ host_name }} disk usage is critical at {{ disk_pct | round(1) }}%.
Repair {{ issue_id }} opened and Joanna investigation requested.
- service: input_text.set_value
target:
entity_id: "{{ band_entity }}"
data:
value: "critical"
- conditions: "{{ current_band == 'warning' and previous_band not in ['warning', 'critical'] }}"
sequence:
- service: repairs.remove
continue_on_error: true
data:
issue_id: "{{ issue_id }}"
- service: input_text.set_value
target:
entity_id: "{{ band_entity }}"
data:
value: "warning"
- service: script.joanna_dispatch
continue_on_error: true
data:
trigger_context: "HA automation docker_host_disk_pressure_monitor (Docker Host Disk Pressure Monitor - Warning)"
source: "home_assistant_automation.docker_host_disk_pressure_monitor.warning"
@ -1272,11 +1280,6 @@ automation:
message: >-
{{ host_name }} disk usage warning at {{ disk_pct | round(1) }}%.
Joanna investigation requested without opening a warning Repair.
- service: input_text.set_value
target:
entity_id: "{{ band_entity }}"
data:
value: "warning"
- conditions: "{{ current_band == 'warning' and previous_band == 'critical' }}"
sequence:
- service: repairs.remove

Loading…
Cancel
Save

Powered by TurnKey Linux.