From 9ea0650edc1a25ea974ffa8c1183386c6b15e405 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Jun 2018 15:41:40 +0200 Subject: [PATCH] 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 --- lib/perfdata/elasticsearchwriter.cpp | 14 +++++++++++++- lib/perfdata/influxdbwriter.cpp | 10 +++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) 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; -- 2.50.0