| 415 | } |
| 416 | |
| 417 | void 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 | |
| 459 | String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts) |
| 460 | { |
nothing calls this directly
no test coverage detected