]> granicus.if.org Git - icinga2/commitdiff
Fix: Icinga doesn't send SetLogPosition messages when one of the endpoints fails...
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Jun 2014 08:00:02 +0000 (10:00 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 23 Jun 2014 08:00:02 +0000 (10:00 +0200)
fixes #6537

lib/remote/apilistener.cpp
lib/remote/apilistener.hpp
lib/remote/endpoint.ti

index e74841cb9eca124e79f87d02dd7ffe386a523ff2..c666a701b459330bf8a3ead9dc8bcaf64c05f210 100644 (file)
@@ -197,12 +197,11 @@ void ApiListener::ListenerThreadProc(const Socket::Ptr& server)
 }
 
 /**
- * Creates a new JSON-RPC client and connects to the specified host and port.
+ * Creates a new JSON-RPC client and connects to the specified endpoint.
  *
- * @param node The remote host.
- * @param service The remote port.
+ * @param endpoint The endpoint.
  */
-void ApiListener::AddConnection(const String& node, const String& service)
+void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
 {
        {
                ObjectLock olock(this);
@@ -215,14 +214,21 @@ void ApiListener::AddConnection(const String& node, const String& service)
                }
        }
 
+       String host = endpoint->GetHost();
+       String port = endpoint->GetPort();
+
        TcpSocket::Ptr client = make_shared<TcpSocket>();
 
        try {
-               client->Connect(node, service);
-               Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleClient));
+               endpoint->SetConnecting(true);
+               client->Connect(host, port);
+               NewClientHandler(client, RoleClient);
+               endpoint->SetConnecting(false);
        } catch (const std::exception& ex) {
+               endpoint->SetConnecting(false);
+
                std::ostringstream info, debug;
-               info << "Cannot connect to host '" << node << "' on port '" << service << "'";
+               info << "Cannot connect to host '" << host << "' on port '" << port << "'";
                debug << info.str() << std::endl << DiagnosticInformation(ex);
                Log(LogCritical, "ApiListener", info.str());
                Log(LogDebug, "ApiListener", debug.str());
@@ -358,7 +364,7 @@ void ApiListener::ApiTimerHandler(void)
                                if (endpoint->GetHost().IsEmpty() || endpoint->GetPort().IsEmpty())
                                        continue;
 
-                               AddConnection(endpoint->GetHost(), endpoint->GetPort());
+                               Utility::QueueAsyncCallback(boost::bind(&ApiListener::AddConnection, this, endpoint));
                        }
                }
        }
index a8a8609d9ad6538347471e6e4c52cfafc18ef020..8d95337d940f11d08e9072b9ddeb67fb1471e038 100644 (file)
@@ -80,7 +80,7 @@ private:
        void ApiTimerHandler(void);
 
        void AddListener(const String& service);
-       void AddConnection(const String& node, const String& service);
+       void AddConnection(const Endpoint::Ptr& endpoint);
 
        void NewClientHandler(const Socket::Ptr& client, ConnectionRole role);
        void ListenerThreadProc(const Socket::Ptr& server);
index cc06414db14a3529625ce786c1a9df871d1b917d..2ea5e0ebff6c69116a6971a12f94194934d19a73 100644 (file)
@@ -16,6 +16,7 @@ class Endpoint : DynamicObject
        [state] double local_log_position;
        [state] double remote_log_position;
 
+       bool connecting;
        bool syncing;
 };