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

Method CheckResultHandler

lib/perfdata/opentsdbwriter.cpp:157–299  ·  view source on GitHub ↗

* Registered check result handler processing data. * Calculates tags from the config. * * @param checkable Host/service object * @param cr Check result */

Source from the content-addressed store, hash-verified

155 * @param cr Check result
156 */
157void OpenTsdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
158{
159 if (IsPaused())
160 return;
161
162 CONTEXT("Processing check result for '" << checkable->GetName() << "'");
163
164 if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
165 return;
166
167 Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
168 Host::Ptr host;
169 Dictionary::Ptr config_tmpl;
170 Dictionary::Ptr config_tmpl_tags;
171 String config_tmpl_metric;
172
173 if (service) {
174 host = service->GetHost();
175 config_tmpl = m_ServiceConfigTemplate;
176 }
177 else {
178 host = static_pointer_cast<Host>(checkable);
179 config_tmpl = m_HostConfigTemplate;
180 }
181
182 // Get the tags nested dictionary in the service/host template in the config
183 if (config_tmpl) {
184 config_tmpl_tags = config_tmpl->Get("tags");
185 config_tmpl_metric = config_tmpl->Get("metric");
186 }
187
188 String metric;
189 std::map<String, String> tags;
190
191 // Resolve macros in configuration template and build custom tag list
192 if (config_tmpl_tags || !config_tmpl_metric.IsEmpty()) {
193
194 // Configure config template macro resolver
195 MacroProcessor::ResolverList resolvers;
196 if (service)
197 resolvers.emplace_back("service", service);
198 resolvers.emplace_back("host", host);
199
200 // Resolve macros for the service and host template config line
201 if (config_tmpl_tags) {
202 ObjectLock olock(config_tmpl_tags);
203
204 for (const Dictionary::Pair& pair : config_tmpl_tags) {
205
206 String missing_macro;
207 Value value = MacroProcessor::ResolveMacros(pair.second, resolvers, cr, &missing_macro);
208
209 if (!missing_macro.IsEmpty()) {
210 Log(LogDebug, "OpenTsdbWriter")
211 << "Unable to resolve macro '" << missing_macro
212 << "' for checkable '" << checkable->GetName() << "'.";
213
214 continue;

Callers

nothing calls this directly

Calls 11

LogClass · 0.85
GetDowntimeDepthMethod · 0.80
GetAcknowledgementMethod · 0.80
CalculateLatencyMethod · 0.80
GetNameMethod · 0.45
GetHostMethod · 0.45
GetMethod · 0.45
IsEmptyMethod · 0.45
GetStateMethod · 0.45
IsReachableMethod · 0.45

Tested by

no test coverage detected