Module: check_mk
Branch: master
Commit: fe2d9e5b239111086e6bff59ca1391aef931372d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fe2d9e5b239111…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Oct 5 17:49:26 2013 +0200
Some fixes for CMC
---
livestatus/src/LogCache.cc | 13 ++-----------
livestatus/src/LogCache.h | 2 --
livestatus/src/LogEntry.cc | 31 +++++++++++++++++++++++--------
livestatus/src/LogEntry.h | 1 +
livestatus/src/Logfile.cc | 34 +++++++++++++++++++++++++++++-----
livestatus/src/Logfile.h | 25 +++++++++++++++----------
6 files changed, 70 insertions(+), 36 deletions(-)
diff --git a/livestatus/src/LogCache.cc b/livestatus/src/LogCache.cc
index 9f5b025..9261be8 100644
--- a/livestatus/src/LogCache.cc
+++ b/livestatus/src/LogCache.cc
@@ -52,7 +52,7 @@ int num_cached_log_messages = 0;
// Debugging logging is hard if debug messages are logged themselves...
void debug(const char *loginfo, ...)
{
- if (g_debug_level < 2)
+ if (g_debug_level >= 3)
return;
FILE *x = fopen("/tmp/livestatus.log", "a+");
@@ -67,7 +67,6 @@ void debug(const char *loginfo, ...)
LogCache::LogCache(unsigned long max_cached_messages)
: _max_cached_messages(max_cached_messages)
, _num_at_last_check(0)
- , _my_world(0)
{
pthread_mutex_init(&_lock, 0);
updateLogfileIndex();
@@ -100,12 +99,6 @@ void LogCache::unlockLogCache()
bool LogCache::logCachePreChecks()
{
-#ifdef CMC
- if (g_live_world != _my_world) {
- forgetLogfiles();
- updateLogfileIndex();
- }
-#endif
// Do we have any logfiles (should always be the case,
// but we don't want to crash...
if (_logfiles.size() == 0) {
@@ -125,6 +118,7 @@ bool LogCache::logCachePreChecks()
void LogCache::forgetLogfiles()
{
+ logger(LOG_INFO, "Logfile cache: flushing complete cache.");
for (_logfiles_t::iterator it = _logfiles.begin();
it != _logfiles.end();
++it)
@@ -133,9 +127,6 @@ void LogCache::forgetLogfiles()
}
_logfiles.clear();
num_cached_log_messages = 0;
-#ifdef CMC
- _my_world = g_live_world;
-#endif
}
void LogCache::updateLogfileIndex()
diff --git a/livestatus/src/LogCache.h b/livestatus/src/LogCache.h
index a3c1bd3..5d795a4 100644
--- a/livestatus/src/LogCache.h
+++ b/livestatus/src/LogCache.h
@@ -31,7 +31,6 @@
#include "Table.h"
class Logfile;
-class World;
typedef map<time_t, Logfile *> _logfiles_t;
@@ -47,7 +46,6 @@ public:
~LogCache();
void setMaxCachedMessages(unsigned long m);
time_t _last_index_update;
- World *_my_world;
const char *name() { return "log"; }
const char *prefixname() { return "logs"; }
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index 1ef92e2..23724c4 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -79,14 +79,7 @@ LogEntry::LogEntry(unsigned lineno, char *line, unsigned logclasses =
LOGCLASS_A
((1 << LOGCLASS_COMMAND & logclasses) &&
handleExternalCommandEntry())
)
{
- if (_host_name)
- _host = find_host(_host_name);
- if (_svc_desc)
- _service = find_service(_host_name, _svc_desc);
- if (_contact_name)
- _contact = find_contact(_contact_name);
- if (_command_name)
- _command = find_command(_command_name);
+ updateReferences();
}
else {
(1 << LOGCLASS_PROGRAM & logclasses) && handleProgrammEntry();
// Performance killer strstr!
@@ -396,3 +389,25 @@ inline int LogEntry::hostStateToInt(char *s)
}
}
+
+unsigned LogEntry::updateReferences()
+{
+ unsigned updated = 0;
+ if (_host_name) {
+ _host = find_host(_host_name);
+ updated++;
+ }
+ if (_svc_desc) {
+ _service = find_service(_host_name, _svc_desc);
+ updated++;
+ }
+ if (_contact_name) {
+ _contact = find_contact(_contact_name);
+ updated++;
+ }
+ if (_command_name) {
+ _command = find_command(_command_name);
+ updated++;
+ }
+ return updated;
+}
diff --git a/livestatus/src/LogEntry.h b/livestatus/src/LogEntry.h
index bd39006..b744b64 100644
--- a/livestatus/src/LogEntry.h
+++ b/livestatus/src/LogEntry.h
@@ -84,6 +84,7 @@ struct LogEntry
LogEntry(unsigned lineno, char *line, unsigned logclasses);
~LogEntry();
+ unsigned updateReferences();
private:
bool handleStatusEntry();
diff --git a/livestatus/src/Logfile.cc b/livestatus/src/Logfile.cc
index cef5b1a..472973e 100644
--- a/livestatus/src/Logfile.cc
+++ b/livestatus/src/Logfile.cc
@@ -33,6 +33,11 @@
#include "Query.h"
#include "LogCache.h"
+#ifdef CMC
+#include "Core.h"
+extern Core *g_core;
+#endif
+
Logfile::Logfile(const char *path, bool watch)
: _path(strdup(path))
@@ -68,14 +73,14 @@ Logfile::Logfile(const char *path, bool watch)
Logfile::~Logfile()
{
- free(_path);
flush();
+ free(_path);
}
void Logfile::flush()
{
- for (logfile_entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it)
+ for (logfile_entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it)
delete it->second;
_entries.clear();
@@ -112,7 +117,7 @@ void Logfile::load(LogCache *logcache, time_t since, time_t until,
unsigned logc
fgetpos(file, &_read_pos);
}
if (missing_types) {
- fseek(file, 0, SEEK_SET);
+ fseek(file, 0, SEEK_SET);
_lineno = 0;
loadRange(file, missing_types, logcache, since, until, logclasses);
_logclasses_read |= missing_types;
@@ -194,12 +199,14 @@ inline bool Logfile::processLogLine(uint32_t lineno, unsigned
logclasses)
logfile_entries_t* Logfile::getEntriesFromQuery(Query *query, LogCache *logcache, time_t
since, time_t until, unsigned logclasses)
{
- load(logcache, since, until, logclasses); // make sure all messages are present
- return &_entries;
+ updateReferences();
+ load(logcache, since, until, logclasses); // make sure all messages are present
+ return &_entries;
}
bool Logfile::answerQuery(Query *query, LogCache *logcache, time_t since, time_t until,
unsigned logclasses)
{
+ updateReferences();
load(logcache, since, until, logclasses); // make sure all messages are present
uint64_t sincekey = makeKey(since, 0);
logfile_entries_t::iterator it = _entries.lower_bound(sincekey);
@@ -217,6 +224,7 @@ bool Logfile::answerQuery(Query *query, LogCache *logcache, time_t
since, time_t
bool Logfile::answerQueryReverse(Query *query, LogCache *logcache, time_t since, time_t
until, unsigned logclasses)
{
+ updateReferences();
load(logcache, since, until, logclasses); // make sure all messages are present
uint64_t untilkey = makeKey(until, 999999999);
logfile_entries_t::iterator it = _entries.upper_bound(untilkey);
@@ -237,3 +245,19 @@ uint64_t Logfile::makeKey(time_t t, unsigned lineno)
return (uint64_t)((uint64_t)t << 32) | (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 (logfile_entries_t::iterator it = _entries.begin(); it != _entries.end();
++it)
+ num += it->second->updateReferences();
+ logger(LOG_NOTICE, "Updated %u log cache references of %s to new
world.", num, _path);
+ _world = g_live_world;
+ }
+#endif
+}
+
diff --git a/livestatus/src/Logfile.h b/livestatus/src/Logfile.h
index acc799c..931b03a 100644
--- a/livestatus/src/Logfile.h
+++ b/livestatus/src/Logfile.h
@@ -37,11 +37,25 @@ using namespace std;
class LogEntry;
class Query;
class LogCache;
+class World;
typedef map<uint64_t, LogEntry *> logfile_entries_t; // key is time_t . lineno
class Logfile
{
+private:
+ char *_path;
+ time_t _since; // time of first entry
+ bool _watch; // true only for current logfile
+ ino_t _inode; // needed to detect switching
+ fpos_t _read_pos; // read until this position
+ uint32_t _lineno; // read until this line
+
+ logfile_entries_t _entries;
+ char _linebuffer[MAX_LOGLINE];
+ World *_world; // CMC: world our references point into
+
+
public:
Logfile(const char *path, bool watch);
~Logfile();
@@ -57,18 +71,9 @@ public:
bool answerQueryReverse(Query *query, LogCache *lc, time_t since, time_t until,
unsigned);
long freeMessages(unsigned logclasses);
+ void updateReferences();
unsigned _logclasses_read; // only these types have been read
-private:
- char *_path;
- time_t _since; // time of first entry
- bool _watch; // true only for current logfile
- ino_t _inode; // needed to detect switching
- fpos_t _read_pos; // read until this position
- uint32_t _lineno; // read until this line
-
- logfile_entries_t _entries;
- char _linebuffer[MAX_LOGLINE];
private: