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

Method NotificationSentToAllUsersHandler

lib/perfdata/elasticsearchwriter.cpp:327–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327void 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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected