Skip to content

Commit

Permalink
Fetched livestatus from downstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Panne committed Apr 20, 2016
1 parent 100bee7 commit e3b6a04
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 30 deletions.
18 changes: 10 additions & 8 deletions livestatus/src/LogCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <chrono>
#include "Core.h"
using std::chrono::system_clock;
extern Core *g_core;
#else
extern time_t last_log_rotation;
#endif // CMC
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion livestatus/src/LogCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "nagios.h" // IWYU pragma: keep
class Column;
class CommandsHolder;
#ifdef CMC
struct Core;
#endif
class Logfile;

typedef std::map<time_t, Logfile *> _logfiles_t;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion livestatus/src/MetricsColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@
#include "config.h" // IWYU pragma: keep
#include <string>
#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);
Expand Down
4 changes: 2 additions & 2 deletions livestatus/src/TableHosts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion livestatus/src/TableHostsByGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 14 additions & 5 deletions livestatus/src/TableLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -139,7 +144,7 @@ TableLog::TableLog(LogCache *log_cache,
-1, downtimes_holder, comments_holder
#ifdef CMC
,
holder_lock
holder_lock, core
#endif
);
TableServices::addColumns(
Expand All @@ -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_",
Expand All @@ -161,7 +166,11 @@ TableLog::TableLog(LogCache *log_cache,

void TableLog::answerQuery(Query *query) {
lock_guard<mutex> lg(_log_cache->_lock);
_log_cache->logCachePreChecks();
_log_cache->logCachePreChecks(
#ifdef CMC
_core
#endif
);

int since = 0;
int until = time(nullptr) + 1;
Expand Down
5 changes: 4 additions & 1 deletion livestatus/src/TableLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion livestatus/src/TableServices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions livestatus/src/TableServices.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion livestatus/src/TableServicesByGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion livestatus/src/TableServicesByHostGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 14 additions & 5 deletions livestatus/src/TableStateHistory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -257,7 +262,7 @@ TableStateHistory::TableStateHistory(LogCache *log_cache,
-1, downtimes_holder, comments_holder
#ifdef CMC
,
holder_lock
holder_lock, core
#endif
);
TableServices::addColumns(
Expand All @@ -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
);
}
Expand Down Expand Up @@ -330,7 +335,11 @@ void TableStateHistory::answerQuery(Query *query) {
}

lock_guard<mutex> 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;
Expand Down
5 changes: 4 additions & 1 deletion livestatus/src/TableStateHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions livestatus/src/TableStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit e3b6a04

Please sign in to comment.