From 31710e11629b601c133e3bcf5419cef2fe1fb5e8 Mon Sep 17 00:00:00 2001 From: Silas <67681686+Tqnsls@users.noreply.github.com> Date: Wed, 1 Mar 2023 11:48:39 +0100 Subject: [PATCH 1/5] Added host.notes and service.notes output if specified --- etc/icinga2/scripts/mail-host-notification.sh | 10 +++++++++- .../scripts/mail-service-notification.sh | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/etc/icinga2/scripts/mail-host-notification.sh b/etc/icinga2/scripts/mail-host-notification.sh index 744481a77..3850ad651 100755 --- a/etc/icinga2/scripts/mail-host-notification.sh +++ b/etc/icinga2/scripts/mail-host-notification.sh @@ -27,6 +27,7 @@ Required parameters: Optional parameters: -4 HOSTADDRESS (\$address\$) -6 HOSTADDRESS6 (\$address6\$) + -X HOSTNOTES (\$host.notes\$) -b NOTIFICATIONAUTHORNAME (\$notification.author\$) -c NOTIFICATIONCOMMENT (\$notification.comment\$) -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset) @@ -63,7 +64,7 @@ urlencode() { } ## Main -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:X: opt do case "$opt" in 4) HOSTADDRESS=$OPTARG ;; @@ -77,6 +78,7 @@ do l) HOSTNAME=$OPTARG ;; # required n) HOSTDISPLAYNAME=$OPTARG ;; # required o) HOSTOUTPUT=$OPTARG ;; # required + X) HOSTNOTES="${OPTARG}" ;; r) USEREMAIL=$OPTARG ;; # required s) HOSTSTATE=$OPTARG ;; # required t) NOTIFICATIONTYPE=$OPTARG ;; # required @@ -129,6 +131,12 @@ if [ -n "$HOSTADDRESS6" ] ; then IPv6: $HOSTADDRESS6" fi +## Check whether host notes was specified. +if [ -n "$HOSTNOTES" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +Host-Notes: $HOSTNOTES" +fi + ## Check whether author and comment was specified. if [ -n "$NOTIFICATIONCOMMENT" ] ; then NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE diff --git a/etc/icinga2/scripts/mail-service-notification.sh b/etc/icinga2/scripts/mail-service-notification.sh index 8e560ac23..da277adb7 100755 --- a/etc/icinga2/scripts/mail-service-notification.sh +++ b/etc/icinga2/scripts/mail-service-notification.sh @@ -29,6 +29,8 @@ Required parameters: Optional parameters: -4 HOSTADDRESS (\$address\$) -6 HOSTADDRESS6 (\$address6\$) + -X HOSTNOTES (\$host.notes\$) + -x SERVICENOTES (\$service.notes\$) -b NOTIFICATIONAUTHORNAME (\$notification.author\$) -c NOTIFICATIONCOMMENT (\$notification.comment\$) -i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset) @@ -65,7 +67,7 @@ urlencode() { } ## Main -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:X:x: opt do case "$opt" in 4) HOSTADDRESS=$OPTARG ;; @@ -79,6 +81,8 @@ do i) ICINGAWEB2URL=$OPTARG ;; l) HOSTNAME=$OPTARG ;; # required n) HOSTDISPLAYNAME=$OPTARG ;; # required + X) HOSTNOTES=$OPTARG ;; + x) SERVICENOTES=$OPTARG ;; o) SERVICEOUTPUT=$OPTARG ;; # required r) USEREMAIL=$OPTARG ;; # required s) SERVICESTATE=$OPTARG ;; # required @@ -134,6 +138,18 @@ if [ -n "$HOSTADDRESS6" ] ; then IPv6: $HOSTADDRESS6" fi +## Check whether host notes was specified. +if [ -n "${HOSTNOTES}" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +Host-Notes: $HOSTNOTES" +fi + +## Check whether service notes was specified. +if [ -n "${SERVICENOTES}" ] ; then + NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE +Service-Notes: $SERVICENOTES" +fi + ## Check whether author and comment was specified. if [ -n "$NOTIFICATIONCOMMENT" ] ; then NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE From bdda58175bb30de32e8658bce1b73bfff229402a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?= Date: Thu, 2 Mar 2023 14:08:25 +0100 Subject: [PATCH 2/5] Update mail-host-notification.sh and mail-service-notification.sh --- etc/icinga2/scripts/mail-host-notification.sh | 4 ++-- etc/icinga2/scripts/mail-service-notification.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/icinga2/scripts/mail-host-notification.sh b/etc/icinga2/scripts/mail-host-notification.sh index 3850ad651..0c20ecb65 100755 --- a/etc/icinga2/scripts/mail-host-notification.sh +++ b/etc/icinga2/scripts/mail-host-notification.sh @@ -78,7 +78,7 @@ do l) HOSTNAME=$OPTARG ;; # required n) HOSTDISPLAYNAME=$OPTARG ;; # required o) HOSTOUTPUT=$OPTARG ;; # required - X) HOSTNOTES="${OPTARG}" ;; + X) HOSTNOTES=$OPTARG ;; r) USEREMAIL=$OPTARG ;; # required s) HOSTSTATE=$OPTARG ;; # required t) NOTIFICATIONTYPE=$OPTARG ;; # required @@ -134,7 +134,7 @@ fi ## Check whether host notes was specified. if [ -n "$HOSTNOTES" ] ; then NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE -Host-Notes: $HOSTNOTES" +Host notes: $HOSTNOTES" fi ## Check whether author and comment was specified. diff --git a/etc/icinga2/scripts/mail-service-notification.sh b/etc/icinga2/scripts/mail-service-notification.sh index da277adb7..35287439b 100755 --- a/etc/icinga2/scripts/mail-service-notification.sh +++ b/etc/icinga2/scripts/mail-service-notification.sh @@ -139,15 +139,15 @@ IPv6: $HOSTADDRESS6" fi ## Check whether host notes was specified. -if [ -n "${HOSTNOTES}" ] ; then +if [ -n "$HOSTNOTES" ] ; then NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE -Host-Notes: $HOSTNOTES" +Host notes: $HOSTNOTES" fi ## Check whether service notes was specified. -if [ -n "${SERVICENOTES}" ] ; then +if [ -n "$SERVICENOTES" ] ; then NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE -Service-Notes: $SERVICENOTES" +Service notes: $SERVICENOTES" fi ## Check whether author and comment was specified. From 7f0aaf9b79fb97442bbeb8f78a02cf92e4e9827d Mon Sep 17 00:00:00 2001 From: Silas <67681686+Tqnsls@users.noreply.github.com> Date: Mon, 13 Mar 2023 12:47:39 +0100 Subject: [PATCH 3/5] Update commands.conf --- etc/icinga2/conf.d/commands.conf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/etc/icinga2/conf.d/commands.conf b/etc/icinga2/conf.d/commands.conf index bd511cebc..5e1035018 100644 --- a/etc/icinga2/conf.d/commands.conf +++ b/etc/icinga2/conf.d/commands.conf @@ -43,6 +43,9 @@ object NotificationCommand "mail-host-notification" { required = true value = "$notification_hoststate$" } + "-X" = { + required = false + value = "$notification_hostnotes$" "-t" = { required = true value = "$notification_type$" @@ -62,6 +65,7 @@ object NotificationCommand "mail-host-notification" { notification_hostoutput = "$host.output$" notification_hoststate = "$host.state$" notification_useremail = "$user.email$" + notification_hostnotes = $host.notes$" } } @@ -110,6 +114,14 @@ object NotificationCommand "mail-service-notification" { required = true value = "$notification_type$" } + "-X" = { + required = false + value = "$notification_hostnotes$" + } + "-x" = { + required = false + value = "$notification_servicenotes$" + } "-u" = { required = true value = "$notification_servicedisplayname$" @@ -131,6 +143,8 @@ object NotificationCommand "mail-service-notification" { notification_servicestate = "$service.state$" notification_useremail = "$user.email$" notification_servicedisplayname = "$service.display_name$" + notification_hostnotes = "$host.notes$" + notification_servicenotes = "$service.notes$" } } @@ -160,6 +174,7 @@ object NotificationCommand "mail-host-notification" { NOTIFICATIONCOMMENT = "$notification.comment$" HOSTDISPLAYNAME = "$host.display_name$" USEREMAIL = "$user.email$" + HOSTNOTES = "$host.notes$" } } @@ -180,6 +195,8 @@ object NotificationCommand "mail-service-notification" { HOSTDISPLAYNAME = "$host.display_name$" SERVICEDISPLAYNAME = "$service.display_name$" USEREMAIL = "$user.email$" + HOSTNOTES = "$host.notes$" + SERVICENOTES = "$service.notes$" } } From a85892ccb988f63337ebc064bf4cec8cffbab578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?= Date: Fri, 14 Apr 2023 12:22:27 +0200 Subject: [PATCH 4/5] mail-*-notification: remove redundant required = false --- etc/icinga2/conf.d/commands.conf | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/etc/icinga2/conf.d/commands.conf b/etc/icinga2/conf.d/commands.conf index 5e1035018..29f86210a 100644 --- a/etc/icinga2/conf.d/commands.conf +++ b/etc/icinga2/conf.d/commands.conf @@ -43,9 +43,7 @@ object NotificationCommand "mail-host-notification" { required = true value = "$notification_hoststate$" } - "-X" = { - required = false - value = "$notification_hostnotes$" + "-X" = "$notification_hostnotes$" "-t" = { required = true value = "$notification_type$" @@ -114,14 +112,8 @@ object NotificationCommand "mail-service-notification" { required = true value = "$notification_type$" } - "-X" = { - required = false - value = "$notification_hostnotes$" - } - "-x" = { - required = false - value = "$notification_servicenotes$" - } + "-X" = "$notification_hostnotes$" + "-x" = "$notification_servicenotes$" "-u" = { required = true value = "$notification_servicedisplayname$" From c2c0c27dac86f20343f2b5c19c85af8b50ab2c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?= Date: Fri, 14 Apr 2023 12:36:01 +0200 Subject: [PATCH 5/5] Fix typo --- etc/icinga2/conf.d/commands.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/icinga2/conf.d/commands.conf b/etc/icinga2/conf.d/commands.conf index 29f86210a..e7d555c86 100644 --- a/etc/icinga2/conf.d/commands.conf +++ b/etc/icinga2/conf.d/commands.conf @@ -63,7 +63,7 @@ object NotificationCommand "mail-host-notification" { notification_hostoutput = "$host.output$" notification_hoststate = "$host.state$" notification_useremail = "$user.email$" - notification_hostnotes = $host.notes$" + notification_hostnotes = "$host.notes$" } }