]> granicus.if.org Git - icinga2/commitdiff
Make critical connection errors readable in ApiListener.
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 22 May 2014 11:45:42 +0000 (13:45 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 22 May 2014 14:07:57 +0000 (16:07 +0200)
Refs #6070

lib/remote/apilistener.cpp

index 60dbb14be66b285a1bbcc2e32cd5eaa7de8ff08d..1612e749cf5a48854986193f6bfe994f6d4ef634 100644 (file)
@@ -163,7 +163,8 @@ void ApiListener::ListenerThreadProc(const Socket::Ptr& server)
  * @param node The remote host.
  * @param service The remote port.
  */
-void ApiListener::AddConnection(const String& node, const String& service) {
+void ApiListener::AddConnection(const String& node, const String& service)
+{
        {
                ObjectLock olock(this);
 
@@ -175,8 +176,16 @@ void ApiListener::AddConnection(const String& node, const String& service) {
 
        TcpSocket::Ptr client = make_shared<TcpSocket>();
 
-       client->Connect(node, service);
-       Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleClient));
+       try {
+               client->Connect(node, service);
+               Utility::QueueAsyncCallback(boost::bind(&ApiListener::NewClientHandler, this, client, RoleClient));
+       } catch (const std::exception& ex) {
+               std::ostringstream info, debug;
+               info << "Cannot connect to host '" << node << "' on port '" << service << "'.";
+               debug << info << std::endl << DiagnosticInformation(ex);
+               Log(LogCritical, "remote", info.str());
+               Log(LogDebug, "remote", debug.str());
+       }
 }
 
 /**