SPB Git

Repository Public

maclustr-identity-watch.sh 3.7 KB 75 lines shellscript

1#!/bin/zsh2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : MacLustr Identity8# File             : infrastructure/gateway/maclustr-identity-watch.sh9# Module           : infrastructure10# Repository       : https://git.spboucher.ai/maclustr-identity11# Project Website  : https://identity.spboucher.ai12# Created          : 2026-12-0113# Last Modified    : 2026-12-0114#15# Author           : Simon-Pierre Boucher16# Position         : Professor of Finance17# Institution      : Université du Québec en Outaouais (UQO)18# Organization     : SP Boucher19# Website          : https://spboucher.ai20# Git              : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin   : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License          : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# MacLustr Identity : sonde EXTERNE, lancée toutes les 5 minutes par la passerelle M1M32 (LaunchDaemon io.maclustr.maclustr-identity-watch).42# La surveillance interne (maclustr-identity-monitor) tourne sur le nœud qu'elle surveille : s'il tombe, elle se tait. Cette sonde43# interroge l'adresse publique et alerte par courriel (SP Mail) à l'apparition d'une panne, à son rétablissement, puis toutes les 6 heures.44set -uo pipefail45export PATH=/usr/bin:/bin:/usr/sbin:/sbin46URL=https://identity.spboucher.ai/health/ready47KEY=$HOME/dispatch/.maclustr-identity-alerts.key48STATE=$HOME/dispatch/logs/maclustr-identity-watch.state49now=$(date +%s)50ok=051for i in 1 2 3; do52  body=$(curl -fsS -m 12 "$URL" 2>/dev/null) && [[ "$body" == *'"status":"ready"'* ]] && { ok=1; break; }53  sleep 1054done55prev=""; since=$now; sent=056[ -f "$STATE" ] && read prev since sent < "$STATE"57send() {58  curl -sS -m 20 -o /dev/null -X POST https://mail.spboucher.ai/api/v1/messages/send -H "Authorization: Bearer $(cat $KEY)" -H 'Content-Type: application/json' \59    -H "Idempotency-Key: mlid-watch-$1-$(date -u +%Y%m%d%H)" \60    -d "{\"from\":\"alerts@spboucher.ai\",\"to\":[\"simon@spboucher.ai\"],\"subject\":\"$2\",\"text\":\"$3\",\"priority\":\"high\"}"61}62if [ $ok -eq 1 ]; then63  [ "$prev" = "down" ] && send up "[MacLustr Identity] service rétabli" "identity.spboucher.ai répond de nouveau (sonde externe M1M32). Panne constatée pendant $(( (now - since) / 60 )) min."64  echo "up $now 0" > "$STATE"65else66  if [ "$prev" != "down" ]; then67    send down "[MacLustr Identity] service injoignable" "identity.spboucher.ai ne répond pas à la sonde externe (M1M32), après 3 essais. Vérifier le nœud M2M32c (mld status --live), la passerelle BHS64 et la route. Voir docs/INCIDENT_RESPONSE.md."68    echo "down $now $now" > "$STATE"69  elif [ $(( now - sent )) -gt 21600 ]; then70    send down "[MacLustr Identity] service toujours injoignable" "identity.spboucher.ai ne répond pas depuis $(( (now - since) / 60 )) min (sonde externe M1M32)."71    echo "down $since $now" > "$STATE"72  fi73  print -r -- "$(date "+%Y-%m-%dT%H:%M:%S") injoignable"74fi75
Files main
Menu

Theme