]> granicus.if.org Git - icinga2/commitdiff
GelfWriter: Add additional fields for 'CHECK RESULT' events
authorDaniil Yaroslavtsev <dyaroslavtsev@confyrm.com>
Thu, 6 Aug 2015 12:13:00 +0000 (15:13 +0300)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 18 Dec 2015 10:05:38 +0000 (11:05 +0100)
fixes #9858

doc/6-object-types.md
etc/icinga2/features-available/gelf.conf
lib/perfdata/gelfwriter.cpp
lib/perfdata/gelfwriter.ti

index fd650a611ecd53bf39ca54b669661f67cb00b702..b6b628166f49af30402af1c8bf120c60838db396 100644 (file)
@@ -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.
 
 
 ## <a id="objecttype-graphitewriter"></a> GraphiteWriter
index 43ea7aae55a2fa1f97c06c9f58a0f3d5fc55d84c..2db44ef7e37fa37fb085875a18fbbd40c66f9b59 100644 (file)
@@ -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"
index d883fe51c2dca4764f1bff2a2a828621ad2d82f4..a098e76b26e89f71930b94d153ce46be55b9aaa9 100644 (file)
@@ -33,6 +33,8 @@
 #include "base/networkstream.hpp"
 #include "base/json.hpp"
 #include "base/context.hpp"
+#include <boost/foreach.hpp>
+#include <boost/algorithm/string/replace.hpp>
 
 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<PerfdataValue>())
+                                       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()));
 }
 
index 1f7fdc16c712bfec896c6cd8e287b95ee6c576b7..bdfa2a87bcc4e794bb38b2574e2cbaf92c299d9e 100644 (file)
@@ -35,6 +35,9 @@ class GelfWriter : ConfigObject
        [config] String source {
                default {{{ return "icinga2"; }}}
        };
+       [config] bool enable_send_perfdata {
+               default {{{ return false; }}}
+       };
 };
 
 }