MCPcopy Create free account
hub / github.com/Icinga/icinga2 / StateChangeHandler

Method StateChangeHandler

lib/perfdata/gelfwriter.cpp:417–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
418{
419 if (IsPaused())
420 return;
421
422 Host::Ptr host;
423 Service::Ptr service;
424 tie(host, service) = GetHostService(checkable);
425
426 Dictionary::Ptr fields = new Dictionary();
427
428 fields->Set("_state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
429 fields->Set("_type", "STATE CHANGE");
430 fields->Set("_current_check_attempt", checkable->GetCheckAttempt());
431 fields->Set("_max_check_attempts", checkable->GetMaxCheckAttempts());
432 fields->Set("_hostname", host->GetName());
433
434 if (service) {
435 fields->Set("_service_name", service->GetShortName());
436 fields->Set("_service_state", Service::StateToString(service->GetState()));
437 fields->Set("_last_state", service->GetLastState());
438 fields->Set("_last_hard_state", service->GetLastHardState());
439 } else {
440 fields->Set("_last_state", host->GetLastState());
441 fields->Set("_last_hard_state", host->GetLastHardState());
442 }
443
444 fields->Set("_check_command", checkable->GetCheckCommand()->GetName());
445 fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr));
446 fields->Set("full_message", cr->GetOutput());
447 fields->Set("_check_source", cr->GetCheckSource());
448
449 m_WorkQueue.Enqueue([this, checkable, fields = std::move(fields), ts = cr->GetExecutionEnd()]() {
450 CONTEXT("GELF Processing state change '" << checkable->GetName() << "'");
451
452 Log(LogDebug, "GelfWriter")
453 << "Processing state change for '" << checkable->GetName() << "'";
454
455 SendLogMessage(checkable, ComposeGelfMessage(fields, GetSource(), ts));
456 });
457}
458
459String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts)
460{

Callers

nothing calls this directly

Calls 8

LogClass · 0.85
GetLastStateMethod · 0.80
GetLastHardStateMethod · 0.80
GetCheckCommandMethod · 0.80
SetMethod · 0.45
GetStateMethod · 0.45
GetNameMethod · 0.45
EnqueueMethod · 0.45

Tested by

no test coverage detected