Files
buryan-infra/ops/integration/kuma_notify.py
buryan-agent 5de4697549 Matrix восстановлен, Kuma и HA научились уведомлять в Matrix
Synapse падал в цикле: /opt/matrix/data принадлежал root вместо 991 и
контейнер пересоздался без сети matrix_matrix-net. Исправлено chown,
security-opt и подключением к сети; Matrix 200, боты работают.
Telegram-мост ожил после подключения к той же сети.

Добавлен POST/GET /notify в hub-core: шлёт сообщение в Matrix владельцу через
MEDIA-бота. Kuma получила webhook-уведомление с шаблоном
[{{STATUS}}] {{NAME}} и привязку ко всем мониторам. В HA добавлен
rest_command.hub_notify — проверено 200.

Написана карта связей между сервисами (ops/integration/LINKS.md): что связано,
что нет и какие решения ещё не задействованы (n8n, mautrix-мосты, Bazarr,
Vaultwarden, Zigbee2MQTT, Alertmanager, Paperless intake, Immich upload).
2026-10-20 20:38:08 +03:00

44 lines
1.6 KiB
Python

"""Настраивает Kuma: уведомления в Matrix через hub-core."""
import json
import subprocess
CT = "107"
DB = "/opt/network-lxc/uptime/data/kuma.db"
cfg = {
"type": "webhook",
"webhookURL": "http://192.168.1.10:9120/notify",
"webhookContentType": "json",
"webhookJSONBody": '{"title": "{{ name }}: {{ status }}", "message": "{{ msg }}"}',
"webhookAdditionalHeaders": "",
}
body = json.dumps(cfg, ensure_ascii=False)
def sh(c, timeout=60):
r = subprocess.run(["pct", "exec", CT, "--", "bash", "-c", c],
capture_output=True, text=True, timeout=timeout)
return (r.stdout or r.stderr or "").strip()
sql = f"""
insert into notification (name, active, user_id, is_default, config)
values ('Matrix (hub)', 1, 1, 0, '{body.replace("'", "''")}');
insert into monitor_notification (id, monitor_id, notification_id)
select (select coalesce(max(id),0) from monitor_notification) + row_number() over (),
m.id, (select id from notification where name='Matrix (hub)')
from monitor m
where not exists (
select 1 from monitor_notification mn
where mn.monitor_id = m.id
and mn.notification_id = (select id from notification where name='Matrix (hub)')
);
"""
open("/tmp/kuma_notify.sql", "w").write(sql)
subprocess.run(["pct", "push", CT, "/tmp/kuma_notify.sql", "/tmp/kuma_notify.sql", "--perms", "600"],
capture_output=True, text=True)
print("insert:", sh(f"sqlite3 {DB} < /tmp/kuma_notify.sql"))
print("уведомления:", sh(f"sqlite3 {DB} 'select id,name,active from notification;'"))
print("связок:", sh(f"sqlite3 {DB} 'select count(*) from monitor_notification;'"))