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

Method CheckResultHandler

lib/perfdata/influxdbcommonwriter.cpp:203–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203void InfluxdbCommonWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
204{
205 if (IsPaused())
206 return;
207
208 if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
209 return;
210
211 Host::Ptr host;
212 Service::Ptr service;
213 tie(host, service) = GetHostService(checkable);
214
215 MacroProcessor::ResolverList resolvers;
216 if (service)
217 resolvers.emplace_back("service", service);
218 resolvers.emplace_back("host", host);
219
220 // Clone the template and perform an in-place macro expansion of measurement and tag values
221 Dictionary::Ptr tmpl_clean = service ? GetServiceTemplate() : GetHostTemplate();
222 Dictionary::Ptr tmpl = static_pointer_cast<Dictionary>(tmpl_clean->ShallowClone());
223 tmpl->Set("measurement", MacroProcessor::ResolveMacros(tmpl->Get("measurement"), resolvers, cr));
224
225 Dictionary::Ptr tagsClean = tmpl->Get("tags");
226 if (tagsClean) {
227 Dictionary::Ptr tags = new Dictionary();
228
229 {
230 ObjectLock olock(tagsClean);
231 for (const Dictionary::Pair& pair : tagsClean) {
232 String missing_macro;
233 Value value = MacroProcessor::ResolveMacros(pair.second, resolvers, cr, &missing_macro);
234
235 if (missing_macro.IsEmpty()) {
236 tags->Set(pair.first, value);
237 }
238 }
239 }
240
241 tmpl->Set("tags", tags);
242 }
243
244 Dictionary::Ptr fields;
245 if (GetEnableSendMetadata()) {
246 fields = new Dictionary();
247
248 if (service)
249 fields->Set("state", new InfluxdbInteger(service->GetState()));
250 else
251 fields->Set("state", new InfluxdbInteger(host->GetState()));
252
253 fields->Set("current_attempt", new InfluxdbInteger(checkable->GetCheckAttempt()));
254 fields->Set("max_check_attempts", new InfluxdbInteger(checkable->GetMaxCheckAttempts()));
255 fields->Set("state_type", new InfluxdbInteger(checkable->GetStateType()));
256 fields->Set("reachable", checkable->IsReachable());
257 fields->Set("downtime_depth", new InfluxdbInteger(checkable->GetDowntimeDepth()));
258 fields->Set("acknowledgement", new InfluxdbInteger(checkable->GetAcknowledgement()));
259 fields->Set("latency", cr->CalculateLatency());
260 fields->Set("execution_time", cr->CalculateExecutionTime());

Callers

nothing calls this directly

Calls 15

LogClass · 0.85
GetDowntimeDepthMethod · 0.80
GetAcknowledgementMethod · 0.80
CalculateLatencyMethod · 0.80
GetCheckCommandMethod · 0.80
ShallowCloneMethod · 0.45
SetMethod · 0.45
GetMethod · 0.45
IsEmptyMethod · 0.45
GetStateMethod · 0.45
IsReachableMethod · 0.45

Tested by

no test coverage detected