"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/cli/daemonutility.cpp" between
icinga2-2.11.5.tar.gz and icinga2-2.12.0.tar.gz

About: Icinga 2 is an enterprise grade monitoring system which keeps watch over networks and any conceivable network resource.

daemonutility.cpp  (icinga2-2.11.5):daemonutility.cpp  (icinga2-2.12.0)
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
#include "cli/daemonutility.hpp" #include "cli/daemonutility.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
#include "base/logger.hpp" #include "base/logger.hpp"
#include "base/application.hpp" #include "base/application.hpp"
#include "base/scriptglobal.hpp" #include "base/scriptglobal.hpp"
#include "config/configcompiler.hpp" #include "config/configcompiler.hpp"
#include "config/configcompilercontext.hpp" #include "config/configcompilercontext.hpp"
#include "config/configitembuilder.hpp" #include "config/configitembuilder.hpp"
#include <set>
using namespace icinga; using namespace icinga;
static bool ExecuteExpression(Expression *expression) static bool ExecuteExpression(Expression *expression)
{ {
if (!expression) if (!expression)
return false; return false;
try { try {
ScriptFrame frame(true); ScriptFrame frame(true);
expression->Evaluate(frame); expression->Evaluate(frame);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Log(LogCritical, "config", DiagnosticInformation(ex)); Log(LogCritical, "config", DiagnosticInformation(ex));
return false; return false;
} }
return true; return true;
} }
static void IncludeZoneDirRecursive(const String& path, const String& package, b ool& success) static bool IncludeZoneDirRecursive(const String& path, const String& package, b ool& success)
{ {
String zoneName = Utility::BaseName(path); String zoneName = Utility::BaseName(path);
/* We don't have an activated zone object yet. We may forcefully guess fr om configitems /* We don't have an activated zone object yet. We may forcefully guess fr om configitems
* to not include this specific synced zones directory. * to not include this specific synced zones directory.
*/ */
if(!ConfigItem::GetByTypeAndName(Type::GetByName("Zone"), zoneName)) { if(!ConfigItem::GetByTypeAndName(Type::GetByName("Zone"), zoneName)) {
Log(LogWarning, "config") return false;
<< "Ignoring directory '" << path << "' for unknown zone
'" << zoneName << "'.";
return;
} }
/* register this zone path for cluster config sync */ /* register this zone path for cluster config sync */
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName); ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
std::vector<std::unique_ptr<Expression> > expressions; std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(path, "*.conf", std::bind(&ConfigCompiler::Collect Includes, std::ref(expressions), _1, zoneName, package), GlobFile); Utility::GlobRecursive(path, "*.conf", std::bind(&ConfigCompiler::Collect Includes, std::ref(expressions), _1, zoneName, package), GlobFile);
DictExpression expr(std::move(expressions)); DictExpression expr(std::move(expressions));
if (!ExecuteExpression(&expr)) if (!ExecuteExpression(&expr))
success = false; success = false;
return true;
} }
static void IncludeNonLocalZone(const String& zonePath, const String& package, b ool& success) static bool IncludeNonLocalZone(const String& zonePath, const String& package, b ool& success)
{ {
/* Note: This include function must not call RegisterZoneDir(). /* Note: This include function must not call RegisterZoneDir().
* We do not need to copy it for cluster config sync. */ * We do not need to copy it for cluster config sync. */
String zoneName = Utility::BaseName(zonePath); String zoneName = Utility::BaseName(zonePath);
/* We don't have an activated zone object yet. We may forcefully guess fr om configitems /* We don't have an activated zone object yet. We may forcefully guess fr om configitems
* to not include this specific synced zones directory. * to not include this specific synced zones directory.
*/ */
if(!ConfigItem::GetByTypeAndName(Type::GetByName("Zone"), zoneName)) { if(!ConfigItem::GetByTypeAndName(Type::GetByName("Zone"), zoneName)) {
Log(LogWarning, "config") return false;
<< "Ignoring directory '" << zonePath << "' for unknown z
one '" << zoneName << "'.";
return;
} }
/* Check whether this node already has an authoritative config version /* Check whether this node already has an authoritative config version
* from zones.d in etc or api package directory, or a local marker file) * from zones.d in etc or api package directory, or a local marker file)
*/ */
if (ConfigCompiler::HasZoneConfigAuthority(zoneName) || Utility::PathExis ts(zonePath + "/.authoritative")) { if (ConfigCompiler::HasZoneConfigAuthority(zoneName) || Utility::PathExis ts(zonePath + "/.authoritative")) {
Log(LogNotice, "config") Log(LogNotice, "config")
<< "Ignoring non local config include for zone '" << zone Name << "': We already have an authoritative copy included."; << "Ignoring non local config include for zone '" << zone Name << "': We already have an authoritative copy included.";
return; return true;
} }
std::vector<std::unique_ptr<Expression> > expressions; std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(zonePath, "*.conf", std::bind(&ConfigCompiler::Col lectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile); Utility::GlobRecursive(zonePath, "*.conf", std::bind(&ConfigCompiler::Col lectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile);
DictExpression expr(std::move(expressions)); DictExpression expr(std::move(expressions));
if (!ExecuteExpression(&expr)) if (!ExecuteExpression(&expr))
success = false; success = false;
return true;
} }
static void IncludePackage(const String& packagePath, bool& success) static void IncludePackage(const String& packagePath, bool& success)
{ {
/* Note: Package includes will register their zones /* Note: Package includes will register their zones
* for config sync inside their generated config. */ * for config sync inside their generated config. */
String packageName = Utility::BaseName(packagePath); String packageName = Utility::BaseName(packagePath);
if (Utility::PathExists(packagePath + "/include.conf")) { if (Utility::PathExists(packagePath + "/include.conf")) {
std::unique_ptr<Expression> expr = ConfigCompiler::CompileFile(pa ckagePath + "/include.conf", std::unique_ptr<Expression> expr = ConfigCompiler::CompileFile(pa ckagePath + "/include.conf",
skipping to change at line 132 skipping to change at line 133
} }
/* Load cluster config files from /etc/icinga2/zones.d. /* Load cluster config files from /etc/icinga2/zones.d.
* This should probably be in libremote but * This should probably be in libremote but
* unfortunately moving it there is somewhat non-trivial. */ * unfortunately moving it there is somewhat non-trivial. */
success = true; success = true;
/* Only load zone directory if we're not in staging validation. */ /* Only load zone directory if we're not in staging validation. */
if (!systemNS->Contains("ZonesStageVarDir")) { if (!systemNS->Contains("ZonesStageVarDir")) {
String zonesEtcDir = Configuration::ZonesDir; String zonesEtcDir = Configuration::ZonesDir;
if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir)) if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir)) {
Utility::Glob(zonesEtcDir + "/*", std::bind(&IncludeZoneD std::set<String> zoneEtcDirs;
irRecursive, _1, "_etc", std::ref(success)), GlobDirectory); Utility::Glob(zonesEtcDir + "/*", [&zoneEtcDirs](const St
ring& zoneEtcDir) { zoneEtcDirs.emplace(zoneEtcDir); }, GlobDirectory);
bool hasSuccess = true;
while (!zoneEtcDirs.empty() && hasSuccess) {
hasSuccess = false;
for (auto& zoneEtcDir : zoneEtcDirs) {
if (IncludeZoneDirRecursive(zoneEtcDir, "
_etc", success)) {
zoneEtcDirs.erase(zoneEtcDir);
hasSuccess = true;
break;
}
}
}
for (auto& zoneEtcDir : zoneEtcDirs) {
Log(LogWarning, "config")
<< "Ignoring directory '" << zoneEtcDir <
< "' for unknown zone '" << Utility::BaseName(zoneEtcDir) << "'.";
}
}
if (!success) if (!success)
return false; return false;
} }
/* Load package config files - they may contain additional zones which /* Load package config files - they may contain additional zones which
* are authoritative on this node and are checked in HasZoneConfigAuthori ty(). */ * are authoritative on this node and are checked in HasZoneConfigAuthori ty(). */
String packagesVarDir = Configuration::DataDir + "/api/packages"; String packagesVarDir = Configuration::DataDir + "/api/packages";
if (Utility::PathExists(packagesVarDir)) if (Utility::PathExists(packagesVarDir))
Utility::Glob(packagesVarDir + "/*", std::bind(&IncludePackage, _ 1, std::ref(success)), GlobDirectory); Utility::Glob(packagesVarDir + "/*", std::bind(&IncludePackage, _ 1, std::ref(success)), GlobDirectory);
skipping to change at line 159 skipping to change at line 181
String zonesVarDir = Configuration::DataDir + "/api/zones"; String zonesVarDir = Configuration::DataDir + "/api/zones";
/* Cluster config sync stage validation needs this. */ /* Cluster config sync stage validation needs this. */
if (systemNS->Contains("ZonesStageVarDir")) { if (systemNS->Contains("ZonesStageVarDir")) {
zonesVarDir = systemNS->Get("ZonesStageVarDir"); zonesVarDir = systemNS->Get("ZonesStageVarDir");
Log(LogNotice, "DaemonUtility") Log(LogNotice, "DaemonUtility")
<< "Overriding zones var directory with '" << zonesVarDir << "' for cluster config sync staging."; << "Overriding zones var directory with '" << zonesVarDir << "' for cluster config sync staging.";
} }
if (Utility::PathExists(zonesVarDir)) if (Utility::PathExists(zonesVarDir)) {
Utility::Glob(zonesVarDir + "/*", std::bind(&IncludeNonLocalZone, std::set<String> zoneVarDirs;
_1, "_cluster", std::ref(success)), GlobDirectory); Utility::Glob(zonesVarDir + "/*", [&zoneVarDirs](const String& zo
neVarDir) { zoneVarDirs.emplace(zoneVarDir); }, GlobDirectory);
bool hasSuccess = true;
while (!zoneVarDirs.empty() && hasSuccess) {
hasSuccess = false;
for (auto& zoneVarDir : zoneVarDirs) {
if (IncludeNonLocalZone(zoneVarDir, "_cluster", s
uccess)) {
zoneVarDirs.erase(zoneVarDir);
hasSuccess = true;
break;
}
}
}
for (auto& zoneEtcDir : zoneVarDirs) {
Log(LogWarning, "config")
<< "Ignoring directory '" << zoneEtcDir << "' for
unknown zone '" << Utility::BaseName(zoneEtcDir) << "'.";
}
}
if (!success) if (!success)
return false; return false;
/* This is initialized inside the IcingaApplication class. */ /* This is initialized inside the IcingaApplication class. */
Value vAppType; Value vAppType;
VERIFY(systemNS->Get("ApplicationType", &vAppType)); VERIFY(systemNS->Get("ApplicationType", &vAppType));
Type::Ptr appType = Type::GetByName(vAppType); Type::Ptr appType = Type::GetByName(vAppType);
 End of changes. 10 change blocks. 
17 lines changed or deleted 62 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)