mirror of https://github.com/Icinga/icinga2.git
parent
e375f15e5b
commit
0a0399826f
|
@ -159,26 +159,28 @@ hosts or services:
|
||||||
|
|
||||||
Name | Description
|
Name | Description
|
||||||
-----------------------|--------------
|
-----------------------|--------------
|
||||||
HOSTNAME | The name of the host object.
|
host.name | The name of the host object.
|
||||||
HOSTDISPLAYNAME | The value of the `display_name` attribute.
|
host.displayname | The value of the `display_name` attribute.
|
||||||
HOSTALIAS | This is an alias for the `HOSTDISPLAYNAME` macro.
|
host.state | The host's current state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
|
||||||
HOSTSTATE | The host's current state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
|
host.stateid | The host's current state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
|
||||||
HOSTSTATEID | The host's current state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
|
host.statetype | The host's current state type. Can be one of `SOFT` and `HARD`.
|
||||||
HOSTSTATETYPE | The host's current state type. Can be one of `SOFT` and `HARD`.
|
host.attempt | The current check attempt number.
|
||||||
HOSTATTEMPT | The current check attempt number.
|
host.maxattempt | The maximum number of checks which are executed before changing to a hard state.
|
||||||
MAXHOSTATTEMPT | The maximum number of checks which are executed before changing to a hard state.
|
host.laststate | The host's previous state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
|
||||||
LASTHOSTSTATE | The host's previous state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
|
host.laststateid | The host's previous state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
|
||||||
LASTHOSTSTATEID | The host's previous state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
|
host.laststatetype | The host's previous state type. Can be one of `SOFT` and `HARD`.
|
||||||
LASTHOSTSTATETYPE | The host's previous state type. Can be one of `SOFT` and `HARD`.
|
host.laststatechange | The last state change's timestamp.
|
||||||
LASTHOSTSTATECHANGE | The last state change's timestamp.
|
host.durationsec | The time since the last state change.
|
||||||
HOSTDURATIONSEC | The time since the last state change.
|
host.latency | The host's check latency.
|
||||||
HOSTLATENCY | The host's check latency.
|
host.executiontime | The host's check execution time.
|
||||||
HOSTEXECUTIONTIME | The host's check execution time.
|
host.output | The last check's output.
|
||||||
HOSTOUTPUT | The last check's output.
|
host.perfdata | The last check's performance data.
|
||||||
HOSTPERFDATA | The last check's performance data.
|
host.lastcheck | The timestamp when the last check was executed.
|
||||||
LASTHOSTCHECK | The timestamp when the last check was executed.
|
host.totalservices | Number of services associated with the host.
|
||||||
HOSTADDRESS | This is an alias for the `address` macro. If the `address` macro is not defined the host object's name is used instead.
|
host.totalservicesok | Number of services associated with the host which are in an `OK` state.
|
||||||
HOSTADDRESS6 | This is an alias for the `address6` macro. If the `address` macro is not defined the host object's name is used instead.
|
host.totalserviceswarning | Number of services associated with the host which are in a `WARNING` state.
|
||||||
|
host.totalservicesunknown | Number of services associated with the host which are in an `UNKNOWN` state.
|
||||||
|
host.totalservicescritical | Number of services associated with the host which are in a `CRITICAL` state.
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
>
|
>
|
||||||
|
@ -195,29 +197,24 @@ services:
|
||||||
|
|
||||||
Name | Description
|
Name | Description
|
||||||
-----------------------|--------------
|
-----------------------|--------------
|
||||||
SERVICEDESC | The short name of the service object.
|
service.description | The short name of the service object.
|
||||||
SERVICEDISPLAYNAME | The value of the `display_name` attribute.
|
service.displayname | The value of the `display_name` attribute.
|
||||||
SERVICECHECKCOMMAND | This is an alias for the `SERVICEDISPLAYNAME` macro.
|
service.checkcommand | This is an alias for the `SERVICEDISPLAYNAME` macro.
|
||||||
SERVICESTATE | The service's current state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
|
service.state | The service's current state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
|
||||||
SERVICESTATEID | The service's current state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
|
service.stateid | The service's current state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
|
||||||
SERVICESTATETYPE | The service's current state type. Can be one of `SOFT` and `HARD`.
|
service.statetype | The service's current state type. Can be one of `SOFT` and `HARD`.
|
||||||
SERVICEATTEMPT | The current check attempt number.
|
service.attempt | The current check attempt number.
|
||||||
MAXSERVICEATTEMPT | The maximum number of checks which are executed before changing to a hard state.
|
service.maxattempt | The maximum number of checks which are executed before changing to a hard state.
|
||||||
LASTSERVICESTATE | The service's previous state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
|
service.laststate | The service's previous state. Can be one of `OK`, `WARNING`, `CRITICAL` and `UNKNOWN`.
|
||||||
LASTSERVICESTATEID | The service's previous state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
|
service.laststateid | The service's previous state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
|
||||||
LASTSERVICESTATETYPE | The service's previous state type. Can be one of `SOFT` and `HARD`.
|
service.laststatetype | The service's previous state type. Can be one of `SOFT` and `HARD`.
|
||||||
LASTSERVICESTATECHANGE | The last state change's timestamp.
|
service.laststatechange| The last state change's timestamp.
|
||||||
SERVICEDURATIONSEC | The time since the last state change.
|
service.durationsec | The time since the last state change.
|
||||||
SERVICELATENCY | The service's check latency.
|
service.latency | The service's check latency.
|
||||||
SERVICEEXECUTIONTIME | The service's check execution time.
|
service.executiontime | The service's check execution time.
|
||||||
SERVICEOUTPUT | The last check's output.
|
service.output | The last check's output.
|
||||||
SERVICEPERFDATA | The last check's performance data.
|
service.perfdata | The last check's performance data.
|
||||||
LASTSERVICECHECK | The timestamp when the last check was executed.
|
service.lastcheck | The timestamp when the last check was executed.
|
||||||
TOTALHOSTSERVICES | Number of services associated with the host.
|
|
||||||
TOTALHOSTSERVICESOK | Number of services associated with the host which are in an `OK` state.
|
|
||||||
TOTALHOSTSERVICESWARNING | Number of services associated with the host which are in a `WARNING` state.
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -301,6 +301,60 @@ attribute in command objects.
|
||||||
Icinga 2 requires an object specific namespace when accessing configuration
|
Icinga 2 requires an object specific namespace when accessing configuration
|
||||||
and stateful runtime macros. Custom attributes can be access directly.
|
and stateful runtime macros. Custom attributes can be access directly.
|
||||||
|
|
||||||
|
Changes to host runtime macros
|
||||||
|
|
||||||
|
Icinga 1.x | Icinga 2
|
||||||
|
-----------------------|----------------------
|
||||||
|
|
||||||
|
Changes to service runtime macros
|
||||||
|
|
||||||
|
Icinga 1.x | Icinga 2
|
||||||
|
-----------------------|----------------------
|
||||||
|
SERVICEDESC | service.description
|
||||||
|
SERVICEDISPLAYNAME | service.displayname
|
||||||
|
SERVICECHECKCOMMAND | service.checkcommand
|
||||||
|
SERVICESTATE | service.state
|
||||||
|
SERVICESTATEID | service.stateid
|
||||||
|
SERVICESTATETYPE | service.statetype
|
||||||
|
SERVICEATTEMPT | service.attempt
|
||||||
|
MAXSERVICEATTEMPT | service.maxattempt
|
||||||
|
LASTSERVICESTATE | service.laststate
|
||||||
|
LASTSERVICESTATEID | service.laststateid
|
||||||
|
LASTSERVICESTATETYPE | service.laststatetype
|
||||||
|
LASTSERVICESTATECHANGE | service.laststatechange
|
||||||
|
SERVICEDURATIONSEC | service.durationsec
|
||||||
|
SERVICELATENCY | service.latency
|
||||||
|
SERVICEEXECUTIONTIME | service.executiontime
|
||||||
|
SERVICEOUTPUT | service.output
|
||||||
|
SERVICEPERFDATA | service.perfdata
|
||||||
|
LASTSERVICECHECK | service.lastcheck
|
||||||
|
|
||||||
|
|
||||||
|
Changes to user (contact) runtime macros
|
||||||
|
|
||||||
|
Icinga 1.x | Icinga 2
|
||||||
|
-----------------------|----------------------
|
||||||
|
HOSTNAME | host.name
|
||||||
|
HOSTDISPLAYNAME | host.displayname
|
||||||
|
HOSTALIAS | ..
|
||||||
|
HOSTSTATE | host.state
|
||||||
|
HOSTSTATEID | host.stateid
|
||||||
|
HOSTSTATETYPE | host.statetype
|
||||||
|
HOSTATTEMPT | host.attempt
|
||||||
|
MAXHOSTATTEMPT | host.maxattempt
|
||||||
|
LASTHOSTSTATE | host.laststate
|
||||||
|
LASTHOSTSTATEID | host.laststateid
|
||||||
|
LASTHOSTSTATETYPE | host.laststatetype
|
||||||
|
LASTHOSTSTATECHANGE | host.laststatechange
|
||||||
|
HOSTDURATIONSEC | host.durationsec
|
||||||
|
HOSTLATENCY | host.latency
|
||||||
|
HOSTEXECUTIONTIME | host.executiontime
|
||||||
|
HOSTOUTPUT | host.output
|
||||||
|
HOSTPERFDATA | host.perfdata
|
||||||
|
LASTHOSTCHECK | host.lastcheck
|
||||||
|
HOSTADDRESS | --
|
||||||
|
HOSTADDRESS6 | --
|
||||||
|
|
||||||
Changes to global runtime macros:
|
Changes to global runtime macros:
|
||||||
|
|
||||||
Icinga 1.x | Icinga 2
|
Icinga 1.x | Icinga 2
|
||||||
|
|
|
@ -258,113 +258,124 @@ String Host::StateTypeToString(StateType type)
|
||||||
|
|
||||||
bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
|
bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
|
||||||
{
|
{
|
||||||
if (macro == "HOSTNAME") {
|
/* require prefix for object macros */
|
||||||
*result = GetName();
|
if (macro.SubStr(0, 5) == "host.") {
|
||||||
return true;
|
String key = macro.SubStr(5);
|
||||||
}
|
|
||||||
else if (macro == "HOSTDISPLAYNAME" || macro == "HOSTALIAS") {
|
|
||||||
*result = GetDisplayName();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckResult::Ptr cr = GetLastCheckResult();
|
if (key == "name") {
|
||||||
|
*result = GetName();
|
||||||
if (macro == "HOSTSTATE") {
|
return true;
|
||||||
switch (GetState()) {
|
}
|
||||||
case HostUnreachable:
|
else if (key == "displaymane") {
|
||||||
*result = "UNREACHABLE";
|
*result = GetDisplayName();
|
||||||
break;
|
|
||||||
case HostUp:
|
|
||||||
*result = "UP";
|
|
||||||
break;
|
|
||||||
case HostDown:
|
|
||||||
*result = "DOWN";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTSTATEID") {
|
|
||||||
*result = Convert::ToString(GetState());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTSTATETYPE") {
|
|
||||||
*result = StateTypeToString(GetStateType());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTATTEMPT") {
|
|
||||||
*result = Convert::ToString(GetCheckAttempt());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "MAXHOSTATTEMPT") {
|
|
||||||
*result = Convert::ToString(GetMaxCheckAttempts());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTHOSTSTATE") {
|
|
||||||
*result = StateToString(GetLastState());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTHOSTSTATEID") {
|
|
||||||
*result = Convert::ToString(GetLastState());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTHOSTSTATETYPE") {
|
|
||||||
*result = StateTypeToString(GetLastStateType());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTHOSTSTATECHANGE") {
|
|
||||||
*result = Convert::ToString((long)GetLastStateChange());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTDURATIONSEC") {
|
|
||||||
*result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTCHECKCOMMAND") {
|
|
||||||
CheckCommand::Ptr commandObj = GetCheckCommand();
|
|
||||||
|
|
||||||
if (commandObj)
|
|
||||||
*result = commandObj->GetName();
|
|
||||||
else
|
|
||||||
*result = "";
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (cr) {
|
|
||||||
if (macro == "HOSTLATENCY") {
|
|
||||||
*result = Convert::ToString(Service::CalculateLatency(cr));
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTEXECUTIONTIME") {
|
|
||||||
*result = Convert::ToString(Service::CalculateExecutionTime(cr));
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTOUTPUT") {
|
|
||||||
*result = cr->GetOutput();
|
|
||||||
return true;
|
|
||||||
} else if (macro == "HOSTPERFDATA") {
|
|
||||||
*result = PluginUtility::FormatPerfdata(cr->GetPerformanceData());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTHOSTCHECK") {
|
|
||||||
*result = Convert::ToString((long)cr->GetScheduleStart());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary::Ptr vars = GetVars();
|
CheckResult::Ptr cr = GetLastCheckResult();
|
||||||
|
|
||||||
if (macro.SubStr(0, 5) == "_HOST") {
|
if (key == "state") {
|
||||||
*result = vars ? vars->Get(macro.SubStr(5)) : "";
|
switch (GetState()) {
|
||||||
return true;
|
case HostUnreachable:
|
||||||
}
|
*result = "UNREACHABLE";
|
||||||
|
break;
|
||||||
|
case HostUp:
|
||||||
|
*result = "UP";
|
||||||
|
break;
|
||||||
|
case HostDown:
|
||||||
|
*result = "DOWN";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
String name = macro;
|
return true;
|
||||||
|
} else if (key == "stateid") {
|
||||||
|
*result = Convert::ToString(GetState());
|
||||||
|
return true;
|
||||||
|
} else if (key == "statetype") {
|
||||||
|
*result = StateTypeToString(GetStateType());
|
||||||
|
return true;
|
||||||
|
} else if (key == "attempt") {
|
||||||
|
*result = Convert::ToString(GetCheckAttempt());
|
||||||
|
return true;
|
||||||
|
} else if (key == "maxattempt") {
|
||||||
|
*result = Convert::ToString(GetMaxCheckAttempts());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststate") {
|
||||||
|
*result = StateToString(GetLastState());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststateid") {
|
||||||
|
*result = Convert::ToString(GetLastState());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststatetype") {
|
||||||
|
*result = StateTypeToString(GetLastStateType());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststatechange") {
|
||||||
|
*result = Convert::ToString((long)GetLastStateChange());
|
||||||
|
return true;
|
||||||
|
} else if (key == "durationsec") {
|
||||||
|
*result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
|
||||||
|
return true;
|
||||||
|
} else if (key == "checkcommand") {
|
||||||
|
CheckCommand::Ptr commandObj = GetCheckCommand();
|
||||||
|
|
||||||
if (name == "HOSTADDRESS")
|
if (commandObj)
|
||||||
name = "address";
|
*result = commandObj->GetName();
|
||||||
else if (macro == "HOSTADDRESS6")
|
else
|
||||||
name = "address6";
|
*result = "";
|
||||||
|
|
||||||
if (vars && vars->Contains(name)) {
|
return true;
|
||||||
*result = vars->Get(name);
|
} else if (key == "totalservices" || key == "totalservicesok" || key == "totalserviceswarning"
|
||||||
return true;
|
|| key == "totalservicesunknown" || key == "totalservicescritical") {
|
||||||
}
|
int filter = -1;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
if (macro == "HOSTADDRESS" || macro == "HOSTADDRESS6") {
|
if (key == "totalservicesok")
|
||||||
*result = GetName();
|
filter = StateOK;
|
||||||
return true;
|
else if (key == "totalserviceswarning")
|
||||||
|
filter = StateWarning;
|
||||||
|
else if (key == "totalservicesunknown")
|
||||||
|
filter = StateUnknown;
|
||||||
|
else if (key == "totalservicescritical")
|
||||||
|
filter = StateCritical;
|
||||||
|
|
||||||
|
BOOST_FOREACH(const Service::Ptr& service, GetServices()) {
|
||||||
|
if (filter != -1 && service->GetState() != filter)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = Convert::ToString(count);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (cr) {
|
||||||
|
if (key == "latency") {
|
||||||
|
*result = Convert::ToString(Service::CalculateLatency(cr));
|
||||||
|
return true;
|
||||||
|
} else if (key == "executiontime") {
|
||||||
|
*result = Convert::ToString(Service::CalculateExecutionTime(cr));
|
||||||
|
return true;
|
||||||
|
} else if (key == "output") {
|
||||||
|
*result = cr->GetOutput();
|
||||||
|
return true;
|
||||||
|
} else if (key == "perfdata") {
|
||||||
|
*result = PluginUtility::FormatPerfdata(cr->GetPerformanceData());
|
||||||
|
return true;
|
||||||
|
} else if (key == "lastcheck") {
|
||||||
|
*result = Convert::ToString((long)cr->GetScheduleStart());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary::Ptr vars = GetVars();
|
||||||
|
|
||||||
|
if (vars && vars->Contains(key)) {
|
||||||
|
*result = vars->Get(key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -134,35 +134,34 @@ String IcingaApplication::GetNodeName(void) const
|
||||||
bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
|
bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
|
||||||
{
|
{
|
||||||
/* require icinga prefix for application macros */
|
/* require icinga prefix for application macros */
|
||||||
if (macro.SubStr(0, 7) != "icinga.")
|
if (macro.SubStr(0, 7) == "icinga.") {
|
||||||
return false;
|
String key = macro.SubStr(7);
|
||||||
|
|
||||||
String key = macro.SubStr(7);
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
double now = Utility::GetTime();
|
if (key == "timet") {
|
||||||
|
*result = Convert::ToString((long)now);
|
||||||
|
return true;
|
||||||
|
} else if (key == "longdatetime") {
|
||||||
|
*result = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", now);
|
||||||
|
return true;
|
||||||
|
} else if (key == "shortdatetime") {
|
||||||
|
*result = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", now);
|
||||||
|
return true;
|
||||||
|
} else if (key == "date") {
|
||||||
|
*result = Utility::FormatDateTime("%Y-%m-%d", now);
|
||||||
|
return true;
|
||||||
|
} else if (key == "time") {
|
||||||
|
*result = Utility::FormatDateTime("%H:%M:%S %z", now);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (key == "timet") {
|
Dictionary::Ptr vars = GetVars();
|
||||||
*result = Convert::ToString((long)now);
|
|
||||||
return true;
|
|
||||||
} else if (key == "longdatetime") {
|
|
||||||
*result = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", now);
|
|
||||||
return true;
|
|
||||||
} else if (key == "shortdatetime") {
|
|
||||||
*result = Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", now);
|
|
||||||
return true;
|
|
||||||
} else if (key == "date") {
|
|
||||||
*result = Utility::FormatDateTime("%Y-%m-%d", now);
|
|
||||||
return true;
|
|
||||||
} else if (key == "time") {
|
|
||||||
*result = Utility::FormatDateTime("%H:%M:%S %z", now);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary::Ptr vars = GetVars();
|
if (vars && vars->Contains(key)) {
|
||||||
|
*result = vars->Get(key);
|
||||||
if (vars && vars->Contains(key)) {
|
return true;
|
||||||
*result = vars->Get(key);
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -128,108 +128,84 @@ String Service::StateTypeToString(StateType type)
|
||||||
|
|
||||||
bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const
|
bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const
|
||||||
{
|
{
|
||||||
if (macro == "SERVICEDESC") {
|
/* require prefix for object macros */
|
||||||
*result = GetShortName();
|
if (macro.SubStr(0, 8) == "service.") {
|
||||||
return true;
|
String key = macro.SubStr(8);
|
||||||
} else if (macro == "SERVICEDISPLAYNAME") {
|
|
||||||
*result = GetDisplayName();
|
|
||||||
return true;
|
|
||||||
} else if (macro == "SERVICECHECKCOMMAND") {
|
|
||||||
CheckCommand::Ptr commandObj = GetCheckCommand();
|
|
||||||
|
|
||||||
if (commandObj)
|
if (key == "description") {
|
||||||
*result = commandObj->GetName();
|
*result = GetShortName();
|
||||||
else
|
|
||||||
*result = "";
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (macro == "SERVICESTATE") {
|
|
||||||
*result = StateToString(GetState());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "SERVICESTATEID") {
|
|
||||||
*result = Convert::ToString(GetState());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "SERVICESTATETYPE") {
|
|
||||||
*result = StateTypeToString(GetStateType());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "SERVICEATTEMPT") {
|
|
||||||
*result = Convert::ToString(GetCheckAttempt());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "MAXSERVICEATTEMPT") {
|
|
||||||
*result = Convert::ToString(GetMaxCheckAttempts());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTSERVICESTATE") {
|
|
||||||
*result = StateToString(GetLastState());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTSERVICESTATEID") {
|
|
||||||
*result = Convert::ToString(GetLastState());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTSERVICESTATETYPE") {
|
|
||||||
*result = StateTypeToString(GetLastStateType());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "LASTSERVICESTATECHANGE") {
|
|
||||||
*result = Convert::ToString((long)GetLastStateChange());
|
|
||||||
return true;
|
|
||||||
} else if (macro == "SERVICEDURATIONSEC") {
|
|
||||||
*result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
|
|
||||||
return true;
|
|
||||||
} else if (macro == "TOTALHOSTSERVICES" || macro == "TOTALHOSTSERVICESOK" || macro == "TOTALHOSTSERVICESWARNING"
|
|
||||||
|| macro == "TOTALHOSTSERVICESUNKNOWN" || macro == "TOTALHOSTSERVICESCRITICAL") {
|
|
||||||
int filter = -1;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
if (macro == "TOTALHOSTSERVICESOK")
|
|
||||||
filter = StateOK;
|
|
||||||
else if (macro == "TOTALHOSTSERVICESWARNING")
|
|
||||||
filter = StateWarning;
|
|
||||||
else if (macro == "TOTALHOSTSERVICESUNKNOWN")
|
|
||||||
filter = StateUnknown;
|
|
||||||
else if (macro == "TOTALHOSTSERVICESCRITICAL")
|
|
||||||
filter = StateCritical;
|
|
||||||
|
|
||||||
BOOST_FOREACH(const Service::Ptr& service, GetHost()->GetServices()) {
|
|
||||||
if (filter != -1 && service->GetState() != filter)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
*result = Convert::ToString(count);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cr) {
|
|
||||||
if (macro == "SERVICELATENCY") {
|
|
||||||
*result = Convert::ToString(Service::CalculateLatency(cr));
|
|
||||||
return true;
|
return true;
|
||||||
} else if (macro == "SERVICEEXECUTIONTIME") {
|
} else if (key == "displayname") {
|
||||||
*result = Convert::ToString(Service::CalculateExecutionTime(cr));
|
*result = GetDisplayName();
|
||||||
return true;
|
return true;
|
||||||
} else if (macro == "SERVICEOUTPUT") {
|
} else if (key == "checkcommand") {
|
||||||
*result = cr->GetOutput();
|
CheckCommand::Ptr commandObj = GetCheckCommand();
|
||||||
return true;
|
|
||||||
} else if (macro == "SERVICEPERFDATA") {
|
if (commandObj)
|
||||||
*result = PluginUtility::FormatPerfdata(cr->GetPerformanceData());
|
*result = commandObj->GetName();
|
||||||
return true;
|
else
|
||||||
} else if (macro == "LASTSERVICECHECK") {
|
*result = "";
|
||||||
*result = Convert::ToString((long)cr->GetExecutionEnd());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary::Ptr vars = GetVars();
|
if (key == "state") {
|
||||||
|
*result = StateToString(GetState());
|
||||||
|
return true;
|
||||||
|
} else if (key == "stateid") {
|
||||||
|
*result = Convert::ToString(GetState());
|
||||||
|
return true;
|
||||||
|
} else if (key == "statetype") {
|
||||||
|
*result = StateTypeToString(GetStateType());
|
||||||
|
return true;
|
||||||
|
} else if (key == "attempt") {
|
||||||
|
*result = Convert::ToString(GetCheckAttempt());
|
||||||
|
return true;
|
||||||
|
} else if (key == "maxattempt") {
|
||||||
|
*result = Convert::ToString(GetMaxCheckAttempts());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststate") {
|
||||||
|
*result = StateToString(GetLastState());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststateid") {
|
||||||
|
*result = Convert::ToString(GetLastState());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststatetype") {
|
||||||
|
*result = StateTypeToString(GetLastStateType());
|
||||||
|
return true;
|
||||||
|
} else if (key == "laststatechange") {
|
||||||
|
*result = Convert::ToString((long)GetLastStateChange());
|
||||||
|
return true;
|
||||||
|
} else if (key == "durationsec") {
|
||||||
|
*result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (macro.SubStr(0, 8) == "_SERVICE") {
|
if (cr) {
|
||||||
*result = vars ? vars->Get(macro.SubStr(8)) : "";
|
if (key == "latency") {
|
||||||
return true;
|
*result = Convert::ToString(Service::CalculateLatency(cr));
|
||||||
}
|
return true;
|
||||||
|
} else if (key == "executiontime") {
|
||||||
|
*result = Convert::ToString(Service::CalculateExecutionTime(cr));
|
||||||
|
return true;
|
||||||
|
} else if (key == "output") {
|
||||||
|
*result = cr->GetOutput();
|
||||||
|
return true;
|
||||||
|
} else if (key == "perfdata") {
|
||||||
|
*result = PluginUtility::FormatPerfdata(cr->GetPerformanceData());
|
||||||
|
return true;
|
||||||
|
} else if (key == "lastcheck") {
|
||||||
|
*result = Convert::ToString((long)cr->GetExecutionEnd());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary::Ptr vars = GetVars();
|
||||||
|
|
||||||
if (vars && vars->Contains(macro)) {
|
if (vars && vars->Contains(key)) {
|
||||||
*result = vars->Get(macro);
|
*result = vars->Get(key);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue