]> granicus.if.org Git - icinga2/commitdiff
Don't log messages we've already relayed to all relevant zones
authorGunnar Beutner <gunnar@beutner.name>
Thu, 1 Oct 2015 07:17:23 +0000 (09:17 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 13 Oct 2015 11:07:32 +0000 (13:07 +0200)
fixes #10262

lib/remote/apilistener.cpp

index a29b73773d554f021e537750e89879bdd7434f56..7e1e3c52cef904ce9869033cf0cb2040632c1b1c 100644 (file)
@@ -511,9 +511,6 @@ void ApiListener::SyncRelayMessage(const MessageOrigin& origin, const DynamicObj
        Log(LogNotice, "ApiListener")
            << "Relaying '" << message->Get("method") << "' message";
 
-       if (log)
-               PersistMessage(message, secobj);
-
        if (origin.FromZone)
                message->Set("originZone", origin.FromZone->GetName());
 
@@ -522,15 +519,31 @@ void ApiListener::SyncRelayMessage(const MessageOrigin& origin, const DynamicObj
        Zone::Ptr my_zone = Zone::GetLocalZone();
 
        std::vector<Endpoint::Ptr> skippedEndpoints;
+       std::set<Zone::Ptr> allZones;
        std::set<Zone::Ptr> finishedZones;
+       std::set<Zone::Ptr> finishedLogZones;
 
        BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjectsByType<Endpoint>()) {
-               /* don't relay messages to ourselves or disconnected endpoints */
-               if (endpoint->GetName() == GetIdentity() || !endpoint->IsConnected())
+               /* don't relay messages to ourselves */
+               if (endpoint->GetName() == GetIdentity())
                        continue;
 
                Zone::Ptr target_zone = endpoint->GetZone();
 
+               allZones.insert(target_zone);
+
+               /* only relay messages to zones which have access to the object */
+               if (!target_zone->CanAccessObject(secobj)) {
+                       finishedLogZones.insert(target_zone);
+                       continue;
+               }
+
+               /* don't relay messages to disconnected endpoints */
+               if (!endpoint->IsConnected())
+                       continue;
+
+               finishedLogZones.insert(target_zone);
+
                /* don't relay the message to the zone through more than one endpoint */
                if (finishedZones.find(target_zone) != finishedZones.end()) {
                        skippedEndpoints.push_back(endpoint);
@@ -562,15 +575,14 @@ void ApiListener::SyncRelayMessage(const MessageOrigin& origin, const DynamicObj
                        continue;
                }
 
-               /* only relay messages to zones which have access to the object */
-               if (!target_zone->CanAccessObject(secobj))
-                       continue;
-
                finishedZones.insert(target_zone);
 
                SyncSendMessage(endpoint, message);
        }
 
+       if (log && allZones.size() != finishedLogZones.size())
+               PersistMessage(message, secobj);
+
        BOOST_FOREACH(const Endpoint::Ptr& endpoint, skippedEndpoints)
                endpoint->SetLocalLogPosition(ts);
 }