@@ -94,14 +94,14 @@ void GelfWriter::Resume()
94
94
const CheckResult::Ptr& cr, const MessageOrigin::Ptr&) {
95
95
CheckResultHandler (checkable, cr);
96
96
});
97
- m_HandleNotifications = Checkable::OnNotificationSentToUser.connect ([this ](const Notification::Ptr& notification ,
98
- const Checkable::Ptr& checkable, const User::Ptr& user , const NotificationType& type, const CheckResult::Ptr& cr,
97
+ m_HandleNotifications = Checkable::OnNotificationSentToUser.connect ([this ](const Notification::Ptr&,
98
+ const Checkable::Ptr& checkable, const User::Ptr&, const NotificationType& type, const CheckResult::Ptr& cr,
99
99
const String& author, const String& commentText, const String& commandName, const MessageOrigin::Ptr&) {
100
- NotificationToUserHandler (notification, checkable, user , type, cr, author, commentText, commandName);
100
+ NotificationToUserHandler (checkable, type, cr, author, commentText, commandName);
101
101
});
102
102
m_HandleStateChanges = Checkable::OnStateChange.connect ([this ](const Checkable::Ptr& checkable,
103
- const CheckResult::Ptr& cr, StateType type , const MessageOrigin::Ptr&) {
104
- StateChangeHandler (checkable, cr, type );
103
+ const CheckResult::Ptr& cr, StateType, const MessageOrigin::Ptr&) {
104
+ StateChangeHandler (checkable, cr);
105
105
});
106
106
}
107
107
@@ -268,18 +268,6 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check
268
268
if (IsPaused ())
269
269
return ;
270
270
271
- m_WorkQueue.Enqueue ([this , checkable, cr]() { CheckResultHandlerInternal (checkable, cr); });
272
- }
273
-
274
- void GelfWriter::CheckResultHandlerInternal (const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
275
- {
276
- AssertOnWorkQueue ();
277
-
278
- CONTEXT (" GELF Processing check result for '" << checkable->GetName () << " '" );
279
-
280
- Log (LogDebug, " GelfWriter" )
281
- << " Processing check result for '" << checkable->GetName () << " '" ;
282
-
283
271
Host::Ptr host;
284
272
Service::Ptr service;
285
273
tie (host, service) = GetHostService (checkable);
@@ -306,22 +294,15 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
306
294
fields->Set (" _reachable" , checkable->IsReachable ());
307
295
308
296
CheckCommand::Ptr checkCommand = checkable->GetCheckCommand ();
297
+ fields->Set (" _check_command" , checkCommand->GetName ());
309
298
310
- if (checkCommand)
311
- fields->Set (" _check_command" , checkCommand->GetName ());
312
-
313
- double ts = Utility::GetTime ();
314
-
315
- if (cr) {
316
- fields->Set (" _latency" , cr->CalculateLatency ());
317
- fields->Set (" _execution_time" , cr->CalculateExecutionTime ());
318
- fields->Set (" short_message" , CompatUtility::GetCheckResultOutput (cr));
319
- fields->Set (" full_message" , cr->GetOutput ());
320
- fields->Set (" _check_source" , cr->GetCheckSource ());
321
- ts = cr->GetExecutionEnd ();
322
- }
299
+ fields->Set (" _latency" , cr->CalculateLatency ());
300
+ fields->Set (" _execution_time" , cr->CalculateExecutionTime ());
301
+ fields->Set (" short_message" , CompatUtility::GetCheckResultOutput (cr));
302
+ fields->Set (" full_message" , cr->GetOutput ());
303
+ fields->Set (" _check_source" , cr->GetCheckSource ());
323
304
324
- if (cr && GetEnableSendPerfdata ()) {
305
+ if (GetEnableSendPerfdata ()) {
325
306
Array::Ptr perfdata = cr->GetPerformanceData ();
326
307
327
308
if (perfdata) {
@@ -366,31 +347,21 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
366
347
}
367
348
}
368
349
369
- SendLogMessage ( checkable, ComposeGelfMessage ( fields, GetSource ( ), ts));
370
- }
350
+ m_WorkQueue. Enqueue ([ this , checkable, fields = std::move (fields ), ts = cr-> GetExecutionEnd ()]() {
351
+ CONTEXT ( " GELF Processing check result for ' " << checkable-> GetName () << " ' " );
371
352
372
- void GelfWriter::NotificationToUserHandler (const Notification::Ptr& notification, const Checkable::Ptr& checkable,
373
- const User::Ptr& user, NotificationType notificationType, CheckResult::Ptr const & cr,
374
- const String& author, const String& commentText, const String& commandName)
375
- {
376
- if (IsPaused ())
377
- return ;
353
+ Log (LogDebug, " GelfWriter" )
354
+ << " Processing check result for '" << checkable->GetName () << " '" ;
378
355
379
- m_WorkQueue.Enqueue ([this , notification, checkable, user, notificationType, cr, author, commentText, commandName]() {
380
- NotificationToUserHandlerInternal (notification, checkable, user, notificationType, cr, author, commentText, commandName);
356
+ SendLogMessage (checkable, ComposeGelfMessage (fields, GetSource (), ts));
381
357
});
382
358
}
383
359
384
- void GelfWriter::NotificationToUserHandlerInternal (const Notification::Ptr& notification, const Checkable::Ptr& checkable,
385
- const User::Ptr& user, NotificationType notificationType, CheckResult::Ptr const & cr,
386
- const String& author, const String& commentText, const String& commandName)
360
+ void GelfWriter::NotificationToUserHandler (const Checkable::Ptr& checkable, NotificationType notificationType,
361
+ const CheckResult::Ptr& cr, const String& author, const String& commentText, const String& commandName)
387
362
{
388
- AssertOnWorkQueue ();
389
-
390
- CONTEXT (" GELF Processing notification to all users '" << checkable->GetName () << " '" );
391
-
392
- Log (LogDebug, " GelfWriter" )
393
- << " Processing notification for '" << checkable->GetName () << " '" ;
363
+ if (IsPaused ())
364
+ return ;
394
365
395
366
Host::Ptr host;
396
367
Service::Ptr service;
@@ -430,32 +401,23 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti
430
401
fields->Set (" _command" , commandName);
431
402
fields->Set (" _notification_type" , notificationTypeString);
432
403
fields->Set (" _comment" , authorComment);
404
+ fields->Set (" _check_command" , checkable->GetCheckCommand ()->GetName ());
433
405
434
- CheckCommand::Ptr commandObj = checkable->GetCheckCommand ();
406
+ m_WorkQueue.Enqueue ([this , checkable, ts, fields = std::move (fields)]() {
407
+ CONTEXT (" GELF Processing notification to all users '" << checkable->GetName () << " '" );
435
408
436
- if (commandObj )
437
- fields-> Set ( " _check_command " , commandObj ->GetName ()) ;
409
+ Log (LogDebug, " GelfWriter " )
410
+ << " Processing notification for ' " << checkable ->GetName () << " ' " ;
438
411
439
- SendLogMessage (checkable, ComposeGelfMessage (fields, GetSource (), ts));
412
+ SendLogMessage (checkable, ComposeGelfMessage (fields, GetSource (), ts));
413
+ });
440
414
}
441
415
442
- void GelfWriter::StateChangeHandler (const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type )
416
+ void GelfWriter::StateChangeHandler (const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
443
417
{
444
418
if (IsPaused ())
445
419
return ;
446
420
447
- m_WorkQueue.Enqueue ([this , checkable, cr, type]() { StateChangeHandlerInternal (checkable, cr, type); });
448
- }
449
-
450
- void GelfWriter::StateChangeHandlerInternal (const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
451
- {
452
- AssertOnWorkQueue ();
453
-
454
- CONTEXT (" GELF Processing state change '" << checkable->GetName () << " '" );
455
-
456
- Log (LogDebug, " GelfWriter" )
457
- << " Processing state change for '" << checkable->GetName () << " '" ;
458
-
459
421
Host::Ptr host;
460
422
Service::Ptr service;
461
423
tie (host, service) = GetHostService (checkable);
@@ -478,21 +440,20 @@ void GelfWriter::StateChangeHandlerInternal(const Checkable::Ptr& checkable, con
478
440
fields->Set (" _last_hard_state" , host->GetLastHardState ());
479
441
}
480
442
481
- CheckCommand::Ptr commandObj = checkable->GetCheckCommand ();
443
+ fields-> Set ( " _check_command " , checkable->GetCheckCommand ()-> GetName () );
482
444
483
- if (commandObj)
484
- fields->Set (" _check_command" , commandObj->GetName ());
445
+ fields->Set (" short_message" , CompatUtility::GetCheckResultOutput (cr));
446
+ fields->Set (" full_message" , cr->GetOutput ());
447
+ fields->Set (" _check_source" , cr->GetCheckSource ());
485
448
486
- double ts = Utility::GetTime ();
449
+ m_WorkQueue.Enqueue ([this , checkable, fields = std::move (fields), ts = cr->GetExecutionEnd ()]() {
450
+ CONTEXT (" GELF Processing state change '" << checkable->GetName () << " '" );
487
451
488
- if (cr) {
489
- fields->Set (" short_message" , CompatUtility::GetCheckResultOutput (cr));
490
- fields->Set (" full_message" , cr->GetOutput ());
491
- fields->Set (" _check_source" , cr->GetCheckSource ());
492
- ts = cr->GetExecutionEnd ();
493
- }
452
+ Log (LogDebug, " GelfWriter" )
453
+ << " Processing state change for '" << checkable->GetName () << " '" ;
494
454
495
- SendLogMessage (checkable, ComposeGelfMessage (fields, GetSource (), ts));
455
+ SendLogMessage (checkable, ComposeGelfMessage (fields, GetSource (), ts));
456
+ });
496
457
}
497
458
498
459
String GelfWriter::ComposeGelfMessage (const Dictionary::Ptr& fields, const String& source, double ts)
@@ -506,6 +467,8 @@ String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const Strin
506
467
507
468
void GelfWriter::SendLogMessage (const Checkable::Ptr& checkable, const String& gelfMessage)
508
469
{
470
+ AssertOnWorkQueue ();
471
+
509
472
std::ostringstream msgbuf;
510
473
msgbuf << gelfMessage;
511
474
msgbuf << ' \0 ' ;
0 commit comments