mirror of https://github.com/Icinga/icinga2.git
Merge pull request #7027 from Icinga/feature/es-improve-error-handling
Elasticsearch: Improve error handling/logging
This commit is contained in:
commit
9f91ab98b8
|
@ -512,15 +512,13 @@ void ElasticsearchWriter::SendRequest(const String& body)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogWarning, "ElasticsearchWriter")
|
std::ostringstream msgbuf;
|
||||||
<< "Unexpected response code " << resp.StatusCode;
|
msgbuf << "Unexpected response code " << resp.StatusCode << " from URL '" << req.RequestUrl->Format() << "'";
|
||||||
|
|
||||||
String contentType = resp.Headers->Get("content-type");
|
String contentType = resp.Headers->Get("content-type");
|
||||||
|
|
||||||
if (contentType != "application/json") {
|
if (contentType != "application/json" && contentType != "application/json; charset=utf-8") {
|
||||||
Log(LogWarning, "ElasticsearchWriter")
|
msgbuf << "; Unexpected Content-Type: '" << contentType << "'";
|
||||||
<< "Unexpected Content-Type: " << contentType;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t responseSize = resp.GetBodySize();
|
size_t responseSize = resp.GetBodySize();
|
||||||
|
@ -528,6 +526,11 @@ void ElasticsearchWriter::SendRequest(const String& body)
|
||||||
resp.ReadBody(buffer.get(), responseSize);
|
resp.ReadBody(buffer.get(), responseSize);
|
||||||
buffer.get()[responseSize] = '\0';
|
buffer.get()[responseSize] = '\0';
|
||||||
|
|
||||||
|
#ifdef I2_DEBUG
|
||||||
|
msgbuf << "; Response body: '" << buffer.get() << "'";
|
||||||
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
|
/* {"statusCode":404,"error":"Not Found","message":"Not Found"} */
|
||||||
Dictionary::Ptr jsonResponse;
|
Dictionary::Ptr jsonResponse;
|
||||||
try {
|
try {
|
||||||
jsonResponse = JsonDecode(buffer.get());
|
jsonResponse = JsonDecode(buffer.get());
|
||||||
|
@ -540,7 +543,7 @@ void ElasticsearchWriter::SendRequest(const String& body)
|
||||||
String error = jsonResponse->Get("error");
|
String error = jsonResponse->Get("error");
|
||||||
|
|
||||||
Log(LogCritical, "ElasticsearchWriter")
|
Log(LogCritical, "ElasticsearchWriter")
|
||||||
<< "Elasticsearch error message:\n" << error;
|
<< "Error: '" << error << "'. " << msgbuf.str();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue