mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
Merge pull request #5170 from sysadmama/notification-scripts
Enhance mail notifications scripts and add support for command line parameters
This commit is contained in:
commit
ebdbca0730
@ -3,36 +3,124 @@
|
|||||||
object NotificationCommand "mail-host-notification" {
|
object NotificationCommand "mail-host-notification" {
|
||||||
command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
|
command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
|
||||||
|
|
||||||
env = {
|
arguments += {
|
||||||
NOTIFICATIONTYPE = "$notification.type$"
|
"-4" = {
|
||||||
HOSTALIAS = "$host.display_name$"
|
required = true
|
||||||
HOSTADDRESS = "$address$"
|
value = "$notification_address$"
|
||||||
HOSTSTATE = "$host.state$"
|
}
|
||||||
LONGDATETIME = "$icinga.long_date_time$"
|
"-6" = "$notification_address6$"
|
||||||
HOSTOUTPUT = "$host.output$"
|
"-b" = "$notification_author$"
|
||||||
NOTIFICATIONAUTHORNAME = "$notification.author$"
|
"-c" = "$notification_comment$"
|
||||||
NOTIFICATIONCOMMENT = "$notification.comment$"
|
"-d" = {
|
||||||
HOSTDISPLAYNAME = "$host.display_name$"
|
required = true
|
||||||
USEREMAIL = "$user.email$"
|
value = "$notification_date$"
|
||||||
|
}
|
||||||
|
"-f" = "$notification_from$"
|
||||||
|
"-i" = "$notification_icingaweb2url$"
|
||||||
|
"-l" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_hostname$"
|
||||||
|
}
|
||||||
|
"-n" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_hostdisplayname$"
|
||||||
|
}
|
||||||
|
"-o" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_hostoutput$"
|
||||||
|
}
|
||||||
|
"-r" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_useremail$"
|
||||||
|
}
|
||||||
|
"-s" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_hoststate$"
|
||||||
|
}
|
||||||
|
"-t" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_type$"
|
||||||
|
}
|
||||||
|
"-v" = "$notification_logtosyslog$"
|
||||||
|
}
|
||||||
|
|
||||||
|
vars += {
|
||||||
|
notification_address = "$address$"
|
||||||
|
notification_address6 = "$address6$"
|
||||||
|
notification_author = "$notification.author$"
|
||||||
|
notification_comment = "$notification.comment$"
|
||||||
|
notification_type = "$notification.type$"
|
||||||
|
notification_date = "$icinga.long_date_time$"
|
||||||
|
notification_hostname = "$host.name$"
|
||||||
|
notification_hostdisplayname = "$host.display_name$"
|
||||||
|
notification_hostoutput = "$host.output$"
|
||||||
|
notification_hoststate = "$host.state$"
|
||||||
|
notification_useremail = "$user.email$"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object NotificationCommand "mail-service-notification" {
|
object NotificationCommand "mail-service-notification" {
|
||||||
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
|
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
|
||||||
|
|
||||||
env = {
|
arguments += {
|
||||||
NOTIFICATIONTYPE = "$notification.type$"
|
"-4" = {
|
||||||
SERVICEDESC = "$service.name$"
|
required = true
|
||||||
HOSTALIAS = "$host.display_name$"
|
value = "$notification_address$"
|
||||||
HOSTADDRESS = "$address$"
|
|
||||||
SERVICESTATE = "$service.state$"
|
|
||||||
LONGDATETIME = "$icinga.long_date_time$"
|
|
||||||
SERVICEOUTPUT = "$service.output$"
|
|
||||||
NOTIFICATIONAUTHORNAME = "$notification.author$"
|
|
||||||
NOTIFICATIONCOMMENT = "$notification.comment$"
|
|
||||||
HOSTDISPLAYNAME = "$host.display_name$"
|
|
||||||
SERVICEDISPLAYNAME = "$service.display_name$"
|
|
||||||
USEREMAIL = "$user.email$"
|
|
||||||
}
|
}
|
||||||
|
"-6" = "$notification_address6$"
|
||||||
|
"-b" = "$notification_author$"
|
||||||
|
"-c" = "$notification_comment$"
|
||||||
|
"-d" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_date$"
|
||||||
|
}
|
||||||
|
"-e" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_servicename$"
|
||||||
|
}
|
||||||
|
"-f" = "$notification_from$"
|
||||||
|
"-i" = "$notification_icingaweb2url$"
|
||||||
|
"-l" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_hostname$"
|
||||||
|
}
|
||||||
|
"-n" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_hostdisplayname$"
|
||||||
|
}
|
||||||
|
"-o" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_serviceoutput$"
|
||||||
|
}
|
||||||
|
"-r" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_useremail$"
|
||||||
|
}
|
||||||
|
"-s" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_servicestate$"
|
||||||
|
}
|
||||||
|
"-t" = "$notification_type$"
|
||||||
|
"-u" = {
|
||||||
|
required = true
|
||||||
|
value = "$notification_servicedisplayname$"
|
||||||
|
}
|
||||||
|
"-v" = "$notification_logtosyslog$"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vars += {
|
||||||
|
notification_address = "$address$"
|
||||||
|
notification_address6 = "$address6$"
|
||||||
|
notification_author = "$notification.author$"
|
||||||
|
notification_comment = "$notification.comment$"
|
||||||
|
notification_type = "$notification.type$"
|
||||||
|
notification_date = "$icinga.long_date_time$"
|
||||||
|
notification_hostname = "$host.name$"
|
||||||
|
notification_hostdisplayname = "$host.display_name$"
|
||||||
|
notification_servicename = "$service.name$"
|
||||||
|
notification_serviceoutput = "$service.output$"
|
||||||
|
notification_servicestate = "$service.state$"
|
||||||
|
notification_useremail = "$user.email$"
|
||||||
|
notification_servicedisplayname = "$service.display_name$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,18 +10,24 @@
|
|||||||
|
|
||||||
apply Notification "mail-icingaadmin" to Host {
|
apply Notification "mail-icingaadmin" to Host {
|
||||||
import "mail-host-notification"
|
import "mail-host-notification"
|
||||||
|
|
||||||
user_groups = host.vars.notification.mail.groups
|
user_groups = host.vars.notification.mail.groups
|
||||||
users = host.vars.notification.mail.users
|
users = host.vars.notification.mail.users
|
||||||
|
|
||||||
|
//interval = 2h
|
||||||
|
|
||||||
|
vars.notification_logtosyslog = true
|
||||||
|
|
||||||
assign where host.vars.notification.mail
|
assign where host.vars.notification.mail
|
||||||
}
|
}
|
||||||
|
|
||||||
apply Notification "mail-icingaadmin" to Service {
|
apply Notification "mail-icingaadmin" to Service {
|
||||||
import "mail-service-notification"
|
import "mail-service-notification"
|
||||||
|
|
||||||
user_groups = host.vars.notification.mail.groups
|
user_groups = host.vars.notification.mail.groups
|
||||||
users = host.vars.notification.mail.users
|
users = host.vars.notification.mail.users
|
||||||
|
|
||||||
|
//interval = 2h
|
||||||
|
|
||||||
|
vars.notification_logtosyslog = true
|
||||||
|
|
||||||
assign where host.vars.notification.mail
|
assign where host.vars.notification.mail
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,12 @@ template Notification "mail-host-notification" {
|
|||||||
FlappingStart, FlappingEnd,
|
FlappingStart, FlappingEnd,
|
||||||
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
|
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
|
||||||
|
|
||||||
|
vars += {
|
||||||
|
// notification_icingaweb2url = "https://www.example.com/icingaweb2"
|
||||||
|
// notification_from = "Icinga 2 Host Monitoring <icinga@example.com>"
|
||||||
|
notification_logtosyslog = false
|
||||||
|
}
|
||||||
|
|
||||||
period = "24x7"
|
period = "24x7"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +73,11 @@ template Notification "mail-service-notification" {
|
|||||||
FlappingStart, FlappingEnd,
|
FlappingStart, FlappingEnd,
|
||||||
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
|
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
|
||||||
|
|
||||||
period = "24x7"
|
vars += {
|
||||||
|
// notification_icingaweb2url = "https://www.example.com/icingaweb2"
|
||||||
|
// notification_from = "Icinga 2 Service Monitoring <icinga@example.com>"
|
||||||
|
notification_logtosyslog = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
period = "24x7"
|
||||||
|
}
|
||||||
|
@ -1,20 +1,141 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
template=`cat <<TEMPLATE
|
|
||||||
***** Icinga *****
|
|
||||||
|
|
||||||
Notification Type: $NOTIFICATIONTYPE
|
PROG="`basename $0`"
|
||||||
|
HOSTNAME="`hostname`"
|
||||||
|
MAILBIN="mail"
|
||||||
|
|
||||||
Host: $HOSTALIAS
|
if [ -z "`which $MAILBIN`" ] ; then
|
||||||
Address: $HOSTADDRESS
|
echo "$MAILBIN not found in \$PATH. Consider installing it."
|
||||||
State: $HOSTSTATE
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
Date/Time: $LONGDATETIME
|
## Function helpers
|
||||||
|
Usage() {
|
||||||
|
cat << EOF
|
||||||
|
|
||||||
Additional Info: $HOSTOUTPUT
|
Required parameters:
|
||||||
|
-4 HOSTADDRESS (\$address\$)
|
||||||
|
-d LONGDATETIME (\$icinga.long_date_time\$)
|
||||||
|
-l HOSTNAME (\$host.name\$)
|
||||||
|
-n HOSTDISPLAYNAME (\$host.display_name\$)
|
||||||
|
-o HOSTOUTPUT (\$host.output\$)
|
||||||
|
-r USEREMAIL (\$user.email\$)
|
||||||
|
-s HOSTSTATE (\$host.state\$)
|
||||||
|
-t NOTIFICATIONTYPE (\$notification.type\$)
|
||||||
|
|
||||||
Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
|
Optional parameters:
|
||||||
TEMPLATE
|
-6 HOSTADDRESS6 (\$address6\$)
|
||||||
|
-b NOTIFICATIONAUTHORNAME (\$notification.author\$)
|
||||||
|
-c NOTIFICATIONCOMMENT (\$notification.comment\$)
|
||||||
|
-i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset)
|
||||||
|
-f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils)
|
||||||
|
-v (\$notification_sendtosyslog\$, Default: false)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
Help() {
|
||||||
|
Usage;
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error() {
|
||||||
|
if [ "$1" ]; then
|
||||||
|
echo $1
|
||||||
|
fi
|
||||||
|
Usage;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
## Main
|
||||||
|
while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt
|
||||||
|
do
|
||||||
|
case "$opt" in
|
||||||
|
4) HOSTADDRESS=$OPTARG ;; # required
|
||||||
|
6) HOSTADDRESS6=$OPTARG ;;
|
||||||
|
b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
|
||||||
|
c) NOTIFICATIONCOMMENT=$OPTARG ;;
|
||||||
|
d) LONGDATETIME=$OPTARG ;; # required
|
||||||
|
f) MAILFROM=$OPTARG ;;
|
||||||
|
h) Help ;;
|
||||||
|
i) ICINGAWEB2URL=$OPTARG ;;
|
||||||
|
l) HOSTNAME=$OPTARG ;; # required
|
||||||
|
n) HOSTDISPLAYNAME=$OPTARG ;; # required
|
||||||
|
o) HOSTOUTPUT=$OPTARG ;; # required
|
||||||
|
r) USEREMAIL=$OPTARG ;; # required
|
||||||
|
s) HOSTSTATE=$OPTARG ;; # required
|
||||||
|
t) NOTIFICATIONTYPE=$OPTARG ;; # required
|
||||||
|
v) VERBOSE=$OPTARG ;;
|
||||||
|
\?) echo "ERROR: Invalid option -$OPTARG" >&2
|
||||||
|
Error ;;
|
||||||
|
:) echo "Missing option argument for -$OPTARG" >&2
|
||||||
|
Error ;;
|
||||||
|
*) echo "Unimplemented option: -$OPTARG" >&2
|
||||||
|
Error ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
## Check required parameters (TODO: better error message)
|
||||||
|
## Keep formatting in sync with mail-service-notification.sh
|
||||||
|
if [ ! "$HOSTADDRESS" ] || [ ! "$LONGDATETIME" ] \
|
||||||
|
|| [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \
|
||||||
|
|| [ ! "$HOSTOUTPUT" ] || [ ! "$HOSTSTATE" ] \
|
||||||
|
|| [ ! "$USEREMAIL" ] || [ ! "$NOTIFICATIONTYPE" ]; then
|
||||||
|
Error "Requirement parameters are missing."
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Build the message's subject
|
||||||
|
SUBJECT="[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!"
|
||||||
|
|
||||||
|
## Build the notification message
|
||||||
|
NOTIFICATION_MESSAGE=`cat << EOF
|
||||||
|
***** Icinga 2 Host Monitoring on $HOSTNAME *****
|
||||||
|
|
||||||
|
==> $HOSTDISPLAYNAME ($HOSTNAME) is $HOSTSTATE! <==
|
||||||
|
|
||||||
|
Info: $HOSTOUTPUT
|
||||||
|
|
||||||
|
When: $LONGDATETIME
|
||||||
|
Host: $HOSTNAME (Display Name: "$HOSTDISPLAYNAME")
|
||||||
|
IPv4: $HOSTADDRESS
|
||||||
|
EOF
|
||||||
`
|
`
|
||||||
|
|
||||||
/usr/bin/printf "%b" "$template" | mail -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME is $HOSTSTATE" $USEREMAIL
|
## Check whether IPv6 was specified.
|
||||||
|
if [ -n "$HOSTADDRESS6" ] ; then
|
||||||
|
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
|
||||||
|
IPv6: $HOSTADDRESS6"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Check whether author and comment was specified.
|
||||||
|
if [ -n "$NOTIFICATIONCOMMENT" ] ; then
|
||||||
|
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
|
||||||
|
|
||||||
|
Comment by $NOTIFICATIONAUTHORNAME:
|
||||||
|
$NOTIFICATIONCOMMENT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Check whether Icinga Web 2 URL was specified.
|
||||||
|
if [ -n "$ICINGAWEB2URL" ] ; then
|
||||||
|
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
|
||||||
|
|
||||||
|
URL:
|
||||||
|
$ICINGAWEB2URL/monitoring/host/show?host=$HOSTNAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Check whether verbose mode was enabled and log to syslog.
|
||||||
|
if [ "$VERBOSE" == "true" ] ; then
|
||||||
|
logger "$PROG sends $SUBJECT => $USEREMAIL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Send the mail using the $MAILBIN command.
|
||||||
|
## If an explicit sender was specified, try to set it.
|
||||||
|
if [ -n "$MAILFROM" ] ; then
|
||||||
|
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \
|
||||||
|
| $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL
|
||||||
|
else
|
||||||
|
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \
|
||||||
|
| $MAILBIN -s "$SUBJECT" $USEREMAIL
|
||||||
|
fi
|
||||||
|
@ -1,21 +1,147 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
template=`cat <<TEMPLATE
|
|
||||||
***** Icinga *****
|
|
||||||
|
|
||||||
Notification Type: $NOTIFICATIONTYPE
|
PROG="`basename $0`"
|
||||||
|
HOSTNAME="`hostname`"
|
||||||
|
MAILBIN="mail"
|
||||||
|
|
||||||
Service: $SERVICEDESC
|
if [ -z "`which $MAILBIN`" ] ; then
|
||||||
Host: $HOSTALIAS
|
echo "$MAILBIN not found in \$PATH. Consider installing it."
|
||||||
Address: $HOSTADDRESS
|
exit 1
|
||||||
State: $SERVICESTATE
|
fi
|
||||||
|
|
||||||
Date/Time: $LONGDATETIME
|
## Function helpers
|
||||||
|
Usage() {
|
||||||
|
cat << EOF
|
||||||
|
|
||||||
Additional Info: $SERVICEOUTPUT
|
Required parameters:
|
||||||
|
-4 HOSTADDRESS (\$address\$)
|
||||||
|
-d LONGDATETIME (\$icinga.long_date_time\$)
|
||||||
|
-e SERVICENAME (\$service.name\$)
|
||||||
|
-l HOSTNAME (\$host.name\$)
|
||||||
|
-n HOSTDISPLAYNAME (\$host.display_name\$)
|
||||||
|
-o SERVICEOUTPUT (\$service.output\$)
|
||||||
|
-r USEREMAIL (\$user.email\$)
|
||||||
|
-s SERVICESTATE (\$service.state\$)
|
||||||
|
-t NOTIFICATIONTYPE (\$notification.type\$)
|
||||||
|
-u SERVICEDISPLAYNAME (\$service.display_name\$)
|
||||||
|
|
||||||
Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
|
Optional parameters:
|
||||||
TEMPLATE
|
-6 HOSTADDRESS6 (\$address6\$)
|
||||||
|
-b NOTIFICATIONAUTHORNAME (\$notification.author\$)
|
||||||
|
-c NOTIFICATIONCOMMENT (\$notification.comment\$)
|
||||||
|
-i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset)
|
||||||
|
-f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils)
|
||||||
|
-v (\$notification_sendtosyslog\$, Default: false)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
Help() {
|
||||||
|
Usage;
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error() {
|
||||||
|
if [ "$1" ]; then
|
||||||
|
echo $1
|
||||||
|
fi
|
||||||
|
Usage;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
## Main
|
||||||
|
while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt
|
||||||
|
do
|
||||||
|
case "$opt" in
|
||||||
|
4) HOSTADDRESS=$OPTARG ;; # required
|
||||||
|
6) HOSTADDRESS6=$OPTARG ;;
|
||||||
|
b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
|
||||||
|
c) NOTIFICATIONCOMMENT=$OPTARG ;;
|
||||||
|
d) LONGDATETIME=$OPTARG ;; # required
|
||||||
|
e) SERVICENAME=$OPTARG ;; # required
|
||||||
|
f) MAILFROM=$OPTARG ;;
|
||||||
|
h) Usage ;;
|
||||||
|
i) ICINGAWEB2URL=$OPTARG ;;
|
||||||
|
l) HOSTNAME=$OPTARG ;; # required
|
||||||
|
n) HOSTDISPLAYNAME=$OPTARG ;; # required
|
||||||
|
o) SERVICEOUTPUT=$OPTARG ;; # required
|
||||||
|
r) USEREMAIL=$OPTARG ;; # required
|
||||||
|
s) SERVICESTATE=$OPTARG ;; # required
|
||||||
|
t) NOTIFICATIONTYPE=$OPTARG ;; # required
|
||||||
|
u) SERVICEDISPLAYNAME=$OPTARG ;; # required
|
||||||
|
v) VERBOSE=$OPTARG ;;
|
||||||
|
\?) echo "ERROR: Invalid option -$OPTARG" >&2
|
||||||
|
Usage ;;
|
||||||
|
:) echo "Missing option argument for -$OPTARG" >&2
|
||||||
|
Usage ;;
|
||||||
|
*) echo "Unimplemented option: -$OPTARG" >&2
|
||||||
|
Usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
## Check required parameters (TODO: better error message)
|
||||||
|
## Keep formatting in sync with mail-host-notification.sh
|
||||||
|
if [ ! "$HOSTADDRESS" ] || [ ! "$LONGDATETIME" ] \
|
||||||
|
|| [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \
|
||||||
|
|| [ ! "$SERVICENAME" ] || [ ! "$SERVICEDISPLAYNAME" ] \
|
||||||
|
|| [ ! "$SERVICEOUTPUT" ] || [ ! "$SERVICESTATE" ] \
|
||||||
|
|| [ ! "$USEREMAIL" ] || [ ! "$NOTIFICATIONTYPE" ]; then
|
||||||
|
Error "Requirement parameters are missing."
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Build the message's subject
|
||||||
|
SUBJECT="[$NOTIFICATIONTYPE] $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!"
|
||||||
|
|
||||||
|
## Build the notification message
|
||||||
|
NOTIFICATION_MESSAGE=`cat << EOF
|
||||||
|
***** Icinga 2 Service Monitoring on $HOSTNAME *****
|
||||||
|
|
||||||
|
==> $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE! <==
|
||||||
|
|
||||||
|
Info: $SERVICEOUTPUT
|
||||||
|
|
||||||
|
When: $LONGDATETIME
|
||||||
|
Service: $SERVICENAME (Display Name: "$SERVICEDISPLAYNAME")
|
||||||
|
Host: $HOSTNAME (Display Name: "$HOSTDISPLAYNAME")
|
||||||
|
IPv4: $HOSTADDRESS
|
||||||
|
EOF
|
||||||
`
|
`
|
||||||
|
|
||||||
/usr/bin/printf "%b" "$template" | mail -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME - $SERVICEDISPLAYNAME is $SERVICESTATE" $USEREMAIL
|
## Check whether IPv6 was specified.
|
||||||
|
if [ -n "$HOSTADDRESS6" ] ; then
|
||||||
|
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
|
||||||
|
IPv6: $HOSTADDRESS6"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Check whether author and comment was specified.
|
||||||
|
if [ -n "$NOTIFICATIONCOMMENT" ] ; then
|
||||||
|
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
|
||||||
|
|
||||||
|
Comment by $NOTIFICATIONAUTHORNAME:
|
||||||
|
$NOTIFICATIONCOMMENT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Check whether Icinga Web 2 URL was specified.
|
||||||
|
if [ -n "$ICINGAWEB2URL" ] ; then
|
||||||
|
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
|
||||||
|
|
||||||
|
URL:
|
||||||
|
$ICINGAWEB2URL/monitoring/service/show?host=$HOSTNAME&service=$SERVICENAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Check whether verbose mode was enabled and log to syslog.
|
||||||
|
if [ "$VERBOSE" == "true" ] ; then
|
||||||
|
logger "$PROG sends $SUBJECT => $USEREMAIL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Send the mail using the $MAILBIN command.
|
||||||
|
## If an explicit sender was specified, try to set it.
|
||||||
|
if [ -n "$MAILFROM" ] ; then
|
||||||
|
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \
|
||||||
|
| $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL
|
||||||
|
else
|
||||||
|
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \
|
||||||
|
| $MAILBIN -s "$SUBJECT" $USEREMAIL
|
||||||
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user