| 109 | } |
| 110 | |
| 111 | bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs, const String& objectsFile) |
| 112 | { |
| 113 | bool success; |
| 114 | |
| 115 | Namespace::Ptr systemNS = ScriptGlobal::Get("System"); |
| 116 | VERIFY(systemNS); |
| 117 | |
| 118 | Namespace::Ptr internalNS = ScriptGlobal::Get("Internal"); |
| 119 | VERIFY(internalNS); |
| 120 | |
| 121 | if (!objectsFile.IsEmpty()) |
| 122 | ConfigCompilerContext::GetInstance()->OpenObjectsFile(objectsFile); |
| 123 | |
| 124 | if (!configs.empty()) { |
| 125 | for (String configPath : configs) { |
| 126 | try { |
| 127 | std::unique_ptr<Expression> expression = ConfigCompiler::CompileFile(configPath, String(), "_etc"); |
| 128 | success = ExecuteExpression(&*expression); |
| 129 | if (!success) |
| 130 | return false; |
| 131 | } catch (const std::exception& ex) { |
| 132 | Log(LogCritical, "cli", "Could not compile config files: " + DiagnosticInformation(ex, false)); |
| 133 | Application::Exit(1); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /* Load cluster config files from /etc/icinga2/zones.d. |
| 139 | * This should probably be in libremote but |
| 140 | * unfortunately moving it there is somewhat non-trivial. */ |
| 141 | success = true; |
| 142 | |
| 143 | /* Only load zone directory if we're not in staging validation. */ |
| 144 | if (!internalNS->Contains("ZonesStageVarDir")) { |
| 145 | String zonesEtcDir = Configuration::ZonesDir; |
| 146 | if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir)) { |
| 147 | std::set<String> zoneEtcDirs; |
| 148 | Utility::Glob(zonesEtcDir + "/*", [&zoneEtcDirs](const String& zoneEtcDir) { zoneEtcDirs.emplace(zoneEtcDir); }, GlobDirectory); |
| 149 | |
| 150 | bool hasSuccess = true; |
| 151 | |
| 152 | while (!zoneEtcDirs.empty() && hasSuccess) { |
| 153 | hasSuccess = false; |
| 154 | |
| 155 | for (auto& zoneEtcDir : zoneEtcDirs) { |
| 156 | if (IncludeZoneDirRecursive(zoneEtcDir, "_etc", success)) { |
| 157 | zoneEtcDirs.erase(zoneEtcDir); |
| 158 | hasSuccess = true; |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | for (auto& zoneEtcDir : zoneEtcDirs) { |
| 165 | Log(LogWarning, "config") |
| 166 | << "Ignoring directory '" << zoneEtcDir << "' for unknown zone '" << Utility::BaseName(zoneEtcDir) << "'."; |
| 167 | } |
| 168 | } |
nothing calls this directly
no test coverage detected