mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 21:24:41 +02:00
Merge pull request #5840 from Icinga/fix/elasticsearch-writer-6
Fix newline terminator for bulk requests in ElasticsearchWriter
This commit is contained in:
commit
13895b43a2
@ -347,7 +347,7 @@ The check results include parsed performance data metrics if enabled.
|
|||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
>
|
>
|
||||||
> Elasticsearch 5.x+ is required.
|
> Elasticsearch 5.x+ is required. This feature has been tested with Elasticsearch 5.6.4 and 6.0.0.
|
||||||
|
|
||||||
Enable the feature and restart Icinga 2.
|
Enable the feature and restart Icinga 2.
|
||||||
|
|
||||||
|
@ -396,6 +396,11 @@ void ElasticsearchWriter::Flush(void)
|
|||||||
String body = boost::algorithm::join(m_DataBuffer, "\n");
|
String body = boost::algorithm::join(m_DataBuffer, "\n");
|
||||||
m_DataBuffer.clear();
|
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);
|
SendRequest(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,12 +460,20 @@ void ElasticsearchWriter::SendRequest(const String& body)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
resp.Parse(context, true);
|
resp.Parse(context, true);
|
||||||
|
while (resp.Parse(context, true) && !resp.Complete)
|
||||||
|
; /* Do nothing */
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Log(LogWarning, "ElasticsearchWriter")
|
Log(LogWarning, "ElasticsearchWriter")
|
||||||
<< "Cannot read from HTTP API on host '" << GetHost() << "' port '" << GetPort() << "'.";
|
<< "Failed to parse HTTP response from host '" << GetHost() << "' port '" << GetPort() << "': " << DiagnosticInformation(ex, false);
|
||||||
throw ex;
|
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 > 299) {
|
||||||
if (resp.StatusCode == 401) {
|
if (resp.StatusCode == 401) {
|
||||||
/* More verbose error logging with Elasticsearch is hidden behind a proxy. */
|
/* More verbose error logging with Elasticsearch is hidden behind a proxy. */
|
||||||
@ -479,10 +492,6 @@ void ElasticsearchWriter::SendRequest(const String& body)
|
|||||||
Log(LogWarning, "ElasticsearchWriter")
|
Log(LogWarning, "ElasticsearchWriter")
|
||||||
<< "Unexpected response code " << resp.StatusCode;
|
<< "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");
|
String contentType = resp.Headers->Get("content-type");
|
||||||
|
|
||||||
if (contentType != "application/json") {
|
if (contentType != "application/json") {
|
||||||
@ -509,6 +518,8 @@ void ElasticsearchWriter::SendRequest(const String& body)
|
|||||||
|
|
||||||
Log(LogCritical, "ElasticsearchWriter")
|
Log(LogCritical, "ElasticsearchWriter")
|
||||||
<< "Elasticsearch error message:\n" << error;
|
<< "Elasticsearch error message:\n" << error;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user