Update notification service

This commit is contained in:
MacRimi
2026-02-24 17:55:03 +01:00
parent 507f769357
commit 4182af75ff
4 changed files with 131 additions and 228 deletions

View File

@@ -232,7 +232,7 @@ def _pve_remove_our_blocks(text, headers_to_remove):
def _build_webhook_fallback():
"""Build fallback manual commands for webhook setup."""
import base64
body_tpl = '{"title":"{{ title }}","message":"{{ message }}","severity":"{{ severity }}","timestamp":"{{ timestamp }}"}'
body_tpl = '{"title":"{{ escape title }}","message":"{{ escape message }}","severity":"{{ severity }}","timestamp":"{{ timestamp }}","fields":{{ json fields }}}'
body_b64 = base64.b64encode(body_tpl.encode()).decode()
return [
"# 1. Append to END of /etc/pve/notifications.cfg",
@@ -310,15 +310,13 @@ def setup_pve_webhook_core() -> dict:
# PVE secret format is: secret name=key,value=<base64>
# Neither is needed for localhost calls.
# PVE stores body as base64 in the config file. We encode it here
# so the config parser reads it correctly.
# Only use fields that ALWAYS exist: title, message, severity, timestamp.
# "type" and "hostname" are inside "fields" (not top-level) and
# {{ escape X }} fails hard on undefined fields, breaking the
# entire notification delivery for ALL targets.
# Our _classify() extracts type/hostname from the message content.
# PVE stores body as base64 in the config file.
# {{ escape title/message }} -- JSON-safe escaping of quotes/newlines.
# {{ json fields }} -- renders ALL PVE metadata as a JSON object
# (type, hostname, job-id). This is a single Handlebars helper
# that always works, even if fields is empty (renders {}).
import base64
body_template = '{"title":"{{ title }}","message":"{{ message }}","severity":"{{ severity }}","timestamp":"{{ timestamp }}"}'
body_template = '{"title":"{{ escape title }}","message":"{{ escape message }}","severity":"{{ severity }}","timestamp":"{{ timestamp }}","fields":{{ json fields }}}'
body_b64 = base64.b64encode(body_template.encode()).decode()
endpoint_block = (