[icinga-checkins] icinga.org: icinga2/next: Use a shell script for the mail-service-notification command.

git at icinga.org git at icinga.org
Wed Nov 27 10:26:55 CET 2013


Module: icinga2
Branch: next
Commit: 3c29e4e90711efe41566970c62d9ede7d2d42e6b
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=3c29e4e90711efe41566970c62d9ede7d2d42e6b

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Nov 27 09:45:04 2013 +0100

Use a shell script for the mail-service-notification command.

Refs #5224

---

 etc/CMakeLists.txt                       |    1 +
 etc/icinga2/conf.d/notifications.conf    |   36 +++++++++++++-----------------
 etc/icinga2/scripts/mail-notification.sh |   20 +++++++++++++++++
 icinga2.spec                             |    2 ++
 4 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt
index 864350f..00c07c9 100644
--- a/etc/CMakeLists.txt
+++ b/etc/CMakeLists.txt
@@ -41,6 +41,7 @@ install_if_not_exists(icinga2/features-available/notification.conf ${CMAKE_INSTA
 install_if_not_exists(icinga2/features-available/perfdata.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
 install_if_not_exists(icinga2/features-available/statusdata.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
 install_if_not_exists(icinga2/features-available/syslog.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available)
+install_if_not_exists(icinga2/scripts/mail-notification.sh ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/scripts)
 
 install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled\")")
 install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/checker.conf \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled/checker.conf\")")
diff --git a/etc/icinga2/conf.d/notifications.conf b/etc/icinga2/conf.d/notifications.conf
index 9f58e55..36013c5 100644
--- a/etc/icinga2/conf.d/notifications.conf
+++ b/etc/icinga2/conf.d/notifications.conf
@@ -22,27 +22,21 @@ template Notification "mail-notification" {
 }
 
 object NotificationCommand "mail-service-notification" inherits "plugin-notification-command" {
-  command = [
-    "/usr/bin/printf",
-    "\"%b\"",
-    {{{\"***** Icinga  *****
-
-    Notification Type: $NOTIFICATIONTYPE$
-
-    Service: $SERVICEDESC$
-    Host: $HOSTALIAS$
-    Address: $HOSTADDRESS$
-    State: $SERVICESTATE$
-
-    Date/Time: $LONGDATETIME$
-
-    Additional Info: $SERVICEOUTPUT$
-
-    Comment: [$NOTIFICATIONAUTHORNAME$] $NOTIFICATIONCOMMENT$\"}}},
-    "/bin/mail",
-    "-s",
-    "\"$NOTIFICATIONTYPE$ - $HOSTDISPLAYNAME$ - $SERVICEDISPLAYNAME$ is $SERVICESTATE$\"",
-    "$USEREMAIL$"
+  command = [ (IcingaSysconfDir + "/icinga2/scripts/mail-notification.sh") ],
+
+  export_macros = [
+    "NOTIFICATIONTYPE",
+    "SERVICEDESC",
+    "HOSTALIAS",
+    "HOSTADDRESS",
+    "SERVICESTATE",
+    "LONGDATETIME",
+    "SERVICEOUTPUT",
+    "NOTIFICATIONAUTHORNAME",
+    "NOTIFICATIONCOMMENT",
+    "HOSTDISPLAYNAME",
+    "SERVICEDISPLAYNAME",
+    "USEREMAIL"
   ]
 }
 
diff --git a/etc/icinga2/scripts/mail-notification.sh b/etc/icinga2/scripts/mail-notification.sh
new file mode 100755
index 0000000..803892d
--- /dev/null
+++ b/etc/icinga2/scripts/mail-notification.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+template=$(cat <<TEMPLATE
+***** Icinga  *****
+
+Notification Type: $NOTIFICATIONTYPE
+
+Service: $SERVICEDESC
+Host: $HOSTALIAS
+Address: $HOSTADDRESS
+State: $SERVICESTATE
+
+Date/Time: $LONGDATETIME
+
+Additional Info: $SERVICEOUTPUT
+
+Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
+TEMPLATE)
+
+/usr/bin/printf "%b" $template | mail -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME - $SERVICEDISPLAYNAME is $SERVICESTATE" $USEREMAIL
+
diff --git a/icinga2.spec b/icinga2.spec
index c2cc356..600722d 100644
--- a/icinga2.spec
+++ b/icinga2.spec
@@ -315,10 +315,12 @@ exit 0
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/conf.d
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/features-available
 %attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/features-enabled
+%attr(0750,%{icinga_user},%{icinga_group}) %dir %{_sysconfdir}/%{name}/scripts
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/%{name}.conf
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/conf.d/*.conf
 %config(noreplace) %attr(0640,%{icinga_user},%{icinga_group}) %{_sysconfdir}/%{name}/features-available/*.conf
 %config(noreplace) %{_sysconfdir}/%{name}/features-enabled/*.conf
+%config(noreplace) %{_sysconfdir}/%{name}/scripts/*
 %{_sbindir}/%{name}
 %{_bindir}/%{name}-migrate-config
 %{_bindir}/%{name}-build-ca





More information about the icinga-checkins mailing list