Module: check_mk
Branch: master
Commit: d4299df890fdc9b98b9217b61fd7561709796661
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d4299df890fdc9…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Feb 27 12:44:25 2019 +0100
Decouple LogEntry from MonitoringCore, part 3.
Now we can remove quite a bit of dead code & fields and a handful of ugly
'#ifdef CMC' conditionals.
CMK-1753
Change-Id: If85d752e97fd67e19bf6a3d318d3ab38df26bc64
---
livestatus/src/LogEntry.cc | 26 ++++----------------------
livestatus/src/LogEntry.h | 9 +--------
livestatus/src/Logfile.cc | 30 ++----------------------------
livestatus/src/Logfile.h | 8 --------
4 files changed, 7 insertions(+), 66 deletions(-)
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index 591c1b3..7fabd1d 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -27,7 +27,6 @@
#include <stdexcept>
#include <unordered_map>
#include <utility>
-#include "MonitoringCore.h"
// 0123456789012345678901234567890
// [1234567890] FOO BAR: blah blah
@@ -35,13 +34,11 @@ static constexpr size_t timestamp_prefix_length = 13;
// TODO(sp) Fix classifyLogMessage() below to always set all fields and remove
// this set-me-to-zero-to-be-sure-block.
-LogEntry::LogEntry(MonitoringCore *mc, size_t lineno, std::string line)
+LogEntry::LogEntry(size_t lineno, std::string line)
: _lineno(static_cast<int32_t>(lineno))
, _message(std::move(line))
, _state(0)
- , _attempt(0)
- , _host(nullptr)
- , _service(nullptr) {
+ , _attempt(0) {
// pointer to options (everything after ':')
size_t pos = _message.find(':');
if (pos != std::string::npos) {
@@ -66,7 +63,6 @@ LogEntry::LogEntry(MonitoringCore *mc, size_t lineno, std::string line)
classifyLogMessage();
applyWorkarounds();
- updateReferences(mc);
}
bool LogEntry::assign(Param par, const std::string &field) {
@@ -389,28 +385,14 @@ std::unordered_map<std::string, HostState> hostStateTypes{
{"UNKNOWN", HostState::up}};
} // namespace
+// static
ServiceState LogEntry::parseServiceState(const std::string &str) {
auto it = serviceStateTypes.find(extractStateType(str));
return it == serviceStateTypes.end() ? ServiceState::ok : it->second;
}
+// static
HostState LogEntry::parseHostState(const std::string &str) {
auto it = hostStateTypes.find(extractStateType(str));
return it == hostStateTypes.end() ? HostState::up : it->second;
}
-
-unsigned LogEntry::updateReferences(MonitoringCore *mc) {
- unsigned updated = 0;
- if (!_host_name.empty()) {
- // TODO(sp): Remove ugly cast.
- _host = reinterpret_cast<host *>(mc->find_host(_host_name));
- updated++;
- }
- if (!_service_description.empty()) {
- // TODO(sp): Remove ugly cast.
- _service = reinterpret_cast<service *>(
- mc->find_service(_host_name, _service_description));
- updated++;
- }
- return updated;
-}
diff --git a/livestatus/src/LogEntry.h b/livestatus/src/LogEntry.h
index ac341bd..b2d6aff 100644
--- a/livestatus/src/LogEntry.h
+++ b/livestatus/src/LogEntry.h
@@ -30,8 +30,6 @@
#include <ctime>
#include <string>
#include <vector>
-#include "nagios.h"
-class MonitoringCore;
enum class ServiceState { ok = 0, warning = 1, critical = 2, unknown = 3 };
@@ -121,13 +119,8 @@ public:
std::string _plugin_output;
std::string _comment;
- // NOTE: The following two fields contain only derived information.
- host *_host;
- service *_service;
-
// NOTE: line gets modified!
- LogEntry(MonitoringCore *mc, size_t lineno, std::string line);
- unsigned updateReferences(MonitoringCore *mc);
+ LogEntry(size_t lineno, std::string line);
static ServiceState parseServiceState(const std::string &str);
static HostState parseHostState(const std::string &str);
diff --git a/livestatus/src/Logfile.cc b/livestatus/src/Logfile.cc
index 7d02c6d..a8fe802 100644
--- a/livestatus/src/Logfile.cc
+++ b/livestatus/src/Logfile.cc
@@ -35,10 +35,6 @@
#include "Logger.h"
#include "MonitoringCore.h"
-#ifdef CMC
-#include "cmc.h"
-#endif
-
namespace {
time_t firstTimestampOf(const fs::path &path, Logger *logger) {
std::ifstream is(path, std::ios::binary);
@@ -74,11 +70,7 @@ Logfile::Logfile(MonitoringCore *mc, LogCache *log_cache, fs::path
path,
, _watch(watch)
, _read_pos{}
, _lineno(0)
-#ifdef CMC
- , _world(nullptr)
-#endif
- , _logclasses_read(0) {
-}
+ , _logclasses_read(0) {}
void Logfile::flush() {
_entries.clear();
@@ -183,7 +175,7 @@ long Logfile::freeMessages(unsigned logclasses) {
bool Logfile::processLogLine(size_t lineno, std::string line,
unsigned logclasses) {
- auto entry = std::make_unique<LogEntry>(_mc, lineno, std::move(line));
+ auto entry = std::make_unique<LogEntry>(lineno, std::move(line));
// ignored invalid lines
if (entry->_class == LogEntry::Class::invalid) {
return false;
@@ -202,8 +194,6 @@ bool Logfile::processLogLine(size_t lineno, std::string line,
}
const logfile_entries_t *Logfile::getEntriesFor(unsigned logclasses) {
- // Make sure existing references to objects point to correct world
- updateReferences();
// make sure all messages are present
load(logclasses);
return &_entries;
@@ -214,20 +204,4 @@ uint64_t Logfile::makeKey(time_t t, size_t lineno) {
return (static_cast<uint64_t>(t) << 32) |
static_cast<uint64_t>(lineno);
}
-void Logfile::updateReferences() {
-#ifdef CMC
- // If our references in cached log entries do not point to the currently
- // active configuration world, then update all references
- if (_world != g_live_world) {
- unsigned num = 0;
- for (auto &entry : _entries) {
- num += entry.second->updateReferences(_mc);
- }
- Notice(logger()) << "updated " << num << " log
cache references of "
- << _path << " to new world.";
- _world = g_live_world;
- }
-#endif
-}
-
Logger *Logfile::logger() const { return _mc->loggerLivestatus(); }
diff --git a/livestatus/src/Logfile.h b/livestatus/src/Logfile.h
index f980344..6214c91 100644
--- a/livestatus/src/Logfile.h
+++ b/livestatus/src/Logfile.h
@@ -38,10 +38,6 @@ class LogEntry;
class Logger;
class MonitoringCore;
-#ifdef CMC
-class World;
-#endif
-
// key is time_t . lineno
using logfile_entries_t = std::map<uint64_t, std::unique_ptr<LogEntry>>;
@@ -72,15 +68,11 @@ private:
fpos_t _read_pos; // read until this position
size_t _lineno; // read until this line
logfile_entries_t _entries;
-#ifdef CMC
- World *_world; // CMC: world our references point into
-#endif
unsigned _logclasses_read; // only these types have been read
void load(unsigned logclasses);
void loadRange(FILE *file, unsigned missing_types, unsigned logclasses);
bool processLogLine(size_t lineno, std::string line, unsigned logclasses);
- void updateReferences();
Logger *logger() const;
};