From: Michael Friedrich Date: Wed, 18 Dec 2013 16:19:16 +0000 (+0100) Subject: Livestatus: Call addRowFn directly in UpdateLogEntries(). X-Git-Tag: v0.0.6~1^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be78579deab172482764ae3940f5862a8cce284c;p=icinga2 Livestatus: Call addRowFn directly in UpdateLogEntries(). Refs #5351 Refs #5369 --- diff --git a/components/livestatus/historytable.cpp b/components/livestatus/historytable.cpp index fc90076b0..8f4ffc90b 100644 --- a/components/livestatus/historytable.cpp +++ b/components/livestatus/historytable.cpp @@ -21,7 +21,7 @@ using namespace icinga; -void HistoryTable::UpdateLogEntries(const Dictionary::Ptr&, int, int) +void HistoryTable::UpdateLogEntries(const Dictionary::Ptr&, int, int, const AddRowFunction&) { /* does nothing by default */ } diff --git a/components/livestatus/historytable.h b/components/livestatus/historytable.h index 11e7b285c..58f07c838 100644 --- a/components/livestatus/historytable.h +++ b/components/livestatus/historytable.h @@ -33,7 +33,7 @@ namespace icinga class HistoryTable : public Table { public: - virtual void UpdateLogEntries(const Dictionary::Ptr& bag, int line_count, int lineno); + virtual void UpdateLogEntries(const Dictionary::Ptr& bag, int line_count, int lineno, const AddRowFunction& addRowFn); }; } diff --git a/components/livestatus/logtable.cpp b/components/livestatus/logtable.cpp index 27b2086e1..43bb70674 100644 --- a/components/livestatus/logtable.cpp +++ b/components/livestatus/logtable.cpp @@ -57,13 +57,7 @@ LogTable::LogTable(const String& compat_log_path, time_t from, time_t until) AddColumns(this); } -void LogTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno) -{ - /* additional attributes only for log table */ - log_entry_attrs->Set("lineno", lineno); - m_RowsCache[line_count] = log_entry_attrs; -} void LogTable::AddColumns(Table *table, const String& prefix, const Column::ObjectAccessor& objectAccessor) @@ -103,14 +97,16 @@ void LogTable::FetchRows(const AddRowFunction& addRowFn) LogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex); /* generate log cache */ - LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil); + LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn); +} - unsigned long line_count; +/* gets called in LogUtility::CreateLogCache */ +void LogTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn) +{ + /* additional attributes only for log table */ + log_entry_attrs->Set("lineno", lineno); - BOOST_FOREACH(boost::tie(line_count, boost::tuples::ignore), m_RowsCache) { - /* pass a dictionary with "line_count" as key */ - addRowFn(m_RowsCache[line_count]); - } + addRowFn(log_entry_attrs); } Object::Ptr LogTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor) diff --git a/components/livestatus/logtable.h b/components/livestatus/logtable.h index 4a9b4d60b..b71e12396 100644 --- a/components/livestatus/logtable.h +++ b/components/livestatus/logtable.h @@ -43,7 +43,7 @@ public: virtual String GetName(void) const; - void UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno); + void UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn); protected: virtual void FetchRows(const AddRowFunction& addRowFn); diff --git a/components/livestatus/logutility.cpp b/components/livestatus/logutility.cpp index 1ac1bb806..7ace7f79b 100644 --- a/components/livestatus/logutility.cpp +++ b/components/livestatus/logutility.cpp @@ -74,7 +74,7 @@ void LogUtility::CreateLogIndexFileHandler(const String& path, std::map index, HistoryTable *table, - time_t from, time_t until) + time_t from, time_t until, const AddRowFunction& addRowFn) { ASSERT(table); @@ -108,7 +108,7 @@ void LogUtility::CreateLogCache(std::map index, HistoryTable *ta continue; } - table->UpdateLogEntries(log_entry_attrs, line_count, lineno); + table->UpdateLogEntries(log_entry_attrs, line_count, lineno, addRowFn); line_count++; lineno++; @@ -118,8 +118,6 @@ void LogUtility::CreateLogCache(std::map index, HistoryTable *ta } } - - Dictionary::Ptr LogUtility::GetAttributes(const String& text) { Dictionary::Ptr bag = make_shared(); @@ -261,9 +259,9 @@ Dictionary::Ptr LogUtility::GetAttributes(const String& text) bag->Set("contact_name", tokens[0]); bag->Set("host_name", tokens[1]); - bag->Set("state_type", tokens[2]); + bag->Set("state_type", tokens[2].CStr()); bag->Set("state", Service::StateFromString(tokens[3])); - bag->Set("command_name", atoi(tokens[4].CStr())); + bag->Set("command_name", tokens[4]); bag->Set("plugin_output", tokens[5]); bag->Set("log_class", LogEntryClassNotification); @@ -277,9 +275,9 @@ Dictionary::Ptr LogUtility::GetAttributes(const String& text) bag->Set("contact_name", tokens[0]); bag->Set("host_name", tokens[1]); bag->Set("service_description", tokens[2]); - bag->Set("state_type", tokens[3]); + bag->Set("state_type", tokens[3].CStr()); bag->Set("state", Service::StateFromString(tokens[4])); - bag->Set("command_name", atoi(tokens[5].CStr())); + bag->Set("command_name", tokens[5]); bag->Set("plugin_output", tokens[6]); bag->Set("log_class", LogEntryClassNotification); diff --git a/components/livestatus/logutility.h b/components/livestatus/logutility.h index 09e68300c..9e92afc64 100644 --- a/components/livestatus/logutility.h +++ b/components/livestatus/logutility.h @@ -66,7 +66,7 @@ class LogUtility public: static void CreateLogIndex(const String& path, std::map& index); static void CreateLogIndexFileHandler(const String& path, std::map& index); - static void CreateLogCache(std::map index, HistoryTable *table, time_t from, time_t until); + static void CreateLogCache(std::map index, HistoryTable *table, time_t from, time_t until, const AddRowFunction& addRowFn); static Dictionary::Ptr GetAttributes(const String& text); private: diff --git a/components/livestatus/statehisttable.cpp b/components/livestatus/statehisttable.cpp index 371d8f458..0eca997cb 100644 --- a/components/livestatus/statehisttable.cpp +++ b/components/livestatus/statehisttable.cpp @@ -58,7 +58,7 @@ StateHistTable::StateHistTable(const String& compat_log_path, time_t from, time_ AddColumns(this); } -void StateHistTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno) +void StateHistTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn) { unsigned int time = log_entry_attrs->Get("time"); String host_name = log_entry_attrs->Get("host_name"); @@ -203,6 +203,8 @@ void StateHistTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, in } m_ServicesCache[state_hist_service] = state_hist_service_states; + + /* TODO find a way to directly call addRowFn() - right now m_ServicesCache depends on historical lines ("already seen service") */ } void StateHistTable::AddColumns(Table *table, const String& prefix, @@ -253,7 +255,7 @@ void StateHistTable::FetchRows(const AddRowFunction& addRowFn) LogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex); /* generate log cache */ - LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil); + LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn); Service::Ptr state_hist_service; diff --git a/components/livestatus/statehisttable.h b/components/livestatus/statehisttable.h index 88c2170b8..388de2bcb 100644 --- a/components/livestatus/statehisttable.h +++ b/components/livestatus/statehisttable.h @@ -44,7 +44,7 @@ public: virtual String GetName(void) const; - void UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno); + void UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn); protected: virtual void FetchRows(const AddRowFunction& addRowFn); diff --git a/components/livestatus/table.h b/components/livestatus/table.h index dd5a5abdb..01bb96de1 100644 --- a/components/livestatus/table.h +++ b/components/livestatus/table.h @@ -28,6 +28,8 @@ namespace icinga { +typedef boost::function AddRowFunction; + class Filter; /** @@ -38,8 +40,6 @@ class Table : public Object public: DECLARE_PTR_TYPEDEFS(Table); - typedef boost::function AddRowFunction; - static Table::Ptr GetByName(const String& name, const String& compat_log_path = "", const unsigned long& from = 0, const unsigned long& until = 0); virtual String GetName(void) const = 0;