diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 8cd788ad1..38c8a718d 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -81,28 +81,28 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che } bool connected = false; - double lag = 0; + double zoneLag = 0; BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) { - double eplag = Utility::GetTime() - endpoint->GetRemoteLogPosition(); - if (endpoint->IsConnected()) connected = true; - if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && eplag > lag) - lag = eplag; + double eplag = ApiListener::CalculateZoneLag(endpoint); + + if (eplag > 0 && eplag > zoneLag) + zoneLag = eplag; } if (!connected) { cr->SetState(ServiceCritical); - cr->SetOutput("Zone '" + zoneName + "' is not connected. Log lag: " + Utility::FormatDuration(lag)); + cr->SetOutput("Zone '" + zoneName + "' is not connected. Log lag: " + Utility::FormatDuration(zoneLag)); } else { cr->SetState(ServiceOK); - cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(lag)); + cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(zoneLag)); } Array::Ptr perfdata = new Array(); - perfdata->Add(new PerfdataValue("slave_lag", lag)); + perfdata->Add(new PerfdataValue("slave_lag", zoneLag)); cr->SetPerformanceData(perfdata); checkable->ProcessCheckResult(cr); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 101efccfe..c2173cfaa 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -836,6 +836,17 @@ std::pair ApiListener::GetStatus(void) return std::make_pair(status, perfdata); } +double ApiListener::CalculateZoneLag(const Endpoint::Ptr& endpoint) +{ + double remoteLogPosition = endpoint->GetRemoteLogPosition(); + double eplag = Utility::GetTime() - remoteLogPosition; + + if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && remoteLogPosition != 0) + return eplag; + + return 0; +} + void ApiListener::AddAnonymousClient(const ApiClient::Ptr& aclient) { ObjectLock olock(this); diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 71a33e578..74e39b534 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -68,9 +68,12 @@ public: void RemoveAnonymousClient(const ApiClient::Ptr& aclient); std::set GetAnonymousClients(void) const; + static double CalculateZoneLag(const Endpoint::Ptr& endpoint); + static Value ConfigUpdateHandler(const MessageOrigin& origin, const Dictionary::Ptr& params); static Value HelloAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params); + protected: virtual void OnConfigLoaded(void); virtual void OnAllConfigLoaded(void);