| 15 | using namespace icinga; |
| 16 | |
| 17 | void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, |
| 18 | const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers, |
| 19 | const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int timeout, |
| 20 | const std::function<void(const Value& commandLine, const ProcessResult&)>& callback) |
| 21 | { |
| 22 | Value raw_command = commandObj->GetCommandLine(); |
| 23 | Dictionary::Ptr raw_arguments = commandObj->GetArguments(); |
| 24 | |
| 25 | Value command; |
| 26 | |
| 27 | try { |
| 28 | command = MacroProcessor::ResolveArguments(raw_command, raw_arguments, |
| 29 | macroResolvers, cr, resolvedMacros, useResolvedMacros); |
| 30 | } catch (const std::exception& ex) { |
| 31 | String message = DiagnosticInformation(ex); |
| 32 | |
| 33 | Log(LogWarning, "PluginUtility", message); |
| 34 | |
| 35 | if (callback) { |
| 36 | ProcessResult pr; |
| 37 | pr.PID = -1; |
| 38 | pr.ExecutionStart = Utility::GetTime(); |
| 39 | pr.ExecutionEnd = pr.ExecutionStart; |
| 40 | pr.ExitStatus = 3; /* Unknown */ |
| 41 | pr.Output = message; |
| 42 | callback(Empty, pr); |
| 43 | } |
| 44 | |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | Dictionary::Ptr envMacros = new Dictionary(); |
| 49 | |
| 50 | Dictionary::Ptr env = commandObj->GetEnv(); |
| 51 | |
| 52 | if (env) { |
| 53 | ObjectLock olock(env); |
| 54 | for (const Dictionary::Pair& kv : env) { |
| 55 | String name = kv.second; |
| 56 | |
| 57 | String missingMacro; |
| 58 | Value value = MacroProcessor::ResolveMacros(name, macroResolvers, cr, |
| 59 | &missingMacro, MacroProcessor::EscapeCallback(), resolvedMacros, |
| 60 | useResolvedMacros); |
| 61 | |
| 62 | #ifdef I2_DEBUG |
| 63 | if (!missingMacro.IsEmpty()) |
| 64 | Log(LogDebug, "PluginUtility") |
| 65 | << "Macro '" << name << "' is not defined."; |
| 66 | #endif /* I2_DEBUG */ |
| 67 | |
| 68 | if (value.IsObjectType<Array>()) |
| 69 | value = Utility::Join(value, ';'); |
| 70 | |
| 71 | envMacros->Set(kv.first, value); |
| 72 | } |
| 73 | } |
| 74 |
nothing calls this directly
no test coverage detected