aboutsummaryrefslogblamecommitdiff
path: root/modules/private/monitoring/plugins/notify_by_email
blob: ad0dcc7e5954a1b99a3ad9bfe8bcb5c1f5bde476 (plain) (tree)






























                                                                                                                                                                                                                    
#!/usr/bin/env bash

# $1 = service/host

# $2 = type (PROBLEM RECOVERY ACKNOWLEDGEMENT FLAPPINGSTART FLAPPINGSTOP FLAPPINGDISABLED DOWNTIMESTART DOWNTIMESTOP DOWNTIMECANCELLED)
# http://www.naemon.org/documentation/usersguide/macrolist.html#notificationtype

# $3 = host alias

# $4 = date (YYYY-MM-DDTHH:MM:SS)

# $5 = E-mail

NOTIFICATION_TYPE="$2"
HOST_ALIAS="$3"
DATE="$4"
CONTACT="$5"

message=""

if [ "$1" = "host" ]; then
  message=$(printf "%b" "***** Naemon *****\n\nNotification Type: $NOTIFICATION_TYPE\n\nHost: $HOST_ALIAS\nState: $HOSTSTATE\nInfo: $HOSTOUTPUT\n\nDate/Time: $DATE\n")
  subject="** $NOTIFICATION_TYPE Host Alert: $HOST_ALIAS is $HOSTSTATE **"
else
  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")
  subject="** $NOTIFICATION_TYPE Service Alert: $HOST_ALIAS/$SERVICEDESC is $SERVICESTATE **"
fi

# sendwait waits for sendmail to finish its job, otherwise it continues in the
# background and gets killed too early
echo "$message" | MAILRC=/dev/null mail -r "naemon@immae.eu" -n -Ssendwait -s "$subject" "$CONTACT"