]> granicus.if.org Git - icinga2/commitdiff
Implement support for using custom variables as macros.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 18 Dec 2013 09:53:26 +0000 (10:53 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 18 Dec 2013 09:53:26 +0000 (10:53 +0100)
Fixes #5364

doc/3.03-macros.md
lib/icinga/host.cpp
lib/icinga/notification.cpp
lib/icinga/service.cpp
lib/icinga/user.cpp

index 9ac62ca424493d0f8749c948460d90866698aa54..4775d98ce4f61b971f3ca8d3ee8b68684d9cc87f 100644 (file)
@@ -106,6 +106,9 @@ hosts or services:
   HOSTADDRESS            | This is an alias for the `address` macro. If the `address` macro is not defined the host object's name is used instead.
   HOSTADDRESS6           | This is an alias for the `address6` macro. If the `address` macro is not defined the host object's name is used instead.
 
+Custom variables are made available as macros with the name "_HOST<name>"
+where <name> is the name of the custom variable.
+
 ### Service Macros
 
 The following service macros are available in all commands that are executed for
@@ -137,6 +140,9 @@ services:
   TOTALHOSTSERVICESUNKNOWN  | Number of services associated with the host which are in an `UNKNOWN` state.
   TOTALHOSTSERVICESCRITICAL | Number of services associated with the host which are in a `CRITICAL` state.
 
+Custom variables are made available as macros with the name "_SERVICE<name>"
+where <name> is the name of the custom variable.
+
 ### User Macros
 
 The following service macros are available in all commands that are executed for
@@ -149,6 +155,14 @@ users:
   USEREMAIL              | This is an alias for the `email` macro.
   USERPAGER              | This is an alias for the `pager` macro.
 
+Custom variables are made available as macros with the name "_USER<name>" and
+"_CONTACT<name>" where <name> is the name of the custom variable.
+
+### Notification Macros
+
+Custom variables are made available as macros with the name "_NOTIFICATION<name>"
+where <name> is the name of the custom variable.
+
 ### Global Macros
 
 The following macros are available in all commands:
index 74e3a9c53b7429b66105ccca79d6d96e9ba9a7b7..8fd27f1cb546cd32d380def00afca69af371303c 100644 (file)
@@ -615,6 +615,12 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re
                }
        }
 
+       if (macro.SubStr(0, 5) == "_HOST") {
+               Dictionary::Ptr custom = GetCustom();
+               *result = custom ? custom->Get(macro.SubStr(5)) : "";
+               return true;
+       }
+
        Dictionary::Ptr macros = GetMacros();
 
        String name = macro;
index 28a5aa72b3d77ccabbbd6a55fa90c75bb26b123f..85fb50b0cd0b8193c33e7dbc836a63fc749084cc 100644 (file)
@@ -325,6 +325,12 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
 
 bool Notification::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
 {
+       if (macro.SubStr(0, 13) == "_NOTIFICATION") {
+               Dictionary::Ptr custom = GetCustom();
+               *result = custom ? custom->Get(macro.SubStr(13)) : "";
+               return true;
+       }
+
        Dictionary::Ptr macros = GetMacros();
 
        if (macros && macros->Contains(macro)) {
index be50f34f9c1fcf2f2945ceb12b7c788cb1feb728..9a63b9f8ba2d9bbd89f2cf571dde5f04c8ca1ee2 100644 (file)
@@ -474,6 +474,12 @@ bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Stri
                }
        }
 
+       if (macro.SubStr(0, 8) == "_SERVICE") {
+               Dictionary::Ptr custom = GetCustom();
+               *result = custom ? custom->Get(macro.SubStr(8)) : "";
+               return true;
+       }
+
        Dictionary::Ptr macros = GetMacros();
 
        if (macros && macros->Contains(macro)) {
index 23d92f82f538a56430f6182a304e4d44f3fe8bbf..18935106e6af6a36c36b4a262b6192a1f989faab 100644 (file)
@@ -74,6 +74,14 @@ bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re
        } else if (macro == "USERDISPLAYNAME" || macro == "CONTACTALIAS") {
                *result = GetDisplayName();
                return true;
+       } else if (macro.SubStr(0, 5) == "_USER") {
+               Dictionary::Ptr custom = GetCustom();
+               *result = custom ? custom->Get(macro.SubStr(5)) : "";
+               return true;
+       } else if (macro.SubStr(0, 8) == "_CONTACT") {
+               Dictionary::Ptr custom = GetCustom();
+               *result = custom ? custom->Get(macro.SubStr(8)) : "";
+               return true;
        } else {
                String tmacro;