[icinga-checkins] icinga.org: icinga2/next: Fix thinko with global zone sync

git at icinga.org git at icinga.org
Thu Jun 12 14:34:17 CEST 2014


Module: icinga2
Branch: next
Commit: a57ebbf953c55e16516f67899e9ee4c306065141
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=a57ebbf953c55e16516f67899e9ee4c306065141

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu Jun 12 14:31:07 2014 +0200

Fix thinko with global zone sync

refs #6254

---

 lib/remote/apilistener-sync.cpp |   26 ++++++++++++++++++--------
 lib/remote/zone.cpp             |   10 ++++++++++
 lib/remote/zone.hpp             |    1 +
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/lib/remote/apilistener-sync.cpp b/lib/remote/apilistener-sync.cpp
index 81ce77b..9c561a9 100644
--- a/lib/remote/apilistener-sync.cpp
+++ b/lib/remote/apilistener-sync.cpp
@@ -126,12 +126,6 @@ void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
 void ApiListener::SyncZoneDirs(void) const
 {
 	BOOST_FOREACH(const Zone::Ptr& zone, DynamicType::GetObjects<Zone>()) {
-		/* always sync global zone dirs */
-		if (zone->GetGlobal()) {
-			SyncZoneDir(zone);
-			continue;
-		}
-
 		if (!IsConfigMaster(zone))
 			continue;
 
@@ -158,8 +152,17 @@ void ApiListener::SendConfigUpdate(const ApiClient::Ptr& aclient)
 	BOOST_FOREACH(const Zone::Ptr& zone, DynamicType::GetObjects<Zone>()) {
 		String zoneDir = zonesDir + "/" + zone->GetName();
 
-		if (!zone->IsChildOf(azone) || !Utility::PathExists(zoneDir))
+		if (!zone->IsChildOf(azone) && !zone->IsGlobal()) {
+			Log(LogNotice, "ApiListener", "Skipping sync for '" + zone->GetName() + "'. Not a child of zone '" + azone->GetName() + "'.");
 			continue;
+		}
+		if (!Utility::PathExists(zoneDir)) {
+			Log(LogNotice, "ApiListener", "Ignoring sync for '" + zone->GetName() + "'. Zone directory '" + zoneDir + "' does not exist.");
+			continue;
+		}
+
+		if (zone->IsGlobal())
+			Log(LogInformation, "ApiListener", "Syncing global zone '" + zone->GetName() + "'.");
 
 		configUpdate->Set(zone->GetName(), LoadConfigDir(zonesDir + "/" + zone->GetName()));
 	}
@@ -182,8 +185,15 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin& origin, const Dictio
 
 	ApiListener::Ptr listener = ApiListener::GetInstance();
 
-	if (!listener || !listener->GetAcceptConfig())
+	if (!listener) {
+		Log(LogCritical, "ApiListener", "No instance available.");
 		return Empty;
+	}
+
+	if (!listener->GetAcceptConfig()) {
+		Log(LogWarning, "ApiListener", "Ignoring config update. '" + listener->GetName() + "' does not accept config.");
+		return Empty;
+	}
 
 	Dictionary::Ptr update = params->Get("update");
 
diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp
index 2dbe706..e67e651 100644
--- a/lib/remote/zone.cpp
+++ b/lib/remote/zone.cpp
@@ -81,6 +81,16 @@ bool Zone::IsChildOf(const Zone::Ptr& zone)
 	return false;
 }
 
+bool Zone::IsGlobal(void)
+{
+	Zone::Ptr zone = GetSelf();
+
+	if (!zone)
+		return false;
+
+	return zone->GetGlobal();
+}
+
 Zone::Ptr Zone::GetLocalZone(void)
 {
 	Endpoint::Ptr local = Endpoint::GetLocalEndpoint();
diff --git a/lib/remote/zone.hpp b/lib/remote/zone.hpp
index 7b484bd..1a17c5c 100644
--- a/lib/remote/zone.hpp
+++ b/lib/remote/zone.hpp
@@ -41,6 +41,7 @@ public:
 
 	bool CanAccessObject(const DynamicObject::Ptr& object);
 	bool IsChildOf(const Zone::Ptr& zone);
+	bool IsGlobal(void);
 
 	static Zone::Ptr GetLocalZone(void);
 };



More information about the icinga-checkins mailing list