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

Method NotificationToUserHandler

lib/perfdata/gelfwriter.cpp:361–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361void GelfWriter::NotificationToUserHandler(const Checkable::Ptr& checkable, NotificationType notificationType,
362 const CheckResult::Ptr& cr, const String& author, const String& commentText, const String& commandName)
363{
364 if (IsPaused())
365 return;
366
367 Host::Ptr host;
368 Service::Ptr service;
369 tie(host, service) = GetHostService(checkable);
370
371 String notificationTypeString = Notification::NotificationTypeToStringCompat(notificationType); //TODO: Change that to our own types.
372
373 String authorComment = "";
374
375 if (notificationType == NotificationCustom || notificationType == NotificationAcknowledgement) {
376 authorComment = author + ";" + commentText;
377 }
378
379 String output;
380 double ts = Utility::GetTime();
381
382 if (cr) {
383 output = CompatUtility::GetCheckResultOutput(cr);
384 ts = cr->GetExecutionEnd();
385 }
386
387 Dictionary::Ptr fields = new Dictionary();
388
389 if (service) {
390 fields->Set("_type", "SERVICE NOTIFICATION");
391 //TODO: fix this to _service_name
392 fields->Set("_service", service->GetShortName());
393 fields->Set("short_message", output);
394 } else {
395 fields->Set("_type", "HOST NOTIFICATION");
396 fields->Set("short_message", output);
397 }
398
399 fields->Set("_state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
400
401 fields->Set("_hostname", host->GetName());
402 fields->Set("_command", commandName);
403 fields->Set("_notification_type", notificationTypeString);
404 fields->Set("_comment", authorComment);
405 fields->Set("_check_command", checkable->GetCheckCommand()->GetName());
406
407 m_WorkQueue.Enqueue([this, checkable, ts, fields = std::move(fields)]() {
408 CONTEXT("GELF Processing notification to all users '" << checkable->GetName() << "'");
409
410 Log(LogDebug, "GelfWriter")
411 << "Processing notification for '" << checkable->GetName() << "'";
412
413 SendLogMessage(checkable, ComposeGelfMessage(fields, GetSource(), ts));
414 });
415}
416
417void GelfWriter::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
418{

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected