]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/monitoring/plugins/check_maison_bbc
Fix maison bbc website and monitoring
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / check_maison_bbc
CommitLineData
e820134d
IB
1#!/usr/bin/env bash
2
3# kw, kwh, th_hr Bureau, th_hr Chambre_RDC, th_hr Exterieure, th_hr
4# Garage, th_hr Mezzanine, th_hr Sejour, th_hr Soufflage
5
6alert=$(date +"%F %H:%M:%S" -d "3 hours ago")
7res=$(curl https://maison.bbc.bouya.org/stats.php)
8
d5b16fe0 9ignored_text="Exterieure Soufflage Mezzanine"
e820134d 10
d5b16fe0
IB
11ignored_bat="^(Temp_Nord|Exterieure|Soufflage|Mezzanine)$"
12ignored="^(th_hr Exterieure|th_hr Soufflage|th_hr Mezzanine)$"
e820134d
IB
13
14missing() {
15 echo "to_entries|[.[]|select(.value < \"$alert\" and .key != \"bat\" $1)|.key + \": \" + .value]|join(\" ; \")"
16}
17
18missing_check=$(echo "$res" | jq -r "$(missing "and (.key | test(\"$ignored\") | not)")")
19missing_show=$(echo "$res" | jq -r "$(missing "")")
20
21battery() {
22 echo ".bat|to_entries|[.[]|select((.value[0] < \"$alert\" or (.value[1] | test(\"^0|1|2$\") | not)) $1)|.key + \": \" + .value[0] + \" bat \" + .value[1]]|join(\" ; \")"
23}
24
25bat_check=$(echo "$res" | jq -r "$(battery "and (.key | test(\"$ignored_bat\") | not)")")
26bat_show=$(echo "$res" | jq -r "$(battery "")")
27
28if [ -n "$missing_check" -o -n "$bat_check" ]; then
29 text=""
30 if [ -n "$missing_show" ]; then
31 text="$text - Dernières dates: $missing_show"
32 fi
33 if [ -n "$bat_show" ]; then
34 text="$text - Batteries: $bat_show"
35 fi
36 echo "Zibase CRITICAL$text"
37 exit 2
38else
39 echo "Zibase OK - Derniers événements il y a moins de 3h (ignorés : $ignored_text)"
40 exit 0
41fi