35 lines
1.6 KiB
Text
35 lines
1.6 KiB
Text
|
|
#!/bin/bash
|
||
|
|
# GENERE par Set-OPS (role serveur_artefacts). Ne pas editer a la main.
|
||
|
|
#
|
||
|
|
# SONDE « cache-apt » — le cache apt repond, et il lui reste de la place
|
||
|
|
#
|
||
|
|
# Contrat : docs/supervision-conception.md (API des greffons Nagios) — une ligne sur la
|
||
|
|
# sortie standard, 0 OK / 1 AVERTISSEMENT / 2 CRITIQUE. Le porteur `client_sante` pousse.
|
||
|
|
# Mise en defaut PAR PARAMETRE : `serveur_artefacts_sonde_port` (port ferme) ou `_pct_crit` (seuil impossible).
|
||
|
|
set -uo pipefail
|
||
|
|
|
||
|
|
PORT={{ serveur_artefacts_sonde_port }}
|
||
|
|
REP={{ serveur_artefacts_sonde_repertoire }}
|
||
|
|
AVERT={{ serveur_artefacts_sonde_pct_avert }}
|
||
|
|
CRIT={{ serveur_artefacts_sonde_pct_crit }}
|
||
|
|
|
||
|
|
# ON DEMANDE UNE PAGE, ON NE SE CONTENTE PAS D'UN connect(). Un `connect()` reussit contre
|
||
|
|
# un processus mort-vivant qui n'a plus rien a servir ; seule une reponse prouve le
|
||
|
|
# service. C'est la lecon du depot : « un connect() TCP ne prouve rien ».
|
||
|
|
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 8 "http://127.0.0.1:${PORT}/acng-report.html" 2>/dev/null)
|
||
|
|
[[ "${code}" == "200" ]] || { echo "Le cache ne repond pas sur ${PORT} (HTTP ${code:-aucune reponse})."; exit 2; }
|
||
|
|
|
||
|
|
pct=$(df --output=pcent "${REP}" 2>/dev/null | tail -1 | tr -dc '0-9')
|
||
|
|
[[ -n "${pct}" ]] || { echo "Cache joignable, mais ${REP} illisible."; exit 1; }
|
||
|
|
taille=$(du -sh "${REP}" 2>/dev/null | cut -f1)
|
||
|
|
|
||
|
|
if (( pct >= CRIT )); then
|
||
|
|
echo "Cache a ${pct}% du volume (${taille}) — apt echouera bientot pour tout l'ecosysteme."
|
||
|
|
exit 2
|
||
|
|
fi
|
||
|
|
if (( pct >= AVERT )); then
|
||
|
|
echo "Cache a ${pct}% du volume (${taille}), seuil ${AVERT}%."
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
echo "Cache apt : repond sur ${PORT}, ${taille} sur un volume a ${pct}%.|pct=${pct}%;${AVERT};${CRIT};0;100"
|