MCPcopy Create free account
hub / github.com/Icinga/icinga2 / AddCheckResult

Method AddCheckResult

lib/perfdata/elasticsearchwriter.cpp:171–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void ElasticsearchWriter::AddCheckResult(const Dictionary::Ptr& fields, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
172{
173 String prefix = "check_result.";
174
175 fields->Set(prefix + "output", cr->GetOutput());
176 fields->Set(prefix + "check_source", cr->GetCheckSource());
177 fields->Set(prefix + "exit_status", cr->GetExitStatus());
178 fields->Set(prefix + "command", cr->GetCommand());
179 fields->Set(prefix + "state", cr->GetState());
180 fields->Set(prefix + "vars_before", cr->GetVarsBefore());
181 fields->Set(prefix + "vars_after", cr->GetVarsAfter());
182
183 fields->Set(prefix + "execution_start", FormatTimestamp(cr->GetExecutionStart()));
184 fields->Set(prefix + "execution_end", FormatTimestamp(cr->GetExecutionEnd()));
185 fields->Set(prefix + "schedule_start", FormatTimestamp(cr->GetScheduleStart()));
186 fields->Set(prefix + "schedule_end", FormatTimestamp(cr->GetScheduleEnd()));
187
188 /* Add extra calculated field. */
189 fields->Set(prefix + "latency", cr->CalculateLatency());
190 fields->Set(prefix + "execution_time", cr->CalculateExecutionTime());
191
192 if (!GetEnableSendPerfdata())
193 return;
194
195 Array::Ptr perfdata = cr->GetPerformanceData();
196
197 CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();
198
199 if (perfdata) {
200 ObjectLock olock(perfdata);
201 for (const Value& val : perfdata) {
202 PerfdataValue::Ptr pdv;
203
204 if (val.IsObjectType<PerfdataValue>())
205 pdv = val;
206 else {
207 try {
208 pdv = PerfdataValue::Parse(val);
209 } catch (const std::exception&) {
210 Log(LogWarning, "ElasticsearchWriter")
211 << "Ignoring invalid perfdata for checkable '"
212 << checkable->GetName() << "' and command '"
213 << checkCommand->GetName() << "' with value: " << val;
214 continue;
215 }
216 }
217
218 String escapedKey = pdv->GetLabel();
219 boost::replace_all(escapedKey, " ", "_");
220 boost::replace_all(escapedKey, ".", "_");
221 boost::replace_all(escapedKey, "\\", "_");
222 boost::algorithm::replace_all(escapedKey, "::", ".");
223
224 String perfdataPrefix = prefix + "perfdata." + escapedKey;
225
226 fields->Set(perfdataPrefix + ".value", pdv->GetValue());
227
228 if (!pdv->GetMin().IsEmpty())

Callers

nothing calls this directly

Calls 10

LogClass · 0.85
GetCommandMethod · 0.80
CalculateLatencyMethod · 0.80
GetCheckCommandMethod · 0.80
SetMethod · 0.45
GetStateMethod · 0.45
GetNameMethod · 0.45
GetValueMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected