Implement global runtime macros as $icinga.<name>$.

Refs #5855
This commit is contained in:
Michael Friedrich 2014-04-04 19:35:47 +02:00
parent 3d419cd48b
commit e375f15e5b
4 changed files with 40 additions and 16 deletions

View 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"

View 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`

View 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

View 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;
}