mirror of https://github.com/Icinga/icinga2.git
Merge pull request #5241 from Icinga/fix/influxdb-error-log
Verbose InfluxDB Error Logging fixes #4411
This commit is contained in:
commit
9bb2c11c8d
|
@ -34,6 +34,7 @@
|
|||
#include "base/convert.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include "base/stream.hpp"
|
||||
#include "base/json.hpp"
|
||||
#include "base/networkstream.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include "base/statsfunction.hpp"
|
||||
|
@ -43,6 +44,7 @@
|
|||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/scoped_array.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
|
@ -507,6 +509,36 @@ void InfluxdbWriter::FlushHandler(const String& body)
|
|||
if (resp.StatusCode != 204) {
|
||||
Log(LogWarning, "InfluxdbWriter")
|
||||
<< "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") {
|
||||
Log(LogWarning, "InfluxdbWriter")
|
||||
<< "Unexpected Content-Type: " << contentType;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t responseSize = resp.GetBodySize();
|
||||
boost::scoped_array<char> buffer(new char[responseSize + 1]);
|
||||
resp.ReadBody(buffer.get(), responseSize);
|
||||
buffer.get()[responseSize] = '\0';
|
||||
|
||||
Dictionary::Ptr jsonResponse;
|
||||
try {
|
||||
jsonResponse = JsonDecode(buffer.get());
|
||||
} catch (...) {
|
||||
Log(LogWarning, "InfluxdbWriter")
|
||||
<< "Unable to parse JSON response:\n" << buffer.get();
|
||||
return;
|
||||
}
|
||||
|
||||
String error = jsonResponse->Get("error");
|
||||
|
||||
Log(LogCritical, "InfluxdbWriter")
|
||||
<< "InfluxDB error message:\n" << error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -241,6 +241,14 @@ size_t HttpResponse::ReadBody(char *data, size_t count)
|
|||
return m_Body->Read(data, count, true);
|
||||
}
|
||||
|
||||
size_t HttpResponse::GetBodySize(void) const
|
||||
{
|
||||
if (!m_Body)
|
||||
return 0;
|
||||
else
|
||||
return m_Body->GetAvailableBytes();
|
||||
}
|
||||
|
||||
bool HttpResponse::IsPeerConnected(void) const
|
||||
{
|
||||
return !m_Stream->IsEof();
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
|
||||
bool Parse(StreamReadContext& src, bool may_wait);
|
||||
size_t ReadBody(char *data, size_t count);
|
||||
size_t GetBodySize(void) const;
|
||||
|
||||
void SetStatus(int code, const String& message);
|
||||
void AddHeader(const String& key, const String& value);
|
||||
|
|
Loading…
Reference in New Issue