]> granicus.if.org Git - icinga2/commitdiff
Implement global runtime macros as $icinga.<name>$.
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 4 Apr 2014 17:35:47 +0000 (19:35 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 4 Apr 2014 17:35:47 +0000 (19:35 +0200)
Refs #5855

components/perfdata/perfdatawriter.ti
doc/3.03-custom-attributes-runtime-macros.md
doc/8-differences-between-icinga-1x-and-2.md
lib/icinga/icingaapplication.cpp

index 4003921038d104fd92b73940b81d8b3eef189f31..5f577aa98b3959808901cd7ca845805587f4a800 100644 (file)
@@ -21,7 +21,7 @@ class PerfdataWriter : DynamicObject
        [config] String host_format_template {
                default {{{
                        return "DATATYPE::HOSTPERFDATA\t"
-                           "TIMET::$TIMET$\t"
+                           "TIMET::$icinga.timet$\t"
                            "HOSTNAME::$HOSTNAME$\t"
                            "HOSTPERFDATA::$HOSTPERFDATA$\t"
                            "HOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\t"
@@ -32,7 +32,7 @@ class PerfdataWriter : DynamicObject
        [config] String service_format_template {
                default {{{
                        return "DATATYPE::SERVICEPERFDATA\t"
-                           "TIMET::$TIMET$\t"
+                           "TIMET::$icinga.timet$\t"
                            "HOSTNAME::$HOSTNAME$\t"
                            "SERVICEDESC::$SERVICEDESC$\t"
                            "SERVICEPERFDATA::$SERVICEPERFDATA$\t"
index 7d4f1fac090757f970c4a404d36c3ec596a67304..e3eb74e7ac5c8749428315ec4cccbdcd596f74d7 100644 (file)
@@ -244,17 +244,19 @@ where <name> is the name of the custom variable.
 
 ### <a id="global-runtime-macros"></a> Global Runtime Macros
 
-TODO
-
 The following macros are available in all executed commands:
 
+> **Note**
+>
+> Global application runtime macros require the `icinga.` prefix.
+
   Name                   | Description
   -----------------------|--------------
-  TIMET                  | Current UNIX timestamp.
-  LONGDATETIME           | Current date and time including timezone information. Example: `2014-01-03 11:23:08 +0000`
-  SHORTDATETIME          | Current date and time. Example: `2014-01-03 11:23:08`
-  DATE                   | Current date. Example: `2014-01-03`
-  TIME                   | Current time including timezone information. Example: `11:23:08 +0000`
+  icinga.timet           | Current UNIX timestamp.
+  icinga.longdatetime    | Current date and time including timezone information. Example: `2014-01-03 11:23:08 +0000`
+  icinga.shortdatetime   | Current date and time. Example: `2014-01-03 11:23:08`
+  icinga.date            | Current date. Example: `2014-01-03`
+  icinga.time            | Current time including timezone information. Example: `11:23:08 +0000`
 
 
 
index ff674e21ddf5c711f9c8b1fdcd00bb76d0bf9131..1b879c48b18de59d157efe421be840607dba42e1 100644 (file)
@@ -296,6 +296,22 @@ Icinga 2.
 Macros exported into the environment must be set using the `export_macros`
 attribute in command objects.
 
+### <a id="differences-1x-2-runtime-macros"></a> Runtime Macros
+
+Icinga 2 requires an object specific namespace when accessing configuration
+and stateful runtime macros. Custom attributes can be access directly.
+
+Changes to global runtime macros:
+
+   Icinga 1.x             | Icinga 2
+   -----------------------|----------------------
+   TIMET                  | icinga.timet
+   LONGDATETIME           | icinga.longdatetime
+   SHORTDATETIME          | icinga.shortdatetime
+   DATE                   | icinga.date
+   TIME                   | icinga.time
+
+
 ## <a id="differences-1x-2-checks"></a> Checks
 
 ### <a id="differences-1x-2-check-output"></a> Check Output
index 82148c6f7bd8aa15dc2476415be9960640e66373..de39684ba644d79cca031fb044183bafac214cc8 100644 (file)
@@ -133,29 +133,35 @@ String IcingaApplication::GetNodeName(void) const
 
 bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
 {
+       /* require icinga prefix for application macros */
+       if (macro.SubStr(0, 7) != "icinga.")
+               return false;
+
+       String key = macro.SubStr(7);
+
        double now = Utility::GetTime();
 
-       if (macro == "TIMET") {
+       if (key == "timet") {
                *result = Convert::ToString((long)now);
                return true;
-       } else if (macro == "LONGDATETIME") {
+       } else if (key == "longdatetime") {
                *result = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", now);
                return true;
-       } else if (macro == "SHORTDATETIME") {
+       } else if (key == "shortdatetime") {
                *result = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", now);
                return true;
-       } else if (macro == "DATE") {
+       } else if (key == "date") {
                *result = Utility::FormatDateTime("%Y-%m-%d", now);
                return true;
-       } else if (macro == "TIME") {
+       } else if (key == "time") {
                *result = Utility::FormatDateTime("%H:%M:%S %z", now);
                return true;
        }
 
        Dictionary::Ptr vars = GetVars();
 
-       if (vars && vars->Contains(macro)) {
-               *result = vars->Get(macro);
+       if (vars && vars->Contains(key)) {
+               *result = vars->Get(key);
                return true;
        }