]> granicus.if.org Git - icinga2/commitdiff
Fix connection error handling in Elasticsearch and InfluxDB features 6401/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Thu, 21 Jun 2018 13:41:40 +0000 (15:41 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 21 Jun 2018 13:41:40 +0000 (15:41 +0200)
Previously this would just throw the entire exception stack trace
which is not needed here.

fixes #6394

lib/perfdata/elasticsearchwriter.cpp
lib/perfdata/influxdbwriter.cpp

index 2e8ffa5159e4879f8d2ebe9387cad7e112e291df..d9d56b00472a6d22761064a98d0ae2bf31a3b697 100644 (file)
@@ -428,7 +428,19 @@ void ElasticsearchWriter::SendRequest(const String& body)
 
        url->SetPath(path);
 
-       Stream::Ptr stream = Connect();
+       Stream::Ptr stream;
+
+       try {
+               stream = Connect();
+       } catch (const std::exception& ex) {
+               Log(LogWarning, "ElasticsearchWriter")
+                       << "Flush failed, cannot connect to Elasticsearch.";
+               return;
+       }
+
+       if (!stream)
+               return;
+
        HttpRequest req(stream);
 
        /* Specify required headers by Elasticsearch. */
index 8a3fe97b19366a949b593f0e80afd48a73763075..89cf13220db1222cfe6778141ea140f4436956ad 100644 (file)
@@ -419,7 +419,15 @@ void InfluxdbWriter::Flush()
        String body = boost::algorithm::join(m_DataBuffer, "\n");
        m_DataBuffer.clear();
 
-       Stream::Ptr stream = Connect();
+       Stream::Ptr stream;
+
+       try {
+               stream = Connect();
+       } catch (const std::exception& ex) {
+               Log(LogWarning, "InfluxDbWriter")
+                       << "Flush failed, cannot connect to InfluxDB.";
+               return;
+       }
 
        if (!stream)
                return;