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