| 325 | } |
| 326 | |
| 327 | void ElasticsearchWriter::NotificationSentToAllUsersHandler(const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, |
| 328 | NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text) |
| 329 | { |
| 330 | if (IsPaused()) |
| 331 | return; |
| 332 | |
| 333 | Host::Ptr host; |
| 334 | Service::Ptr service; |
| 335 | tie(host, service) = GetHostService(checkable); |
| 336 | |
| 337 | String notificationTypeString = Notification::NotificationTypeToStringCompat(type); //TODO: Change that to our own types. |
| 338 | |
| 339 | Dictionary::Ptr fields = new Dictionary(); |
| 340 | |
| 341 | if (service) { |
| 342 | fields->Set("service", service->GetShortName()); |
| 343 | fields->Set("state", service->GetState()); |
| 344 | fields->Set("last_state", service->GetLastState()); |
| 345 | fields->Set("last_hard_state", service->GetLastHardState()); |
| 346 | } else { |
| 347 | fields->Set("state", host->GetState()); |
| 348 | fields->Set("last_state", host->GetLastState()); |
| 349 | fields->Set("last_hard_state", host->GetLastHardState()); |
| 350 | } |
| 351 | |
| 352 | fields->Set("host", host->GetName()); |
| 353 | |
| 354 | ArrayData userNames; |
| 355 | |
| 356 | for (const User::Ptr& user : users) { |
| 357 | userNames.push_back(user->GetName()); |
| 358 | } |
| 359 | |
| 360 | fields->Set("users", new Array(std::move(userNames))); |
| 361 | fields->Set("notification_type", notificationTypeString); |
| 362 | fields->Set("author", author); |
| 363 | fields->Set("text", text); |
| 364 | fields->Set("check_command", checkable->GetCheckCommand()->GetName()); |
| 365 | |
| 366 | AddTemplateTags(fields, checkable, cr); |
| 367 | |
| 368 | m_WorkQueue.Enqueue([this, checkable, cr, fields = std::move(fields)]() { |
| 369 | CONTEXT("Elasticwriter processing notification to all users '" << checkable->GetName() << "'"); |
| 370 | |
| 371 | Log(LogDebug, "ElasticsearchWriter") |
| 372 | << "Processing notification for '" << checkable->GetName() << "'"; |
| 373 | |
| 374 | double ts = Utility::GetTime(); |
| 375 | |
| 376 | if (cr) { |
| 377 | AddCheckResult(fields, checkable, cr); |
| 378 | ts = cr->GetExecutionEnd(); |
| 379 | } |
| 380 | |
| 381 | Enqueue(checkable, "notification", fields, ts); |
| 382 | }); |
| 383 | } |
| 384 |
nothing calls this directly
no test coverage detected