]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/monitoring/plugins/notify_maison_bbc_by_email
Add monitoring host
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / notify_maison_bbc_by_email
1 #!/usr/bin/env bash
2
3 # $1 = service/host
4
5 # $2 = type (PROBLEM RECOVERY ACKNOWLEDGEMENT FLAPPINGSTART FLAPPINGSTOP FLAPPINGDISABLED DOWNTIMESTART DOWNTIMESTOP DOWNTIMECANCELLED)
6 # http://www.naemon.org/documentation/usersguide/macrolist.html#notificationtype
7
8 # $3 = host alias
9
10 # $4 = date (YYYY-MM-DDTHH:MM:SS)
11
12 # $5 = E-mail
13
14 NOTIFICATION_TYPE="$2"
15 DATE="$4"
16 CONTACT="$5"
17
18 output=$(echo "$SERVICEOUTPUT" | awk '{gsub(" - ", "\n\n", $0); gsub (" (;|:) ", "\n ", $0); gsub(" dates: ", " dates:\n ", $0); gsub("Batteries: ", "Batteries:\n ", $0); print $0}')
19 if [ "$NOTIFICATION_TYPE" = "RECOVERY" ]; then
20 subject="Fin d'alerte Maison BBC Zibase"
21 message=$(printf "%b" "Alerte terminée le $DATE.\nInformations:\n$output")
22 else
23 subject="Alerte Maison BBC Zibase"
24 message=$(printf "%b" "Alerte lancée le $DATE.\nInformations:\n$output")
25 fi
26
27 echo "$message" | MAILRC=/dev/null mail -r "$ADMINEMAIL" -n -s "$subject" "$CONTACT"