[icinga-checkins] icinga.org: icinga2/fix/api-cluster-global-zone-11541: Ensure that objects in global zone can by synced on connect

git at icinga.org git at icinga.org
Fri Nov 11 16:30:26 CET 2016


Module: icinga2
Branch: fix/api-cluster-global-zone-11541
Commit: a2b43582e5ef5b4467951558012ef704523ad8e1
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=a2b43582e5ef5b4467951558012ef704523ad8e1

Author: Michael Friedrich <michael.friedrich at icinga.com>
Date:   Fri Nov 11 10:41:49 2016 +0100

Ensure that objects in global zone can by synced on connect

---

 lib/remote/apilistener-configsync.cpp |    2 +-
 lib/remote/apilistener.cpp            |   28 ++++++++++++++++++++++++----
 lib/remote/zone.cpp                   |    3 +++
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp
index 0f8ba9c..72775ea 100644
--- a/lib/remote/apilistener-configsync.cpp
+++ b/lib/remote/apilistener-configsync.cpp
@@ -243,7 +243,7 @@ Value ApiListener::ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin
 
 	if (!object) {
 		Log(LogNotice, "ApiListener")
-		    << "Could not delete non-existent object '" << params->Get("name") << "'.";
+		    << "Could not delete non-existent object '" << params->Get("name") << "' with type '" << params->Get("type") << "'.";
 		return Empty;
 	}
 
diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp
index 08a476e..13d600e 100644
--- a/lib/remote/apilistener.cpp
+++ b/lib/remote/apilistener.cpp
@@ -689,7 +689,7 @@ void ApiListener::SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionar
 
 	if (!endpoint->GetSyncing()) {
 		Log(LogNotice, "ApiListener")
-		    << "Sending message to '" << endpoint->GetName() << "'";
+		    << "Sending message '" << message->Get("method") << "' to '" << endpoint->GetName() << "'";
 
 		double maxTs = 0;
 
@@ -713,9 +713,15 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig
 
 	Zone::Ptr myZone = Zone::GetLocalZone();
 
-	/* only relay the message to a) the same zone, b) the parent zone and c) direct child zones */
-	if (targetZone != myZone && targetZone != myZone->GetParent() && targetZone->GetParent() != myZone)
+	/* only relay the message to a) the same zone, b) the parent zone and c) direct child zones. Exception is a global zone. */
+	if (!targetZone->GetGlobal() &&
+	    targetZone != myZone &&
+	    targetZone != myZone->GetParent() &&
+	    targetZone->GetParent() != myZone) {
+		Log(LogCritical, "ApiListener")
+		   << "Not relaying message '" << message->Get("method") << "'. Not in the same/parent/child zone.";
 		return true;
+	}
 
 	Endpoint::Ptr myEndpoint = GetLocalEndpoint();
 
@@ -723,7 +729,21 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig
 
 	bool relayed = false, log_needed = false, log_done = false;
 
-	for (const Endpoint::Ptr& endpoint : targetZone->GetEndpoints()) {
+	std::set<Endpoint::Ptr> targetEndpoints;
+
+	if (targetZone->GetGlobal()) {
+		for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
+			/* Fetch immediate parent and child zone members */
+			if (myZone->GetParent() == zone || zone->GetParent() == myZone) {
+				std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
+				targetEndpoints.insert(endpoints.begin(), endpoints.end());
+			}
+		}
+	} else {
+		targetEndpoints = targetZone->GetEndpoints();
+	}
+
+	for (const Endpoint::Ptr& endpoint : targetEndpoints) {
 		/* don't relay messages to ourselves */
 		if (endpoint == GetLocalEndpoint())
 			continue;
diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp
index a72a7a2..fde6768 100644
--- a/lib/remote/zone.cpp
+++ b/lib/remote/zone.cpp
@@ -103,6 +103,9 @@ bool Zone::CanAccessObject(const ConfigObject::Ptr& object)
 	if (!object_zone)
 		object_zone = Zone::GetLocalZone();
 
+	if (object_zone->GetGlobal())
+		return true;
+
 	return object_zone->IsChildOf(this);
 }
 



More information about the icinga-checkins mailing list