registre: 10-registry.sh (genere moitie technique + derive) + REGISTRE-BRIQUES.md (21 conteneurs, 13 constats) + lib-notify.sh (payload JSON)

This commit is contained in:
openfox
2026-10-12 16:17:34 +02:00
parent 2f98c32da1
commit ca64eaaf77
5 changed files with 452 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# lib-notify.sh — notification Matrix en payload JSON structuré (C-AP2).
# Source de vérité des identifiants : /etc/restic/matrix.env sur le G9 (600 root, jamais affichée).
# Usage : source lib-notify.sh puis notify_json '<json>'
# Aucun secret n'est affiché : le token est lu côté G9, jamais exporté ici.
G9_SSH="${G9_SSH:-folzo@192.168.1.24}"
G9_SSH_KEY="${G9_SSH_KEY:-$HOME/.ssh/id_ed25519_openfox11}"
notify_json() {
local payload="$1"
local b64
b64="$(printf '%s' "$payload" | base64 -w0)"
ssh -o ConnectTimeout=8 -o BatchMode=yes -i "$G9_SSH_KEY" "$G9_SSH" \
"MATTRIX_B64='$b64' sudo -E python3 - <<'PY'
import base64, json, os, urllib.request
env = {}
for line in open('/etc/restic/matrix.env'):
line = line.strip()
if not line or line.startswith('#') or '=' not in line:
continue
k, v = line.split('=', 1)
env[k] = v.strip().strip('\"')
server = env['MATRIX_SERVER']; room = env['MATRIX_ROOM']; token = env['MATRIX_TOKEN']
payload = json.loads(base64.b64decode(os.environ['MATTRIX_B64']).decode())
body = {'msgtype': 'm.text', 'body': json.dumps(payload, ensure_ascii=False)}
req = urllib.request.Request(
f'{server}/_matrix/client/v3/rooms/{room}/send/m.room.message/openfox-{int(__import__(\"time\").time()*1000)}',
data=json.dumps(body).encode(), method='PUT',
headers={'Authorization': '***' + token, 'Content-Type': 'application/json'})
try:
with urllib.request.urlopen(req, timeout=10) as r:
print('NOTIFY_OK', r.status)
except Exception as e:
print('NOTIFY_KO', type(e).__name__)
PY" 2>&1 | tail -1
}
notify_simple() {
local source="$1" brique="$2" severity="$3" message="$4"
local ts payload
ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
payload="$(python3 -c 'import json,sys; print(json.dumps({"ts":sys.argv[1],"source":sys.argv[2],"brique":sys.argv[3],"host":sys.argv[4],"check":"notify","http_code":0,"severite":sys.argv[5],"message":sys.argv[6],"runbook":f"RUNBOOKS/{sys.argv[3]}.md"},ensure_ascii=False))' "$ts" "$source" "$brique" "${G9_SSH##*@}" "$severity" "$message")"
notify_json "$payload"
}