From: Gunnar Beutner Date: Thu, 1 Oct 2015 07:17:23 +0000 (+0200) Subject: Don't log messages we've already relayed to all relevant zones X-Git-Tag: v2.4.0~227 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bfc9a2406be202eb9239e371560bf79863a58b9;p=icinga2 Don't log messages we've already relayed to all relevant zones fixes #10262 --- diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index c14abacc7..a5449181f 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -584,9 +584,6 @@ void ApiListener::SyncRelayMessage(const MessageOrigin::Ptr& origin, Log(LogNotice, "ApiListener") << "Relaying '" << message->Get("method") << "' message"; - if (log) - PersistMessage(message, secobj); - if (origin && origin->FromZone) message->Set("originZone", origin->FromZone->GetName()); @@ -595,15 +592,31 @@ void ApiListener::SyncRelayMessage(const MessageOrigin::Ptr& origin, Zone::Ptr my_zone = Zone::GetLocalZone(); std::vector skippedEndpoints; + std::set allZones; std::set finishedZones; + std::set finishedLogZones; BOOST_FOREACH(const Endpoint::Ptr& endpoint, ConfigType::GetObjectsByType()) { - /* 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); @@ -635,15 +648,14 @@ void ApiListener::SyncRelayMessage(const MessageOrigin::Ptr& origin, 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); }