Merge pull request #5331 from Icinga/feature/gelf-add-check-command

GelfWriter: Add 'check_command' to CHECK RESULT/* NOTIFICATION/STATE CHANGE messages
This commit is contained in:
Michael Friedrich 2017-06-06 20:36:47 +02:00 committed by GitHub
commit 5ab928f819
1 changed files with 17 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "perfdata/gelfwriter.tcpp" #include "perfdata/gelfwriter.tcpp"
#include "icinga/service.hpp" #include "icinga/service.hpp"
#include "icinga/notification.hpp" #include "icinga/notification.hpp"
#include "icinga/checkcommand.hpp"
#include "icinga/macroprocessor.hpp" #include "icinga/macroprocessor.hpp"
#include "icinga/compatutility.hpp" #include "icinga/compatutility.hpp"
#include "base/tcpsocket.hpp" #include "base/tcpsocket.hpp"
@ -220,6 +221,11 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
fields->Set("_reachable", checkable->IsReachable()); fields->Set("_reachable", checkable->IsReachable());
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
if (commandObj)
fields->Set("_check_command", commandObj->GetName());
double ts = Utility::GetTime(); double ts = Utility::GetTime();
if (cr) { if (cr) {
@ -317,6 +323,7 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti
if (service) { if (service) {
fields->Set("_type", "SERVICE NOTIFICATION"); fields->Set("_type", "SERVICE NOTIFICATION");
//TODO: fix this to _service_name
fields->Set("_service", service->GetShortName()); fields->Set("_service", service->GetShortName());
fields->Set("short_message", output); fields->Set("short_message", output);
} else { } else {
@ -332,6 +339,11 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti
fields->Set("_notification_type", notificationTypeString); fields->Set("_notification_type", notificationTypeString);
fields->Set("_comment", authorComment); fields->Set("_comment", authorComment);
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
if (commandObj)
fields->Set("_check_command", commandObj->GetName());
SendLogMessage(ComposeGelfMessage(fields, GetSource(), ts)); SendLogMessage(ComposeGelfMessage(fields, GetSource(), ts));
} }
@ -371,6 +383,11 @@ void GelfWriter::StateChangeHandlerInternal(const Checkable::Ptr& checkable, con
fields->Set("_last_hard_state", host->GetLastHardState()); fields->Set("_last_hard_state", host->GetLastHardState());
} }
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
if (commandObj)
fields->Set("_check_command", commandObj->GetName());
double ts = Utility::GetTime(); double ts = Utility::GetTime();
if (cr) { if (cr) {