diff --git a/doc/3.03-macros.md b/doc/3.03-macros.md index df595eb64..9ac62ca42 100644 --- a/doc/3.03-macros.md +++ b/doc/3.03-macros.md @@ -131,6 +131,11 @@ services: SERVICEOUTPUT | The last check's output. SERVICEPERFDATA | The last check's performance data. LASTSERVICECHECK | 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. ### User Macros diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 5092640ec..bd56df284 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -427,6 +427,29 @@ bool Service::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, Strin } 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) {