Merge pull request #5474 from pv2b/notification-make-ipv4-optional

Notification scripts - make HOSTADDRESS optional
This commit is contained in:
Michael Friedrich 2017-08-14 17:21:59 +02:00 committed by GitHub
commit b4b3509818
4 changed files with 74 additions and 18 deletions

View File

@ -1690,7 +1690,6 @@ information.
Name | Description Name | Description
-------------------------------|--------------------------------------- -------------------------------|---------------------------------------
`notification_address` | **Required.** The host's IPv4 address. Defaults to `$address$`.
`notification_date` | **Required.** Date and time. Defaults to `$icinga.long_date_time$`. `notification_date` | **Required.** Date and time. Defaults to `$icinga.long_date_time$`.
`notification_hostname` | **Required.** The host's `FQDN`. Defaults to `$host.name$`. `notification_hostname` | **Required.** The host's `FQDN`. Defaults to `$host.name$`.
`notification_hostdisplayname` | **Required.** The host's display name. Defaults to `$host.display_name$`. `notification_hostdisplayname` | **Required.** The host's display name. Defaults to `$host.display_name$`.
@ -1698,6 +1697,7 @@ information.
`notification_useremail` | **Required.** The notification's recipient(s). Defaults to `$user.email$`. `notification_useremail` | **Required.** The notification's recipient(s). Defaults to `$user.email$`.
`notification_hoststate` | **Required.** Current state of host. Defaults to `$host.state$`. `notification_hoststate` | **Required.** Current state of host. Defaults to `$host.state$`.
`notification_type` | **Required.** Type of notification. Defaults to `$notification.type$`. `notification_type` | **Required.** Type of notification. Defaults to `$notification.type$`.
`notification_address` | **Optional.** The host's IPv4 address. Defaults to `$address$`.
`notification_address6` | **Optional.** The host's IPv6 address. Defaults to `$address6$`. `notification_address6` | **Optional.** The host's IPv6 address. Defaults to `$address6$`.
`notification_author` | **Optional.** Comment author. Defaults to `$notification.author$`. `notification_author` | **Optional.** Comment author. Defaults to `$notification.author$`.
`notification_comment` | **Optional.** Comment text. Defaults to `$notification.comment$`. `notification_comment` | **Optional.** Comment text. Defaults to `$notification.comment$`.
@ -1716,7 +1716,6 @@ information.
Name | Description Name | Description
----------------------------------|--------------------------------------- ----------------------------------|---------------------------------------
`notification_address` | **Required.** The host's IPv4 address. Defaults to `$address$`.
`notification_date` | **Required.** Date and time. Defaults to `$icinga.long_date_time$`. `notification_date` | **Required.** Date and time. Defaults to `$icinga.long_date_time$`.
`notification_hostname` | **Required.** The host's `FQDN`. Defaults to `$host.name$`. `notification_hostname` | **Required.** The host's `FQDN`. Defaults to `$host.name$`.
`notification_servicename` | **Required.** The service name. Defaults to `$service.name$`. `notification_servicename` | **Required.** The service name. Defaults to `$service.name$`.
@ -1726,6 +1725,7 @@ information.
`notification_useremail` | **Required.** The notification's recipient(s). Defaults to `$user.email$`. `notification_useremail` | **Required.** The notification's recipient(s). Defaults to `$user.email$`.
`notification_servicestate` | **Required.** Current state of host. Defaults to `$service.state$`. `notification_servicestate` | **Required.** Current state of host. Defaults to `$service.state$`.
`notification_type` | **Required.** Type of notification. Defaults to `$notification.type$`. `notification_type` | **Required.** Type of notification. Defaults to `$notification.type$`.
`notification_address` | **Optional.** The host's IPv4 address. Defaults to `$address$`.
`notification_address6` | **Optional.** The host's IPv6 address. Defaults to `$address6$`. `notification_address6` | **Optional.** The host's IPv6 address. Defaults to `$address6$`.
`notification_author` | **Optional.** Comment author. Defaults to `$notification.author$`. `notification_author` | **Optional.** Comment author. Defaults to `$notification.author$`.
`notification_comment` | **Optional.** Comment text. Defaults to `$notification.comment$`. `notification_comment` | **Optional.** Comment text. Defaults to `$notification.comment$`.

View File

@ -10,10 +10,7 @@ object NotificationCommand "mail-host-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ] command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
arguments += { arguments += {
"-4" = { "-4" = "$notification_address$"
required = true
value = "$notification_address$"
}
"-6" = "$notification_address6$" "-6" = "$notification_address6$"
"-b" = "$notification_author$" "-b" = "$notification_author$"
"-c" = "$notification_comment$" "-c" = "$notification_comment$"
@ -72,10 +69,7 @@ object NotificationCommand "mail-service-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ] command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
arguments += { arguments += {
"-4" = { "-4" = "$notification_address$"
required = true
value = "$notification_address$"
}
"-6" = "$notification_address6$" "-6" = "$notification_address6$"
"-b" = "$notification_author$" "-b" = "$notification_author$"
"-c" = "$notification_comment$" "-c" = "$notification_comment$"
@ -139,3 +133,55 @@ object NotificationCommand "mail-service-notification" {
notification_servicedisplayname = "$service.display_name$" notification_servicedisplayname = "$service.display_name$"
} }
} }
/*
* If you prefer to use the notification scripts with environment
* variables instead of command line parameters, you can use
* the following commands. They have been updated from < 2.7
* to support the new notification scripts and should help
* with an upgrade.
* Remove the comment blocks and comment the notification commands above.
*/
/*
object NotificationCommand "mail-host-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
env = {
NOTIFICATIONTYPE = "$notification.type$"
HOSTDISPLAYNAME = "$host.display_name$"
HOSTNAME = "$host.name$"
HOSTADDRESS = "$address$"
HOSTSTATE = "$host.state$"
LONGDATETIME = "$icinga.long_date_time$"
HOSTOUTPUT = "$host.output$"
NOTIFICATIONAUTHORNAME = "$notification.author$"
NOTIFICATIONCOMMENT = "$notification.comment$"
HOSTDISPLAYNAME = "$host.display_name$"
USEREMAIL = "$user.email$"
}
}
object NotificationCommand "mail-service-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
env = {
NOTIFICATIONTYPE = "$notification.type$"
SERVICENAME = "$service.name$"
HOSTNAME = "$host.name$"
HOSTDISPLAYNAME = "$host.display_name$"
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$"
}
}
*/

View File

@ -16,7 +16,6 @@ Usage() {
cat << EOF cat << EOF
Required parameters: Required parameters:
-4 HOSTADDRESS (\$address\$)
-d LONGDATETIME (\$icinga.long_date_time\$) -d LONGDATETIME (\$icinga.long_date_time\$)
-l HOSTNAME (\$host.name\$) -l HOSTNAME (\$host.name\$)
-n HOSTDISPLAYNAME (\$host.display_name\$) -n HOSTDISPLAYNAME (\$host.display_name\$)
@ -26,6 +25,7 @@ Required parameters:
-t NOTIFICATIONTYPE (\$notification.type\$) -t NOTIFICATIONTYPE (\$notification.type\$)
Optional parameters: Optional parameters:
-4 HOSTADDRESS (\$address\$)
-6 HOSTADDRESS6 (\$address6\$) -6 HOSTADDRESS6 (\$address6\$)
-b NOTIFICATIONAUTHORNAME (\$notification.author\$) -b NOTIFICATIONAUTHORNAME (\$notification.author\$)
-c NOTIFICATIONCOMMENT (\$notification.comment\$) -c NOTIFICATIONCOMMENT (\$notification.comment\$)
@ -53,7 +53,7 @@ Error() {
while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt
do do
case "$opt" in case "$opt" in
4) HOSTADDRESS=$OPTARG ;; # required 4) HOSTADDRESS=$OPTARG ;;
6) HOSTADDRESS6=$OPTARG ;; 6) HOSTADDRESS6=$OPTARG ;;
b) NOTIFICATIONAUTHORNAME=$OPTARG ;; b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
c) NOTIFICATIONCOMMENT=$OPTARG ;; c) NOTIFICATIONCOMMENT=$OPTARG ;;
@ -81,7 +81,7 @@ shift $((OPTIND - 1))
## Check required parameters (TODO: better error message) ## Check required parameters (TODO: better error message)
## Keep formatting in sync with mail-service-notification.sh ## Keep formatting in sync with mail-service-notification.sh
if [ ! "$HOSTADDRESS" ] || [ ! "$LONGDATETIME" ] \ if [ ! "$LONGDATETIME" ] \
|| [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \ || [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \
|| [ ! "$HOSTOUTPUT" ] || [ ! "$HOSTSTATE" ] \ || [ ! "$HOSTOUTPUT" ] || [ ! "$HOSTSTATE" ] \
|| [ ! "$USEREMAIL" ] || [ ! "$NOTIFICATIONTYPE" ]; then || [ ! "$USEREMAIL" ] || [ ! "$NOTIFICATIONTYPE" ]; then
@ -101,10 +101,15 @@ Info: $HOSTOUTPUT
When: $LONGDATETIME When: $LONGDATETIME
Host: $HOSTNAME (Display Name: "$HOSTDISPLAYNAME") Host: $HOSTNAME (Display Name: "$HOSTDISPLAYNAME")
IPv4: $HOSTADDRESS
EOF EOF
` `
## Check whether IPv4 was specified.
if [ -n "$HOSTADDRESS" ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
IPv4: $HOSTADDRESS"
fi
## Check whether IPv6 was specified. ## Check whether IPv6 was specified.
if [ -n "$HOSTADDRESS6" ] ; then if [ -n "$HOSTADDRESS6" ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

View File

@ -16,7 +16,6 @@ Usage() {
cat << EOF cat << EOF
Required parameters: Required parameters:
-4 HOSTADDRESS (\$address\$)
-d LONGDATETIME (\$icinga.long_date_time\$) -d LONGDATETIME (\$icinga.long_date_time\$)
-e SERVICENAME (\$service.name\$) -e SERVICENAME (\$service.name\$)
-l HOSTNAME (\$host.name\$) -l HOSTNAME (\$host.name\$)
@ -28,6 +27,7 @@ Required parameters:
-u SERVICEDISPLAYNAME (\$service.display_name\$) -u SERVICEDISPLAYNAME (\$service.display_name\$)
Optional parameters: Optional parameters:
-4 HOSTADDRESS (\$address\$)
-6 HOSTADDRESS6 (\$address6\$) -6 HOSTADDRESS6 (\$address6\$)
-b NOTIFICATIONAUTHORNAME (\$notification.author\$) -b NOTIFICATIONAUTHORNAME (\$notification.author\$)
-c NOTIFICATIONCOMMENT (\$notification.comment\$) -c NOTIFICATIONCOMMENT (\$notification.comment\$)
@ -55,7 +55,7 @@ Error() {
while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt
do do
case "$opt" in case "$opt" in
4) HOSTADDRESS=$OPTARG ;; # required 4) HOSTADDRESS=$OPTARG ;;
6) HOSTADDRESS6=$OPTARG ;; 6) HOSTADDRESS6=$OPTARG ;;
b) NOTIFICATIONAUTHORNAME=$OPTARG ;; b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
c) NOTIFICATIONCOMMENT=$OPTARG ;; c) NOTIFICATIONCOMMENT=$OPTARG ;;
@ -85,7 +85,7 @@ shift $((OPTIND - 1))
## Check required parameters (TODO: better error message) ## Check required parameters (TODO: better error message)
## Keep formatting in sync with mail-host-notification.sh ## Keep formatting in sync with mail-host-notification.sh
if [ ! "$HOSTADDRESS" ] || [ ! "$LONGDATETIME" ] \ if [ ! "$LONGDATETIME" ] \
|| [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \ || [ ! "$HOSTNAME" ] || [ ! "$HOSTDISPLAYNAME" ] \
|| [ ! "$SERVICENAME" ] || [ ! "$SERVICEDISPLAYNAME" ] \ || [ ! "$SERVICENAME" ] || [ ! "$SERVICEDISPLAYNAME" ] \
|| [ ! "$SERVICEOUTPUT" ] || [ ! "$SERVICESTATE" ] \ || [ ! "$SERVICEOUTPUT" ] || [ ! "$SERVICESTATE" ] \
@ -107,10 +107,15 @@ Info: $SERVICEOUTPUT
When: $LONGDATETIME When: $LONGDATETIME
Service: $SERVICENAME (Display Name: "$SERVICEDISPLAYNAME") Service: $SERVICENAME (Display Name: "$SERVICEDISPLAYNAME")
Host: $HOSTNAME (Display Name: "$HOSTDISPLAYNAME") Host: $HOSTNAME (Display Name: "$HOSTDISPLAYNAME")
IPv4: $HOSTADDRESS
EOF EOF
` `
## Check whether IPv4 was specified.
if [ -n "$HOSTADDRESS" ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
IPv4: $HOSTADDRESS"
fi
## Check whether IPv6 was specified. ## Check whether IPv6 was specified.
if [ -n "$HOSTADDRESS6" ] ; then if [ -n "$HOSTADDRESS6" ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE