diff --git a/doc/6-object-types.md b/doc/6-object-types.md index fd650a611..b6b628166 100644 --- a/doc/6-object-types.md +++ b/doc/6-object-types.md @@ -502,6 +502,7 @@ Configuration Attributes: host |**Optional.** GELF receiver host address. Defaults to '127.0.0.1'. port |**Optional.** GELF receiver port. Defaults to `12201`. source |**Optional.** Source name for this instance. Defaults to `icinga2`. + enable_send_perfdata |**Optional.** Enable performance data for 'CHECK RESULT' events. ## GraphiteWriter diff --git a/etc/icinga2/features-available/gelf.conf b/etc/icinga2/features-available/gelf.conf index 43ea7aae5..2db44ef7e 100644 --- a/etc/icinga2/features-available/gelf.conf +++ b/etc/icinga2/features-available/gelf.conf @@ -1,7 +1,7 @@ /** * The GelfWriter type writes event log entries - * to a GELF tcp socket provided by graylog2, - * logstash or any other receiver. + * to a GELF tcp socket provided by Graylog, + * Logstash or any other receiver. */ library "perfdata" diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index d883fe51c..a098e76b2 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -33,6 +33,8 @@ #include "base/networkstream.hpp" #include "base/json.hpp" #include "base/context.hpp" +#include +#include using namespace icinga; @@ -107,12 +109,56 @@ void GelfWriter::CheckResultHandler(const Checkable::Ptr& checkable, const Check fields->Set("_current_check_attempt", checkable->GetCheckAttempt()); fields->Set("_max_check_attempts", checkable->GetMaxCheckAttempts()); + fields->Set("_latency", Service::CalculateLatency(cr)); + fields->Set("_execution_time", Service::CalculateExecutionTime(cr)); + fields->Set("_reachable", checkable->IsReachable()); + if (cr) { fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr)); fields->Set("full_message", CompatUtility::GetCheckResultLongOutput(cr)); fields->Set("_check_source", cr->GetCheckSource()); } + if (GetEnableSendPerfdata()) { + Array::Ptr perfdata = cr->GetPerformanceData(); + + if (perfdata) { + ObjectLock olock(perfdata); + BOOST_FOREACH(const Value& val, perfdata) { + PerfdataValue::Ptr pdv; + + if (val.IsObjectType()) + pdv = val; + else { + try { + pdv = PerfdataValue::Parse(val); + + String escaped_key = pdv->GetLabel(); + boost::replace_all(escaped_key, " ", "_"); + boost::replace_all(escaped_key, ".", "_"); + boost::replace_all(escaped_key, "\\", "_"); + boost::algorithm::replace_all(escaped_key, "::", "."); + + fields->Set("_" + escaped_key, pdv->GetValue()); + + if (pdv->GetMin()) + fields->Set("_" + escaped_key + "_min", pdv->GetMin()); + if (pdv->GetMax()) + fields->Set("_" + escaped_key + "_max", pdv->GetMax()); + if (pdv->GetWarn()) + fields->Set("_" + escaped_key + "_warn", pdv->GetWarn()); + if (pdv->GetCrit()) + fields->Set("_" + escaped_key + "_crit", pdv->GetCrit()); + } catch (const std::exception&) { + Log(LogWarning, "GelfWriter") + << "Ignoring invalid perfdata value: '" << val << "' for object '" + << checkable-GetName() << "'."; + } + } + } + } + } + SendLogMessage(ComposeGelfMessage(fields, GetSource())); } diff --git a/lib/perfdata/gelfwriter.ti b/lib/perfdata/gelfwriter.ti index 1f7fdc16c..bdfa2a87b 100644 --- a/lib/perfdata/gelfwriter.ti +++ b/lib/perfdata/gelfwriter.ti @@ -35,6 +35,9 @@ class GelfWriter : ConfigObject [config] String source { default {{{ return "icinga2"; }}} }; + [config] bool enable_send_perfdata { + default {{{ return false; }}} + }; }; }