]> granicus.if.org Git - icinga2/commitdiff
Fix object sync for objects in a global zone
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 11 Nov 2016 09:41:49 +0000 (10:41 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 14 Nov 2016 13:42:47 +0000 (14:42 +0100)
fixes #11541

lib/remote/apilistener-configsync.cpp
lib/remote/apilistener.cpp
lib/remote/zone.cpp

index 0f8ba9c9396527e3cae53c93b43cbcb273dee35e..72775eaa95efc976d3a4f3599c8fca75f517d294 100644 (file)
@@ -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;
        }
 
index 08a476e4af31661b70ed7f9074e68af6a46771d9..e90015fb6ed57bf4ba1df5d97ed6fd1fa4a8239c 100644 (file)
@@ -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,23 @@ 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()) {
+               targetEndpoints = myZone->GetEndpoints();
+
+               for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
+                       /* Fetch immediate child zone members */
+                       if (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;
index a72a7a2446b70dd6e33529aa45540805b1f7186a..fde67688dd77e46f1210bd110333da799a5da464 100644 (file)
@@ -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);
 }