From 9d8edd286f6f004c87d308a3189130c5b6040dc3 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 27 Nov 2013 09:23:30 +0100 Subject: [PATCH 1/2] Implement IcingaSysconfDir variable. Refs #5224 --- config.h.cmake | 1 + doc/4.2-global-variables.md | 3 ++- icinga-app/icinga.cpp | 1 + lib/base/application.cpp | 20 ++++++++++++++++++++ lib/base/application.h | 3 +++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/config.h.cmake b/config.h.cmake index 2a4fe035a..cc80a2e04 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -7,6 +7,7 @@ #cmakedefine HAVE_VFORK #define ICINGA_PREFIX "${CMAKE_INSTALL_PREFIX}" +#define ICINGA_SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}" #define ICINGA_LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}" #define ICINGA_PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/icinga2" diff --git a/doc/4.2-global-variables.md b/doc/4.2-global-variables.md index 247db3c15..becc1de5e 100644 --- a/doc/4.2-global-variables.md +++ b/doc/4.2-global-variables.md @@ -1,10 +1,11 @@ -## Global Variables +## Global Variables Icinga 2 provides a number of special global variables: Variable |Description --------------------------|------------------- IcingaPrefixDir |**Read-only.** Contains the installation prefix that was specified with cmake -DCMAKE_INSTALL_PREFIX. Defaults to /usr/local +IcingaSysconfDir |**Read-only.** Contains the path of the sysconf directory. Defaults to IcingaPrefixDir + "/etc". IcingaLocalStateDir |**Read-only.** Contains the path of the local state directory. Defaults to IcingaPrefixDir + "/var". IcingaPkgDataDir |**Read-only.** Contains the path of the package data directory. Defaults to IcingaPrefixDir + "/share/icinga2". IcingaStatePath |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to IcingaLocalStateDir + "/lib/icinga2/icinga2.state". diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 1a203521c..d10671b70 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -198,6 +198,7 @@ int main(int argc, char **argv) Application::InstallExceptionHandlers(); Application::DeclarePrefixDir(ICINGA_PREFIX); + Application::DeclareSysconfDir(ICINGA_SYSCONFDIR); Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR); Application::DeclarePkgDataDir(ICINGA_PKGDATADIR); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index f6220be8e..932e9f9b7 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -609,6 +609,26 @@ void Application::DeclarePrefixDir(const String& path) ScriptVariable::Declare("IcingaPrefixDir", path); } +/** + * Retrives the path of the sysconf dir. + * + * @returns The path. + */ +String Application::GetSysconfDir(void) +{ + return ScriptVariable::Get("IcingaSysconfDir"); +} + +/** + * Sets the path of the sysconf dir. + * + * @param path The new path. + */ +void Application::DeclareSysconfDir(const String& path) +{ + ScriptVariable::Declare("IcingaSysconfDir", path); +} + /** * Retrieves the path for the local state dir. * diff --git a/lib/base/application.h b/lib/base/application.h index 98e7ee1e5..720f43c70 100644 --- a/lib/base/application.h +++ b/lib/base/application.h @@ -73,6 +73,9 @@ public: static String GetPrefixDir(void); static void DeclarePrefixDir(const String& path); + static String GetSysconfDir(void); + static void DeclareSysconfDir(const String& path); + static String GetLocalStateDir(void); static void DeclareLocalStateDir(const String& path); From 3c29e4e90711efe41566970c62d9ede7d2d42e6b Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 27 Nov 2013 09:45:04 +0100 Subject: [PATCH 2/2] Use a shell script for the mail-service-notification command. Refs #5224 --- etc/CMakeLists.txt | 1 + etc/icinga2/conf.d/notifications.conf | 34 ++++++++++-------------- etc/icinga2/scripts/mail-notification.sh | 20 ++++++++++++++ icinga2.spec | 2 ++ 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100755 etc/icinga2/scripts/mail-notification.sh diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index 864350f9f..00c07c9c2 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 9f58e558f..36013c512 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 ***** + command = [ (IcingaSysconfDir + "/icinga2/scripts/mail-notification.sh") ], - 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$" + 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 000000000..803892dc0 --- /dev/null +++ b/etc/icinga2/scripts/mail-notification.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +template=$(cat <