Module: check_mk
Branch: master
Commit: d8a325fa18dc77633fc49e5fd3787900a9ebda94
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d8a325fa18dc77…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri May 5 11:40:29 2017 +0200
Removed a few more global variables. Slightly improved types.
Change-Id: If9d462f6db2be4a551ee54a359a1b5d07664c14f
---
livestatus/src/MonitoringCore.h | 4 ++++
livestatus/src/Query.cc | 9 ++++-----
livestatus/src/Query.h | 3 ++-
livestatus/src/Store.cc | 10 ++++------
livestatus/src/module.cc | 25 ++++++++++++++-----------
5 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 1c2bdbc..c950604 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -29,6 +29,7 @@
#include <chrono>
#include <string>
#include <vector>
+#include "data_encoding.h"
class Logger;
struct Command {
@@ -86,6 +87,9 @@ public:
virtual std::string mkInventoryPath() = 0;
virtual std::string pnpPath() = 0;
virtual std::string logArchivePath() = 0;
+ virtual Encoding dataEncoding() = 0;
+ virtual size_t maxResponseSize() = 0;
+ virtual size_t maxCachedMessages() = 0;
virtual Logger *loggerLivestatus() = 0;
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index 2f67923..3abae15 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -51,8 +51,6 @@
#include "nagios.h"
#endif
-extern unsigned long g_max_response_size;
-
using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::chrono::system_clock;
@@ -68,8 +66,9 @@ using std::unique_ptr;
using std::vector;
Query::Query(const list<string> &lines, Table *table, Encoding data_encoding,
- OutputBuffer &output)
+ size_t max_response_size, OutputBuffer &output)
: _data_encoding(data_encoding)
+ , _max_response_size(max_response_size)
, _output(output)
, _table(table)
, _keepalive(false)
@@ -721,9 +720,9 @@ bool Query::timelimitReached() {
}
bool Query::processDataset(Row row) {
- if (_renderer_query->size() > g_max_response_size) {
+ if (_renderer_query->size() > _max_response_size) {
Informational(_logger) << "Maximum response size of "
- << g_max_response_size << " bytes
exceeded!";
+ << _max_response_size << " bytes
exceeded!";
// currently we only log an error into the log file and do
// not abort the query. We handle it like Limit:
return false;
diff --git a/livestatus/src/Query.h b/livestatus/src/Query.h
index e723486..2609f50 100644
--- a/livestatus/src/Query.h
+++ b/livestatus/src/Query.h
@@ -54,7 +54,7 @@ class Table;
class Query {
public:
Query(const std::list<std::string> &lines, Table *, Encoding
data_encoding,
- OutputBuffer &output);
+ size_t max_response_size, OutputBuffer &output);
bool process();
@@ -76,6 +76,7 @@ public:
private:
const Encoding _data_encoding;
+ const size_t _max_response_size;
OutputBuffer &_output;
QueryRenderer *_renderer_query;
Table *_table;
diff --git a/livestatus/src/Store.cc b/livestatus/src/Store.cc
index 2678a57..d30b08e 100644
--- a/livestatus/src/Store.cc
+++ b/livestatus/src/Store.cc
@@ -39,12 +39,8 @@
#include "Query.h"
#include "StringUtils.h"
#include "Table.h"
-#include "data_encoding.h"
#include "mk_logwatch.h"
-extern Encoding g_data_encoding;
-extern unsigned long g_max_cached_messages;
-
using mk::lstrip;
using mk::split;
using mk::starts_with;
@@ -55,7 +51,7 @@ using std::string;
Store::Store(MonitoringCore *mc)
: _mc(mc)
- , _log_cache(mc, g_max_cached_messages)
+ , _log_cache(mc, mc->maxCachedMessages())
, _table_columns(mc)
, _table_commands(mc)
, _table_comments(mc)
@@ -281,7 +277,9 @@ bool Store::answerGetRequest(const list<string> &lines,
OutputBuffer &output,
return false;
}
- return Query(lines, table, g_data_encoding, output).process();
+ return Query(lines, table, _mc->dataEncoding(), _mc->maxResponseSize(),
+ output)
+ .process();
}
Logger *Store::logger() const { return _mc->loggerLivestatus(); }
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 2b62e45..dd55075 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -118,14 +118,14 @@ struct ThreadInfo {
static vector<ThreadInfo> fl_thread_info;
static thread_local ThreadInfo *tl_info;
-unsigned long g_max_cached_messages = 500000;
+size_t fl_max_cached_messages = 500000;
// do never read more than that number of lines from a logfile
static uint32_t fl_max_lines_per_logfile = 1000000;
-unsigned long g_max_response_size = 100 * 1024 * 1024; // limit answer to 10 MB
+size_t fl_max_response_size = 100 * 1024 * 1024; // limit answer to 10 MB
int g_thread_running = 0;
AuthorizationKind g_service_authorization = AuthorizationKind::loose;
AuthorizationKind g_group_authorization = AuthorizationKind::strict;
-Encoding g_data_encoding = Encoding::utf8;
+Encoding fl_data_encoding = Encoding::utf8;
// Map to speed up access via name/alias/address
unordered_map<string, host *> fl_hosts_by_designation;
@@ -652,6 +652,9 @@ public:
extern char *log_archive_path;
return log_archive_path;
}
+ Encoding dataEncoding() override { return fl_data_encoding; }
+ size_t maxResponseSize() override { return fl_max_response_size; }
+ size_t maxCachedMessages() override { return fl_max_cached_messages; }
Logger *loggerLivestatus() override { return fl_logger_livestatus; }
@@ -906,10 +909,10 @@ void livestatus_parse_arguments(const char *args_orig) {
strncpy(fl_mkeventd_socket_path, right,
sizeof(fl_mkeventd_socket_path));
} else if (strcmp(left, "max_cached_messages") == 0) {
- g_max_cached_messages = strtoul(right, nullptr, 10);
+ fl_max_cached_messages = strtoul(right, nullptr, 10);
Notice(fl_logger_nagios)
<< "setting max number of cached log messages to "
- << g_max_cached_messages;
+ << fl_max_cached_messages;
} else if (strcmp(left, "max_lines_per_logfile") == 0) {
fl_max_lines_per_logfile = strtoul(right, nullptr, 10);
Notice(fl_logger_nagios)
@@ -920,11 +923,11 @@ void livestatus_parse_arguments(const char *args_orig) {
Notice(fl_logger_nagios) << "setting size of thread stacks to
"
<< g_thread_stack_size;
} else if (strcmp(left, "max_response_size") == 0) {
- g_max_response_size = strtoul(right, nullptr, 10);
+ fl_max_response_size = strtoul(right, nullptr, 10);
Notice(fl_logger_nagios)
<< "setting maximum response size to "
- << g_max_response_size << " bytes ("
- << (g_max_response_size / (1024.0 * 1024.0)) << "
MB)";
+ << fl_max_response_size << " bytes ("
+ << (fl_max_response_size / (1024.0 * 1024.0)) << "
MB)";
} else if (strcmp(left, "num_client_threads") == 0) {
int c = atoi(right);
if (c <= 0 || c > 1000) {
@@ -1014,11 +1017,11 @@ void livestatus_parse_arguments(const char *args_orig) {
check_path("Check_MK logwatch directory",
fl_mk_logwatch_path);
} else if (strcmp(left, "data_encoding") == 0) {
if (strcmp(right, "utf8") == 0) {
- g_data_encoding = Encoding::utf8;
+ fl_data_encoding = Encoding::utf8;
} else if (strcmp(right, "latin1") == 0) {
- g_data_encoding = Encoding::latin1;
+ fl_data_encoding = Encoding::latin1;
} else if (strcmp(right, "mixed") == 0) {
- g_data_encoding = Encoding::mixed;
+ fl_data_encoding = Encoding::mixed;
} else {
Warning(fl_logger_nagios)
<< "invalid data_encoding " << right