diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-07-17 11:33:57 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-07-17 11:33:57 +0200 |
commit | 3bc32d9ebd9b0900eeef756122ad28f8857f8bfe (patch) | |
tree | ff92459e654fde6fe559dfd383d6a76e05a347cf /modules/private/monitoring/plugins/notify_by_email | |
parent | e886ea19877fa0d4de32d35939f69e9c18681d59 (diff) | |
download | Nix-3bc32d9ebd9b0900eeef756122ad28f8857f8bfe.tar.gz Nix-3bc32d9ebd9b0900eeef756122ad28f8857f8bfe.tar.zst Nix-3bc32d9ebd9b0900eeef756122ad28f8857f8bfe.zip |
Add monitoring modules via naemon
Diffstat (limited to 'modules/private/monitoring/plugins/notify_by_email')
-rwxr-xr-x | modules/private/monitoring/plugins/notify_by_email | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/notify_by_email b/modules/private/monitoring/plugins/notify_by_email new file mode 100755 index 0000000..ad0dcc7 --- /dev/null +++ b/modules/private/monitoring/plugins/notify_by_email | |||
@@ -0,0 +1,31 @@ | |||
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" | ||