| 44 | } |
| 45 | |
| 46 | void 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 |
nothing calls this directly
no test coverage detected