Notification scripts: Make the `-4` parameter optional

Not all hosts may have the `address` attribute set, or just use
`address6` instead.

refs #5474
This commit is contained in:
pv2b 2017-08-08 11:39:30 +02:00 committed by Michael Friedrich
parent 4080c84c1b
commit 57a092fc2a
3 changed files with 20 additions and 16 deletions

View File

@ -10,10 +10,7 @@ object NotificationCommand "mail-host-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
arguments += {
"-4" = {
required = true
value = "$notification_address$"
}
"-4" = "$notification_address$"
"-6" = "$notification_address6$"
"-b" = "$notification_author$"
"-c" = "$notification_comment$"
@ -72,10 +69,7 @@ object NotificationCommand "mail-service-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
arguments += {
"-4" = {
required = true
value = "$notification_address$"
}
"-4" = "$notification_address$"
"-6" = "$notification_address6$"
"-b" = "$notification_author$"
"-c" = "$notification_comment$"

View File

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

View File

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