From: Michael Friedrich Date: Fri, 22 Dec 2017 08:53:56 +0000 (+0100) Subject: Revert "Fix newline terminator for bulk requests in ElasticsearchWriter" X-Git-Tag: v2.8.1~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1256fb3356e984c7da9b0eec29ce799a1a61ab8a;p=icinga2 Revert "Fix newline terminator for bulk requests in ElasticsearchWriter" This reverts commit 806eb0d2d2b077a9a4bac073bfbb27c2af369008. refs #5840 --- diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 2171752ca..69221fd88 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -395,11 +395,6 @@ void ElasticsearchWriter::Flush(void) String body = boost::algorithm::join(m_DataBuffer, "\n"); m_DataBuffer.clear(); - /* Elasticsearch 6.x requires a new line. This is compatible to 5.x. - * Tested with 6.0.0 and 5.6.4. - */ - body += "\n"; - SendRequest(body); } @@ -459,20 +454,12 @@ void ElasticsearchWriter::SendRequest(const String& body) try { resp.Parse(context, true); - while (resp.Parse(context, true) && !resp.Complete) - ; /* Do nothing */ } catch (const std::exception& ex) { Log(LogWarning, "ElasticsearchWriter") - << "Failed to parse HTTP response from host '" << GetHost() << "' port '" << GetPort() << "': " << DiagnosticInformation(ex, false); + << "Cannot read from HTTP API on host '" << GetHost() << "' port '" << GetPort() << "'."; throw ex; } - if (!resp.Complete) { - Log(LogWarning, "ElasticsearchWriter") - << "Failed to read a complete HTTP response from the Elasticsearch server."; - return; - } - if (resp.StatusCode > 299) { if (resp.StatusCode == 401) { /* More verbose error logging with Elasticsearch is hidden behind a proxy. */ @@ -491,6 +478,10 @@ void ElasticsearchWriter::SendRequest(const String& body) Log(LogWarning, "ElasticsearchWriter") << "Unexpected response code " << resp.StatusCode; + /* Finish parsing the headers and body. */ + while (!resp.Complete) + resp.Parse(context, true); + String contentType = resp.Headers->Get("content-type"); if (contentType != "application/json") { @@ -517,8 +508,6 @@ void ElasticsearchWriter::SendRequest(const String& body) Log(LogCritical, "ElasticsearchWriter") << "Elasticsearch error message:\n" << error; - - return; } }