mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
GelfWriter: Add additional fields for 'CHECK RESULT' events
fixes #9858
This commit is contained in:
parent
9c8fdf06cf
commit
d739675799
@ -502,6 +502,7 @@ Configuration Attributes:
|
|||||||
host |**Optional.** GELF receiver host address. Defaults to '127.0.0.1'.
|
host |**Optional.** GELF receiver host address. Defaults to '127.0.0.1'.
|
||||||
port |**Optional.** GELF receiver port. Defaults to `12201`.
|
port |**Optional.** GELF receiver port. Defaults to `12201`.
|
||||||
source |**Optional.** Source name for this instance. Defaults to `icinga2`.
|
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
|
## <a id="objecttype-graphitewriter"></a> GraphiteWriter
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* The GelfWriter type writes event log entries
|
* The GelfWriter type writes event log entries
|
||||||
* to a GELF tcp socket provided by graylog2,
|
* to a GELF tcp socket provided by Graylog,
|
||||||
* logstash or any other receiver.
|
* Logstash or any other receiver.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
library "perfdata"
|
library "perfdata"
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
#include "base/networkstream.hpp"
|
#include "base/networkstream.hpp"
|
||||||
#include "base/json.hpp"
|
#include "base/json.hpp"
|
||||||
#include "base/context.hpp"
|
#include "base/context.hpp"
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
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("_current_check_attempt", checkable->GetCheckAttempt());
|
||||||
fields->Set("_max_check_attempts", checkable->GetMaxCheckAttempts());
|
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) {
|
if (cr) {
|
||||||
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr));
|
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr));
|
||||||
fields->Set("full_message", CompatUtility::GetCheckResultLongOutput(cr));
|
fields->Set("full_message", CompatUtility::GetCheckResultLongOutput(cr));
|
||||||
fields->Set("_check_source", cr->GetCheckSource());
|
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()));
|
SendLogMessage(ComposeGelfMessage(fields, GetSource()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,9 @@ class GelfWriter : ConfigObject
|
|||||||
[config] String source {
|
[config] String source {
|
||||||
default {{{ return "icinga2"; }}}
|
default {{{ return "icinga2"; }}}
|
||||||
};
|
};
|
||||||
|
[config] bool enable_send_perfdata {
|
||||||
|
default {{{ return false; }}}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user