From e3b6a04280aebb72f97e7e7df2e2c25260d4492e Mon Sep 17 00:00:00 2001 From: Sven Panne Date: Wed, 20 Apr 2016 14:43:14 +0200 Subject: [PATCH] Fetched livestatus from downstream. --- livestatus/src/LogCache.cc | 18 ++++++++++-------- livestatus/src/LogCache.h | 9 ++++++++- livestatus/src/MetricsColumn.h | 15 ++++++++++++++- livestatus/src/TableHosts.h | 4 ++-- livestatus/src/TableHostsByGroup.h | 2 +- livestatus/src/TableLog.cc | 19 ++++++++++++++----- livestatus/src/TableLog.h | 5 ++++- livestatus/src/TableServices.cc | 2 +- livestatus/src/TableServices.h | 4 ++-- livestatus/src/TableServicesByGroup.h | 2 +- livestatus/src/TableServicesByHostGroup.h | 2 +- livestatus/src/TableStateHistory.cc | 19 ++++++++++++++----- livestatus/src/TableStateHistory.h | 5 ++++- livestatus/src/TableStatus.h | 7 +++++++ 14 files changed, 83 insertions(+), 30 deletions(-) diff --git a/livestatus/src/LogCache.cc b/livestatus/src/LogCache.cc index 61d95aefa..4f00e80a4 100644 --- a/livestatus/src/LogCache.cc +++ b/livestatus/src/LogCache.cc @@ -39,7 +39,6 @@ #include #include "Core.h" using std::chrono::system_clock; -extern Core *g_core; #else extern time_t last_log_rotation; #endif // CMC @@ -91,18 +90,21 @@ void LogCache::setMaxCachedMessages(unsigned long m) { LogCache::~LogCache() { forgetLogfiles(); } -bool LogCache::logCachePreChecks() { - // Do we have any logfiles (should always be the case, - // but we don't want to crash... +bool LogCache::logCachePreChecks( +#ifdef CMC + Core *core +#endif + ) { + // Do we have any logfiles (should always be the case, but we don't want to + // crash... if (_logfiles.empty()) { logger(LOG_INFO, "Warning: no logfile found, not even %s", log_file); return false; } -// Has Nagios rotated logfiles? => Update -// our file index. And delete all memorized -// log messages. +// Has Nagios rotated logfiles? => Update our file index. And delete all +// memorized log messages. #ifdef CMC - if (g_core->_last_logfile_rotation > + if (core->_last_logfile_rotation > system_clock::from_time_t(_last_index_update)) { #else if (last_log_rotation > _last_index_update) { diff --git a/livestatus/src/LogCache.h b/livestatus/src/LogCache.h index 6493019ad..739cea9b5 100644 --- a/livestatus/src/LogCache.h +++ b/livestatus/src/LogCache.h @@ -32,6 +32,9 @@ #include "nagios.h" // IWYU pragma: keep class Column; class CommandsHolder; +#ifdef CMC +struct Core; +#endif class Logfile; typedef std::map _logfiles_t; @@ -62,7 +65,11 @@ class LogCache { void forgetLogfiles(); void updateLogfileIndex(); - bool logCachePreChecks(); + bool logCachePreChecks( +#ifdef CMC + Core *core +#endif + ); private: void scanLogfile(char *path, bool watch); diff --git a/livestatus/src/MetricsColumn.h b/livestatus/src/MetricsColumn.h index ccdf59405..64e5b5164 100644 --- a/livestatus/src/MetricsColumn.h +++ b/livestatus/src/MetricsColumn.h @@ -28,13 +28,26 @@ #include "config.h" // IWYU pragma: keep #include #include "Column.h" +#ifdef CMC +struct Core; +#endif class Query; class MetricsColumn : public Column { +#ifdef CMC + Core *_core; +#endif public: +#ifdef CMC MetricsColumn(std::string name, std::string description, - int indirect_offset, int extra_offset = -1) + int indirect_offset, int extra_offset, Core *core) + : Column(name, description, indirect_offset, extra_offset) + , _core(core) {} +#else + MetricsColumn(std::string name, std::string description, + int indirect_offset, int extra_offset) : Column(name, description, indirect_offset, extra_offset) {} +#endif int type() override { return COLTYPE_LIST; } void output(void *, Query *) override; // Filter *createFilter(int opid, char *value); diff --git a/livestatus/src/TableHosts.h b/livestatus/src/TableHosts.h index bf7b6329f..f50fcaff7 100644 --- a/livestatus/src/TableHosts.h +++ b/livestatus/src/TableHosts.h @@ -42,12 +42,12 @@ class TableHosts : public Table { #ifdef CMC TableHosts(const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); static void addColumns(Table *, std::string prefix, int indirect_offset, int extra_offset, const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); #else TableHosts(const DowntimesOrComments &downtimes_holder, const DowntimesOrComments &comments_holder); diff --git a/livestatus/src/TableHostsByGroup.h b/livestatus/src/TableHostsByGroup.h index 425719f5c..a0db6e3d6 100644 --- a/livestatus/src/TableHostsByGroup.h +++ b/livestatus/src/TableHostsByGroup.h @@ -41,7 +41,7 @@ class TableHostsByGroup : public Table { #ifdef CMC TableHostsByGroup(const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); #else TableHostsByGroup(const DowntimesOrComments &_downtimes_holder, const DowntimesOrComments &_comments_holder); diff --git a/livestatus/src/TableLog.cc b/livestatus/src/TableLog.cc index 4395d0734..5aea45a6f 100644 --- a/livestatus/src/TableLog.cc +++ b/livestatus/src/TableLog.cc @@ -55,13 +55,18 @@ TableLog::TableLog(LogCache *log_cache, #ifdef CMC const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock + std::recursive_mutex &holder_lock, Core *core #else const DowntimesOrComments &downtimes_holder, const DowntimesOrComments &comments_holder #endif ) - : _log_cache(log_cache) { + : +#ifdef CMC + _core(core) + , +#endif + _log_cache(log_cache) { LogEntry *ref = nullptr; addColumn(new OffsetTimeColumn("time", "Time of the log event (UNIX timestamp)", @@ -139,7 +144,7 @@ TableLog::TableLog(LogCache *log_cache, -1, downtimes_holder, comments_holder #ifdef CMC , - holder_lock + holder_lock, core #endif ); TableServices::addColumns( @@ -148,7 +153,7 @@ TableLog::TableLog(LogCache *log_cache, false /* no hosts table */, downtimes_holder, comments_holder #ifdef CMC , - holder_lock + holder_lock, core #endif ); TableContacts::addColumns(this, "current_contact_", @@ -161,7 +166,11 @@ TableLog::TableLog(LogCache *log_cache, void TableLog::answerQuery(Query *query) { lock_guard lg(_log_cache->_lock); - _log_cache->logCachePreChecks(); + _log_cache->logCachePreChecks( +#ifdef CMC + _core +#endif + ); int since = 0; int until = time(nullptr) + 1; diff --git a/livestatus/src/TableLog.h b/livestatus/src/TableLog.h index 01a7732da..53c494d90 100644 --- a/livestatus/src/TableLog.h +++ b/livestatus/src/TableLog.h @@ -45,7 +45,7 @@ class TableLog : public Table { #ifdef CMC TableLog(LogCache *log_cache, const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); #else TableLog(LogCache *log_cache, const DowntimesOrComments &downtimes_holder, const DowntimesOrComments &comments_holder); @@ -57,6 +57,9 @@ class TableLog : public Table { Column *column(const char *colname) override; private: +#ifdef CMC + Core *_core; +#endif LogCache *_log_cache; bool answerQuery(Query *, Logfile *, time_t, time_t); }; diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc index d39d8e5d9..44ad24c9f 100644 --- a/livestatus/src/TableServices.cc +++ b/livestatus/src/TableServices.cc @@ -470,7 +470,7 @@ void TableServices::addColumns(Table *table, string prefix, int indirect_offset, table->addColumn(new MetricsColumn( prefix + "metrics", "A dummy column in order to be compatible with Check_MK Multisite", - indirect_offset)); + indirect_offset, -1)); table->addColumn(new FixedIntColumn( prefix + "cached_at", "A dummy column in order to be compatible with Check_MK Multisite", 0)); diff --git a/livestatus/src/TableServices.h b/livestatus/src/TableServices.h index 59c466e00..046e388c7 100644 --- a/livestatus/src/TableServices.h +++ b/livestatus/src/TableServices.h @@ -42,12 +42,12 @@ class TableServices : public Table { #ifdef CMC TableServices(const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); static void addColumns(Table *, std::string prefix, int indirect_offset, bool add_hosts, const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); #else TableServices(const DowntimesOrComments &downtimes_holder, const DowntimesOrComments &comments_holder); diff --git a/livestatus/src/TableServicesByGroup.h b/livestatus/src/TableServicesByGroup.h index 0d7f1b57a..aa65f7a10 100644 --- a/livestatus/src/TableServicesByGroup.h +++ b/livestatus/src/TableServicesByGroup.h @@ -41,7 +41,7 @@ class TableServicesByGroup : public Table { #ifdef CMC TableServicesByGroup(const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); #else TableServicesByGroup(const DowntimesOrComments &downtimes_holder, const DowntimesOrComments &comments_holder); diff --git a/livestatus/src/TableServicesByHostGroup.h b/livestatus/src/TableServicesByHostGroup.h index d55da3fa4..d59c87a1f 100644 --- a/livestatus/src/TableServicesByHostGroup.h +++ b/livestatus/src/TableServicesByHostGroup.h @@ -41,7 +41,7 @@ class TableServicesByHostGroup : public Table { #ifdef CMC TableServicesByHostGroup(const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); #else TableServicesByHostGroup(const DowntimesOrComments &downtimes_holder, const DowntimesOrComments &comments_holder); diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc index 9f21ee976..f738c9627 100644 --- a/livestatus/src/TableStateHistory.cc +++ b/livestatus/src/TableStateHistory.cc @@ -84,14 +84,19 @@ TableStateHistory::TableStateHistory(LogCache *log_cache, #ifdef CMC const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - recursive_mutex &holder_lock + recursive_mutex &holder_lock, Core *core #else const DowntimesOrComments &downtimes_holder, const DowntimesOrComments &comments_holder #endif ) - : _log_cache(log_cache) { + : +#ifdef CMC + _core(core) + , +#endif + _log_cache(log_cache) { HostServiceState *ref = nullptr; addColumn(new OffsetTimeColumn( "time", "Time of the log event (seconds since 1/1/1970)", @@ -257,7 +262,7 @@ TableStateHistory::TableStateHistory(LogCache *log_cache, -1, downtimes_holder, comments_holder #ifdef CMC , - holder_lock + holder_lock, core #endif ); TableServices::addColumns( @@ -266,7 +271,7 @@ TableStateHistory::TableStateHistory(LogCache *log_cache, false /* no hosts table */, downtimes_holder, comments_holder #ifdef CMC , - holder_lock + holder_lock, core #endif ); } @@ -330,7 +335,11 @@ void TableStateHistory::answerQuery(Query *query) { } lock_guard lg(_log_cache->_lock); - _log_cache->logCachePreChecks(); + _log_cache->logCachePreChecks( +#ifdef CMC + _core +#endif + ); // This flag might be set to true by the return value of processDataset(...) _abort_query = false; diff --git a/livestatus/src/TableStateHistory.h b/livestatus/src/TableStateHistory.h index b92f85a07..9f0068b70 100644 --- a/livestatus/src/TableStateHistory.h +++ b/livestatus/src/TableStateHistory.h @@ -46,6 +46,9 @@ struct LogEntry; #define CLASSMASK_STATEHIST 0xC6 class TableStateHistory : public Table { +#ifdef CMC + Core *_core; +#endif LogCache *_log_cache; int _query_timeframe; @@ -70,7 +73,7 @@ class TableStateHistory : public Table { TableStateHistory(LogCache *log_cache, const Core::_notes_t &downtimes_holder, const Core::_notes_t &comments_holder, - std::recursive_mutex &holder_lock); + std::recursive_mutex &holder_lock, Core *core); #else TableStateHistory(LogCache *log_cache, const DowntimesOrComments &downtimes_holder, diff --git a/livestatus/src/TableStatus.h b/livestatus/src/TableStatus.h index a36f5c718..6e4ab97c5 100644 --- a/livestatus/src/TableStatus.h +++ b/livestatus/src/TableStatus.h @@ -27,11 +27,18 @@ #include "config.h" // IWYU pragma: keep #include "Table.h" +#ifdef CMC +struct Core; +#endif class Query; class TableStatus : public Table { public: +#ifdef CMC + explicit TableStatus(Core *core); +#else TableStatus(); +#endif const char *name() override { return "status"; } void answerQuery(Query *query) override; };