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

Method ScriptFunc

lib/icingadb/icingadbchecktask.cpp:46–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void IcingadbCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
47 const WaitGroup::Ptr& producer, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
48{
49 CheckCommand::Ptr commandObj = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand();
50
51 Host::Ptr host;
52 Service::Ptr service;
53 tie(host, service) = GetHostService(checkable);
54
55 MacroProcessor::ResolverList resolvers;
56 String silenceMissingMacroWarning;
57
58 if (MacroResolver::OverrideMacros)
59 resolvers.emplace_back("override", MacroResolver::OverrideMacros);
60
61 if (service)
62 resolvers.emplace_back("service", service);
63 resolvers.emplace_back("host", host);
64 resolvers.emplace_back("command", commandObj);
65
66 auto resolve ([&](const String& macro) {
67 return MacroProcessor::ResolveMacros(macro, resolvers, checkable->GetLastCheckResult(),
68 &silenceMissingMacroWarning, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
69 });
70
71 struct Thresholds
72 {
73 Value Warning, Critical;
74 };
75
76 auto resolveThresholds ([&resolve](const String& wmacro, const String& cmacro) {
77 return Thresholds{resolve(wmacro), resolve(cmacro)};
78 });
79
80 String icingadbName = resolve("$icingadb_name$");
81
82 auto dumpTakesThresholds (resolveThresholds("$icingadb_full_dump_duration_warning$", "$icingadb_full_dump_duration_critical$"));
83 auto syncTakesThresholds (resolveThresholds("$icingadb_full_sync_duration_warning$", "$icingadb_full_sync_duration_critical$"));
84 auto icingaBacklogThresholds (resolveThresholds("$icingadb_redis_backlog_warning$", "$icingadb_redis_backlog_critical$"));
85 auto icingadbBacklogThresholds (resolveThresholds("$icingadb_database_backlog_warning$", "$icingadb_database_backlog_critical$"));
86
87 if (resolvedMacros && !useResolvedMacros)
88 return;
89
90 if (icingadbName.IsEmpty()) {
91 ReportIcingadbCheck(checkable, commandObj, cr, producer, "Icinga DB UNKNOWN: Attribute 'icingadb_name' must be set.", ServiceUnknown);
92 return;
93 }
94
95 auto conn (IcingaDB::GetByName(icingadbName));
96
97 if (!conn) {
98 ReportIcingadbCheck(checkable, commandObj, cr, producer, "Icinga DB UNKNOWN: Icinga DB connection '" + icingadbName + "' does not exist.", ServiceUnknown);
99 return;
100 }
101
102 auto redis (conn->GetConnection());
103

Callers

nothing calls this directly

Calls 15

ReportIcingadbCheckFunction · 0.85
GetXMessageTsFunction · 0.85
GetCheckCommandMethod · 0.80
GetConnectionMethod · 0.80
IsConnectedMethod · 0.80
GetResultsOfQueriesMethod · 0.80
emplaceMethod · 0.80
findMethod · 0.80
InsertValueMethod · 0.80
UpdateAndGetValuesMethod · 0.80
LoadPendingItemsStatsMethod · 0.80

Tested by

no test coverage detected