|
| 1 | +###################################################################### |
| 2 | +# @CCOSTAN - Follow Me on X |
| 3 | +# For more info visit https://www.vcloudinfo.com/click-here |
| 4 | +# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig |
| 5 | +# ------------------------------------------------------------------- |
| 6 | +# OneNote Indexer Monitoring - Status and health sensors for Joanna |
| 7 | +# Polls codex_appliance OneNote status and exposes trigger-ready health entities. |
| 8 | +# ------------------------------------------------------------------- |
| 9 | +# Notes: Keep onenote indexer monitoring in this package (separate from bearclaw transport). |
| 10 | +# Notes: last_status='never' is treated as success to avoid false alerts after restarts. |
| 11 | +# Notes: Creates/clears a Spook Repair issue and requests Joanna remediation on failures. |
| 12 | +###################################################################### |
| 13 | + |
| 14 | +sensor: |
| 15 | + - platform: rest |
| 16 | + name: OneNote Indexer Status Payload |
| 17 | + unique_id: onenote_indexer_status_payload |
| 18 | + resource: !secret bearclaw_onenote_status_url |
| 19 | + method: GET |
| 20 | + headers: |
| 21 | + x-codex-token: !secret bearclaw_token |
| 22 | + scan_interval: 300 |
| 23 | + timeout: 20 |
| 24 | + value_template: >- |
| 25 | + {% if value_json is mapping %} |
| 26 | + {{ value_json.server_time | default(now().isoformat()) }} |
| 27 | + {% else %} |
| 28 | + unknown |
| 29 | + {% endif %} |
| 30 | + json_attributes: |
| 31 | + - ok |
| 32 | + - indexer |
| 33 | + - embeddingWorker |
| 34 | + |
| 35 | +template: |
| 36 | + - sensor: |
| 37 | + - name: OneNote Indexer Last Job Status |
| 38 | + unique_id: onenote_indexer_last_job_status |
| 39 | + icon: mdi:notebook-check |
| 40 | + state: >- |
| 41 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 42 | + {% set sync = payload.get('sync', {}) if payload is mapping else {} %} |
| 43 | + {% set raw = (sync.get('last_status', '') | string | lower) %} |
| 44 | + {% if raw in ['ok', 'success', 'never'] %} |
| 45 | + success |
| 46 | + {% elif raw == 'running' %} |
| 47 | + running |
| 48 | + {% elif raw == 'error' %} |
| 49 | + error |
| 50 | + {% else %} |
| 51 | + unknown |
| 52 | + {% endif %} |
| 53 | + attributes: |
| 54 | + running: >- |
| 55 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 56 | + {% set sync = payload.get('sync', {}) if payload is mapping else {} %} |
| 57 | + {{ sync.get('running', false) | bool }} |
| 58 | + last_run_id: >- |
| 59 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 60 | + {% set sync = payload.get('sync', {}) if payload is mapping else {} %} |
| 61 | + {{ sync.get('last_run_id') }} |
| 62 | + last_started_at: >- |
| 63 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 64 | + {% set sync = payload.get('sync', {}) if payload is mapping else {} %} |
| 65 | + {{ sync.get('last_started_at') }} |
| 66 | + last_finished_at: >- |
| 67 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 68 | + {% set sync = payload.get('sync', {}) if payload is mapping else {} %} |
| 69 | + {{ sync.get('last_finished_at') }} |
| 70 | + last_error: >- |
| 71 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 72 | + {% set sync = payload.get('sync', {}) if payload is mapping else {} %} |
| 73 | + {{ sync.get('last_error') }} |
| 74 | + pending_embeddings: >- |
| 75 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 76 | + {% set index = payload.get('index', {}) if payload is mapping else {} %} |
| 77 | + {{ index.get('pending_embeddings') }} |
| 78 | + pages: >- |
| 79 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 80 | + {% set index = payload.get('index', {}) if payload is mapping else {} %} |
| 81 | + {{ index.get('pages') }} |
| 82 | + chunks: >- |
| 83 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 84 | + {% set index = payload.get('index', {}) if payload is mapping else {} %} |
| 85 | + {{ index.get('chunks') }} |
| 86 | + last_metrics: >- |
| 87 | + {% set payload = state_attr('sensor.onenote_indexer_status_payload', 'indexer') or {} %} |
| 88 | + {% set sync = payload.get('sync', {}) if payload is mapping else {} %} |
| 89 | + {{ sync.get('last_metrics', {}) }} |
| 90 | +
|
| 91 | + - binary_sensor: |
| 92 | + - name: OneNote Indexer Last Job Successful |
| 93 | + unique_id: onenote_indexer_last_job_successful |
| 94 | + state: >- |
| 95 | + {{ states('sensor.onenote_indexer_last_job_status') in ['success', 'running'] }} |
| 96 | + icon: >- |
| 97 | + {% if is_state('binary_sensor.onenote_indexer_last_job_successful', 'on') %} |
| 98 | + mdi:check-circle |
| 99 | + {% else %} |
| 100 | + mdi:alert-circle |
| 101 | + {% endif %} |
| 102 | +
|
| 103 | + - name: OneNote Indexer Job Failed |
| 104 | + unique_id: onenote_indexer_job_failed |
| 105 | + device_class: problem |
| 106 | + state: >- |
| 107 | + {{ not is_state('binary_sensor.onenote_indexer_last_job_successful', 'on') }} |
| 108 | +
|
| 109 | +automation: |
| 110 | + - id: onenote_indexer_failure_open_repair |
| 111 | + alias: OneNote Indexer - Open Repair On Failure |
| 112 | + description: Open a Spook Repair issue and ask Joanna to troubleshoot when indexer status is failed. |
| 113 | + mode: single |
| 114 | + trigger: |
| 115 | + - platform: state |
| 116 | + entity_id: binary_sensor.onenote_indexer_job_failed |
| 117 | + to: "on" |
| 118 | + for: "00:03:00" |
| 119 | + action: |
| 120 | + - variables: |
| 121 | + last_status: "{{ states('sensor.onenote_indexer_last_job_status') }}" |
| 122 | + run_id: "{{ state_attr('sensor.onenote_indexer_last_job_status', 'last_run_id') | default('n/a') }}" |
| 123 | + last_error: "{{ state_attr('sensor.onenote_indexer_last_job_status', 'last_error') | default('n/a') }}" |
| 124 | + last_metrics: "{{ state_attr('sensor.onenote_indexer_last_job_status', 'last_metrics') | default({}) }}" |
| 125 | + - service: repairs.create |
| 126 | + data: |
| 127 | + issue_id: "onenote_indexer_job_failed" |
| 128 | + title: "OneNote indexer job failed" |
| 129 | + severity: "warning" |
| 130 | + persistent: true |
| 131 | + description: >- |
| 132 | + Home Assistant detected OneNote indexer failure. |
| 133 | +
|
| 134 | + last_status: {{ last_status }} |
| 135 | + last_run_id: {{ run_id }} |
| 136 | + last_error: {{ last_error }} |
| 137 | + last_metrics: {{ last_metrics }} |
| 138 | + - service: script.send_to_logbook |
| 139 | + data: |
| 140 | + topic: "ONENOTE" |
| 141 | + message: >- |
| 142 | + OneNote indexer failed (run {{ run_id }}). Spook repair opened and Joanna remediation requested. |
| 143 | + - service: rest_command.bearclaw_command |
| 144 | + data: |
| 145 | + text: >- |
| 146 | + OneNote indexer containerhealth alert from Home Assistant. |
| 147 | + Please troubleshoot and resolve if possible. |
| 148 | + last_status={{ last_status }}, |
| 149 | + last_run_id={{ run_id }}, |
| 150 | + last_error={{ last_error }}, |
| 151 | + last_metrics={{ last_metrics }}. |
| 152 | + user: "carlo" |
| 153 | + source: "home_assistant_repair" |
| 154 | + |
| 155 | + - id: onenote_indexer_failure_clear_repair |
| 156 | + alias: OneNote Indexer - Clear Repair On Recovery |
| 157 | + description: Clear the Spook Repair issue when OneNote indexer is healthy again. |
| 158 | + mode: single |
| 159 | + trigger: |
| 160 | + - platform: state |
| 161 | + entity_id: binary_sensor.onenote_indexer_job_failed |
| 162 | + to: "off" |
| 163 | + for: "00:02:00" |
| 164 | + action: |
| 165 | + - service: repairs.remove |
| 166 | + continue_on_error: true |
| 167 | + data: |
| 168 | + issue_id: "onenote_indexer_job_failed" |
| 169 | + - service: script.send_to_logbook |
| 170 | + data: |
| 171 | + topic: "ONENOTE" |
| 172 | + message: "OneNote indexer recovered. Spook repair cleared." |
0 commit comments