Module: check_mk
Branch: master
Commit: edf9882ac698242db40deeb97c973dfab5a57211
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=edf9882ac69824…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Jan 11 14:57:57 2017 +0100
Fetched livestatus from downstream.
Change-Id: I8af778bff0c72cae38e51ede8d86312d721d607d
---
livestatus/src/OutputBuffer.cc | 1 -
livestatus/src/OutputBuffer.h | 4 ----
livestatus/src/Query.cc | 8 ++++---
livestatus/src/Query.h | 3 ++-
livestatus/src/Store.cc | 52 ++++++++++++++++++++++--------------------
livestatus/src/Store.h | 2 +-
6 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/livestatus/src/OutputBuffer.cc b/livestatus/src/OutputBuffer.cc
index f84055b..cd701e5 100644
--- a/livestatus/src/OutputBuffer.cc
+++ b/livestatus/src/OutputBuffer.cc
@@ -57,7 +57,6 @@ void OutputBuffer::reset() {
// because of legacy reasons... :-/
_response_header = ResponseHeader::off;
_response_code = ResponseCode::ok;
- _do_keepalive = false;
_error_message = "";
}
diff --git a/livestatus/src/OutputBuffer.h b/livestatus/src/OutputBuffer.h
index 31680c3..7478176 100644
--- a/livestatus/src/OutputBuffer.h
+++ b/livestatus/src/OutputBuffer.h
@@ -56,9 +56,6 @@ public:
void setResponseHeader(ResponseHeader r) { _response_header = r; }
- void setDoKeepalive(bool d) { _do_keepalive = d; }
- bool doKeepalive() { return _do_keepalive; }
-
void setError(ResponseCode code, const std::string &message);
Logger *getLogger() const { return _logger; }
@@ -71,7 +68,6 @@ private:
ResponseHeader _response_header;
ResponseCode _response_code;
std::string _error_message;
- bool _do_keepalive;
Logger *const _logger;
// We use dynamically allocated memory => disable copy/assignment
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index 2f254e0..ee8114f 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -65,6 +65,7 @@ Query::Query(const list<string> &lines, Table *table, Encoding
data_encoding,
: _data_encoding(data_encoding)
, _output(output)
, _table(table)
+ , _keepalive(false)
, _auth_user(nullptr)
, _wait_timeout(0)
, _wait_trigger(nullptr)
@@ -530,9 +531,9 @@ void Query::parseKeepAliveLine(char *line) {
}
if (strcmp(value, "on") == 0) {
- _output.setDoKeepalive(true);
+ _keepalive = true;
} else if (strcmp(value, "off") == 0) {
- _output.setDoKeepalive(false);
+ _keepalive = false;
} else {
invalidHeader("Invalid value for KeepAlive: must be 'on' or
'off'");
}
@@ -664,7 +665,7 @@ void Query::parseLocaltimeLine(char *line) {
bool Query::doStats() { return !_stats_columns.empty(); }
-void Query::process() {
+bool Query::process() {
// Precondition: output has been reset
auto start_time = system_clock::now();
auto renderer = Renderer::make(_output_format, _output, _separators,
@@ -680,6 +681,7 @@ void Query::process() {
Informational(_logger) << "processed request in " <<
elapsed.count()
<< " ms, replied with " <<
_output.size()
<< " bytes";
+ return _keepalive;
}
void Query::start(QueryRenderer &q) {
diff --git a/livestatus/src/Query.h b/livestatus/src/Query.h
index ab8eb9e..be641b9 100644
--- a/livestatus/src/Query.h
+++ b/livestatus/src/Query.h
@@ -55,7 +55,7 @@ public:
Query(const std::list<std::string> &lines, Table *, Encoding
data_encoding,
OutputBuffer &output);
- void process();
+ bool process();
bool processDataset(void *);
@@ -78,6 +78,7 @@ private:
OutputBuffer &_output;
QueryRenderer *_renderer_query;
Table *_table;
+ bool _keepalive;
AndingFilter _filter;
contact *_auth_user;
AndingFilter _wait_condition;
diff --git a/livestatus/src/Store.cc b/livestatus/src/Store.cc
index 39ada20..e1f3ea4 100644
--- a/livestatus/src/Store.cc
+++ b/livestatus/src/Store.cc
@@ -40,11 +40,11 @@
#include "Table.h"
#include "data_encoding.h"
#include "mk_logwatch.h"
-#include "strutil.h"
extern Encoding g_data_encoding;
extern unsigned long g_max_cached_messages;
+using mk::lstrip;
using mk::split;
using mk::starts_with;
using std::list;
@@ -161,36 +161,38 @@ bool Store::answerRequest(InputBuffer &input, OutputBuffer
&output) {
}
return false;
}
- string l = input.nextLine();
- const char *line = l.c_str();
- if (strncmp(line, "GET ", 4) == 0) {
+ string line = input.nextLine();
+ if (starts_with(line, "GET ")) {
auto lines = getLines(input);
- logRequest(l, lines);
- answerGetRequest(lines, output, lstrip(const_cast<char *>(line) + 4));
- } else if (strcmp(line, "GET") == 0) {
+ logRequest(line, lines);
+ return answerGetRequest(lines, output, lstrip(line.substr(4)));
+ }
+ if (starts_with(line, "GET")) {
// only to get error message
auto lines = getLines(input);
- logRequest(l, lines);
- answerGetRequest(lines, output, "");
- } else if (strncmp(line, "COMMAND ", 8) == 0) {
- logRequest(l, {});
- answerCommandRequest(lstrip(const_cast<char *>(line) + 8));
- output.setDoKeepalive(true);
- } else if (strncmp(line, "LOGROTATE", 9) == 0) {
- logRequest(l, {});
+ logRequest(line, lines);
+ return answerGetRequest(lines, output, "");
+ }
+ if (starts_with(line, "COMMAND ")) {
+ logRequest(line, {});
+ answerCommandRequest(lstrip(line.substr(8)).c_str());
+ return true;
+ }
+ if (starts_with(line, "LOGROTATE")) {
+ logRequest(line, {});
Informational(_logger) << "Forcing logfile rotation";
rotate_log_file(time(nullptr));
schedule_new_event(EVENT_LOG_ROTATION, 1, get_next_log_rotation_time(),
0, 0,
reinterpret_cast<void *>(get_next_log_rotation_time),
1, nullptr, nullptr, 0);
- } else {
- logRequest(l, {});
- Warning(_logger) << "Invalid request '" << l <<
"'";
- output.setError(OutputBuffer::ResponseCode::invalid_request,
- "Invalid request method");
+ return false;
}
- return output.doKeepalive();
+ logRequest(line, {});
+ Warning(_logger) << "Invalid request '" << line <<
"'";
+ output.setError(OutputBuffer::ResponseCode::invalid_request,
+ "Invalid request method");
+ return false;
}
void Store::answerCommandRequest(const char *command) {
@@ -266,12 +268,12 @@ bool Store::handleCommand(const string &command) {
return false;
}
-void Store::answerGetRequest(const list<string> &lines, OutputBuffer
&output,
+bool Store::answerGetRequest(const list<string> &lines, OutputBuffer
&output,
const string &tablename) {
if (tablename.empty()) {
output.setError(OutputBuffer::ResponseCode::invalid_request,
"Invalid GET request, missing tablename");
- return;
+ return false;
}
Table *table = findTable(tablename);
@@ -279,8 +281,8 @@ void Store::answerGetRequest(const list<string> &lines,
OutputBuffer &output,
output.setError(
OutputBuffer::ResponseCode::not_found,
"Invalid GET request, no such table '" + string(tablename) +
"'");
- return;
+ return false;
}
- Query(lines, table, g_data_encoding, output).process();
+ return Query(lines, table, g_data_encoding, output).process();
}
diff --git a/livestatus/src/Store.h b/livestatus/src/Store.h
index 675b193..8b51c05 100644
--- a/livestatus/src/Store.h
+++ b/livestatus/src/Store.h
@@ -106,7 +106,7 @@ private:
Table *findTable(const std::string &name);
void logRequest(const std::string &line,
const std::list<std::string> &lines);
- void answerGetRequest(const std::list<std::string> &lines,
+ bool answerGetRequest(const std::list<std::string> &lines,
OutputBuffer &output, const std::string &tablename);
void answerCommandRequest(const char *);
bool handleCommand(const std::string &command);