]> granicus.if.org Git - icinga2/commitdiff
Notification scripts: Make the `-4` parameter optional
authorpv2b <pvz@pvz.pp.se>
Tue, 8 Aug 2017 09:39:30 +0000 (11:39 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 14 Aug 2017 15:11:57 +0000 (17:11 +0200)
Not all hosts may have the `address` attribute set, or just use
`address6` instead.

refs #5474

etc/icinga2/conf.d/commands.conf
etc/icinga2/scripts/mail-host-notification.sh
etc/icinga2/scripts/mail-service-notification.sh

index 2aaf44f86fd36a939eb8a5043ef81b6a6474ced7..11bfa8266cc486e4abe9b81f795350867b0ed59d 100644 (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$"
index d9ab7075480dc57dde949f39679c063c9be46619..1f5db94db049df4a1cd992a4b3fa4a5016a7fc7d 100755 (executable)
@@ -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
index dca23dc63d781cfaa8efec74c270560d997ae0f0..f99e3ed184020edf0714404d742351162795c7d7 100755 (executable)
@@ -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