* Check result event handler, checks whether feature is not paused in HA setups. * * @param checkable Host/Service object * @param cr Check result including performance data */
| 258 | * @param cr Check result including performance data |
| 259 | */ |
| 260 | void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr) |
| 261 | { |
| 262 | if (IsPaused()) |
| 263 | return; |
| 264 | |
| 265 | if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata()) |
| 266 | return; |
| 267 | |
| 268 | Host::Ptr host; |
| 269 | Service::Ptr service; |
| 270 | tie(host, service) = GetHostService(checkable); |
| 271 | |
| 272 | MacroProcessor::ResolverList resolvers; |
| 273 | if (service) |
| 274 | resolvers.emplace_back("service", service); |
| 275 | resolvers.emplace_back("host", host); |
| 276 | |
| 277 | String prefix; |
| 278 | |
| 279 | if (service) { |
| 280 | prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, nullptr, [](const Value& value) -> Value { |
| 281 | return EscapeMacroMetric(value); |
| 282 | }); |
| 283 | } else { |
| 284 | prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, nullptr, [](const Value& value) -> Value { |
| 285 | return EscapeMacroMetric(value); |
| 286 | }); |
| 287 | } |
| 288 | |
| 289 | std::vector<std::pair<String, double>> metadata; |
| 290 | if (GetEnableSendMetadata()) { |
| 291 | metadata = { |
| 292 | {"state", service ? static_cast<unsigned int>(service->GetState()) : static_cast<unsigned int>(host->GetState())}, |
| 293 | {"current_attempt", checkable->GetCheckAttempt()}, |
| 294 | {"max_check_attempts", checkable->GetMaxCheckAttempts()}, |
| 295 | {"state_type", checkable->GetStateType()}, |
| 296 | {"reachable", checkable->IsReachable()}, |
| 297 | {"downtime_depth", checkable->GetDowntimeDepth()}, |
| 298 | {"acknowledgement", checkable->GetAcknowledgement()}, |
| 299 | {"latency", cr->CalculateLatency()}, |
| 300 | {"execution_time", cr->CalculateExecutionTime()} |
| 301 | }; |
| 302 | } |
| 303 | |
| 304 | m_WorkQueue.Enqueue([this, checkable, cr, prefix = std::move(prefix), metadata = std::move(metadata)]() { |
| 305 | CONTEXT("Processing check result for '" << checkable->GetName() << "'"); |
| 306 | |
| 307 | /* TODO: Deal with missing connection here. Needs refactoring |
| 308 | * into parsing the actual performance data and then putting it |
| 309 | * into a queue for re-inserting. */ |
| 310 | |
| 311 | for (auto& [name, val] : metadata) { |
| 312 | SendMetric(checkable, prefix + ".metadata", name, val, cr->GetExecutionEnd()); |
| 313 | } |
| 314 | |
| 315 | SendPerfdata(checkable, prefix + ".perfdata", cr); |
| 316 | }); |
| 317 | } |
nothing calls this directly
no test coverage detected