From: Michael Friedrich Date: Thu, 21 Jun 2018 13:41:40 +0000 (+0200) Subject: Fix connection error handling in Elasticsearch and InfluxDB features X-Git-Tag: v2.9.0~19^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ea0650edc1a25ea974ffa8c1183386c6b15e405;p=icinga2 Fix connection error handling in Elasticsearch and InfluxDB features Previously this would just throw the entire exception stack trace which is not needed here. fixes #6394 --- diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 2e8ffa515..d9d56b004 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -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. */ diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 8a3fe97b1..89cf13220 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -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;