From b06565e0a779626e4c9583956506c15426e74f7c Mon Sep 17 00:00:00 2001 From: Carlo Costanzo Date: Wed, 26 Aug 2026 17:05:33 -0400 Subject: [PATCH] Refine BearClaw infrastructure health alerts --- .../infrastructure/partials/home_sections.yaml | 18 ++++++++++-------- .../partials/joanna_sections.yaml | 8 ++++++-- .../templates/button_card_templates.yaml | 4 ++++ config/packages/infrastructure.yaml | 4 ++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/config/dashboards/infrastructure/partials/home_sections.yaml b/config/dashboards/infrastructure/partials/home_sections.yaml index 3be09fdd..a3b7d286 100644 --- a/config/dashboards/infrastructure/partials/home_sections.yaml +++ b/config/dashboards/infrastructure/partials/home_sections.yaml @@ -192,9 +192,13 @@ icon: mdi:robot-outline variables: ok_state: ok - warning_state: warning + status_severity: > + [[[ + const raw = String(entity?.state ?? '').toLowerCase(); + if (['unknown', 'unavailable', 'none', ''].includes(raw)) return 'unknown'; + return raw === 'error' ? 'critical' : 'healthy'; + ]]] healthy_text: HEALTHY - warning_text: JOB WARNING critical_text: JOB ERROR tap_action: action: navigate @@ -349,14 +353,12 @@ name: BearClaw scheduled job needs attention icon: mdi:calendar-alert variables: - alert_kind: state_not - ok_state: ok - alert_severity: > - [[[ return entity?.state === 'warning' ? 'warning' : 'critical'; ]]] + alert_kind: state_is + alert_state: error + alert_severity: critical exception_detail: > [[[ return String(entity?.attributes?.summary ?? 'SCHEDULED JOB STATUS REQUIRES REVIEW').toUpperCase(); ]]] - state_display: > - [[[ return entity?.state === 'warning' ? 'WARNING' : 'ERROR'; ]]] + state_display: ERROR tap_action: action: navigate navigation_path: /dashboard-infrastructure/joanna diff --git a/config/dashboards/infrastructure/partials/joanna_sections.yaml b/config/dashboards/infrastructure/partials/joanna_sections.yaml index 281904ab..96b701a2 100644 --- a/config/dashboards/infrastructure/partials/joanna_sections.yaml +++ b/config/dashboards/infrastructure/partials/joanna_sections.yaml @@ -177,9 +177,13 @@ critical_text: JOB ERROR state_display: > [[[ - const count = Number.parseInt(entity?.attributes?.issue_count ?? '0', 10); if (entity?.state === 'ok') return 'HEALTHY'; - return `${Number.isFinite(count) ? count : '?'} ${String(entity?.state ?? 'unknown').toUpperCase()}`; + const errors = Number.parseInt(entity?.attributes?.error_count ?? '0', 10); + const warnings = Number.parseInt(entity?.attributes?.warning_count ?? '0', 10); + const parts = []; + if (Number.isFinite(errors) && errors > 0) parts.push(`${errors} ERROR${errors === 1 ? '' : 'S'}`); + if (Number.isFinite(warnings) && warnings > 0) parts.push(`${warnings} WARN`); + return parts.join(' ยท ') || 'STATUS UNKNOWN'; ]]] - type: custom:button-card diff --git a/config/dashboards/infrastructure/templates/button_card_templates.yaml b/config/dashboards/infrastructure/templates/button_card_templates.yaml index 55f0561f..19cbe5ca 100644 --- a/config/dashboards/infrastructure/templates/button_card_templates.yaml +++ b/config/dashboards/infrastructure/templates/button_card_templates.yaml @@ -784,6 +784,10 @@ bearstone_infra_alert_row: const okState = String(variables?.ok_state ?? '').toLowerCase(); show = stateStr.toLowerCase() !== okState; } + else if (kind === 'state_is') { + const alertState = String(variables?.alert_state ?? '').toLowerCase(); + show = Boolean(alertState) && stateStr.toLowerCase() === alertState; + } else if (kind === 'ap_zero') show = (stateStr === '0' && ageS >= minAge); else if (kind === 'disk_high' || kind === 'numeric_high') { const v = parseFloat(stateStr); diff --git a/config/packages/infrastructure.yaml b/config/packages/infrastructure.yaml index 2718a6ef..1a761a56 100644 --- a/config/packages/infrastructure.yaml +++ b/config/packages/infrastructure.yaml @@ -243,7 +243,7 @@ template: 'binary_sensor.kiosk_devices_need_attention' ] %} {% set category_count = expand(categories) | selectattr('state', 'eq', 'on') | list | count %} - {% set bearclaw_issue = states('sensor.bearclaw_scheduled_job_health') in ['warning', 'error'] %} + {% set bearclaw_issue = is_state('sensor.bearclaw_scheduled_job_health', 'error') %} {{ category_count + (1 if bearclaw_issue else 0) }} attributes: active_entities: >- @@ -257,7 +257,7 @@ template: 'binary_sensor.kiosk_devices_need_attention' ] %} {% set active = expand(categories) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list %} - {% if states('sensor.bearclaw_scheduled_job_health') in ['warning', 'error'] %} + {% if is_state('sensor.bearclaw_scheduled_job_health', 'error') %} {% set active = active + ['sensor.bearclaw_scheduled_job_health'] %} {% endif %} {{ active }}