]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/monitoring/plugins/notify_by_email
Add monitoring modules via naemon
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / notify_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 HOST_ALIAS="$3"
16 DATE="$4"
17 CONTACT="$5"
18
19 message=""
20
21 if [ "$1" = "host" ]; then
22 message=$(printf "%b" "***** Naemon *****\n\nNotification Type: $NOTIFICATION_TYPE\n\nHost: $HOST_ALIAS\nState: $HOSTSTATE\nInfo: $HOSTOUTPUT\n\nDate/Time: $DATE\n")
23 subject="** $NOTIFICATION_TYPE Host Alert: $HOST_ALIAS is $HOSTSTATE **"
24 else
25 message=$(printf "%b" "***** Naemon *****\n\nNotification Type: $NOTIFICATION_TYPE\n\nService: $SERVICEDESC\nHost: $HOST_ALIAS\nState: $SERVICESTATE\n\nDate/Time: $DATE\n\nAdditional Info:\n\n$SERVICEOUTPUT\n")
26 subject="** $NOTIFICATION_TYPE Service Alert: $HOST_ALIAS/$SERVICEDESC is $SERVICESTATE **"
27 fi
28
29 # sendwait waits for sendmail to finish its job, otherwise it continues in the
30 # background and gets killed too early
31 echo "$message" | MAILRC=/dev/null mail -r "naemon@immae.eu" -n -Ssendwait -s "$subject" "$CONTACT"