From 89ac5b2fff28469e890eeb550c91952e521ac031 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 6 Jun 2017 20:14:21 +0200 Subject: [PATCH] GelfWriter: Add 'check_command' to CHECK RESULT/* NOTIFICATION/STATE CHANGE messages This allows for much more easy filtering in Graylog web similar to Graphite or InfluxDB and their template dashboards. --- lib/perfdata/gelfwriter.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index b9d43bdd9..f8798d4f6 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -21,6 +21,7 @@ #include "perfdata/gelfwriter.tcpp" #include "icinga/service.hpp" #include "icinga/notification.hpp" +#include "icinga/checkcommand.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/compatutility.hpp" #include "base/tcpsocket.hpp" @@ -220,6 +221,11 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con fields->Set("_reachable", checkable->IsReachable()); + CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); + + if (commandObj) + fields->Set("_check_command", commandObj->GetName()); + double ts = Utility::GetTime(); if (cr) { @@ -317,6 +323,7 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti if (service) { fields->Set("_type", "SERVICE NOTIFICATION"); + //TODO: fix this to _service_name fields->Set("_service", service->GetShortName()); fields->Set("short_message", output); } else { @@ -332,6 +339,11 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti fields->Set("_notification_type", notificationTypeString); fields->Set("_comment", authorComment); + CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); + + if (commandObj) + fields->Set("_check_command", commandObj->GetName()); + SendLogMessage(ComposeGelfMessage(fields, GetSource(), ts)); } @@ -371,6 +383,11 @@ void GelfWriter::StateChangeHandlerInternal(const Checkable::Ptr& checkable, con fields->Set("_last_hard_state", host->GetLastHardState()); } + CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); + + if (commandObj) + fields->Set("_check_command", commandObj->GetName()); + double ts = Utility::GetTime(); if (cr) {