]> granicus.if.org Git - icinga2/commitdiff
Livestatus: Call addRowFn directly in UpdateLogEntries().
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 18 Dec 2013 16:19:16 +0000 (17:19 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 18 Dec 2013 16:32:18 +0000 (17:32 +0100)
Refs #5351
Refs #5369

components/livestatus/historytable.cpp
components/livestatus/historytable.h
components/livestatus/logtable.cpp
components/livestatus/logtable.h
components/livestatus/logutility.cpp
components/livestatus/logutility.h
components/livestatus/statehisttable.cpp
components/livestatus/statehisttable.h
components/livestatus/table.h

index fc90076b05f44c48a1e56306df0660b58007ee27..8f4ffc90b12f8bd38e966b5d808af0c89ad640e7 100644 (file)
@@ -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 */
 }
index 11e7b285c4b66ad352475deddba57f165a12057c..58f07c838faf38455426e4616f33e3696276a697 100644 (file)
@@ -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);
 };
 
 }
index 27b2086e1d65a4b8b676cf6127c27db0a4754185..43bb706745001916cf481906668700d4b2244f8d 100644 (file)
@@ -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)
index 4a9b4d60be30b9ef3f359b54a547dae7dd6fccba..b71e1239643f734aa5ea3a04270bf3372b989496 100644 (file)
@@ -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);
index 1ac1bb8061ae7a9bd6aa9b546c99c069bfd2e037..7ace7f79b1a84f10139ec82b78b759a9ae59ea91 100644 (file)
@@ -74,7 +74,7 @@ void LogUtility::CreateLogIndexFileHandler(const String& path, std::map<time_t,
 }
 
 void LogUtility::CreateLogCache(std::map<time_t, String> 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<time_t, String> 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<time_t, String> index, HistoryTable *ta
        }
 }
 
-
-
 Dictionary::Ptr LogUtility::GetAttributes(const String& text)
 {
         Dictionary::Ptr bag = make_shared<Dictionary>();
@@ -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);
index 09e68300cf216c79ee721bb03fd2ad7fb7131f43..9e92afc6431f0804550bc4292b5522e4dfbd116f 100644 (file)
@@ -66,7 +66,7 @@ class LogUtility
 public:
        static void CreateLogIndex(const String& path, std::map<time_t, String>& index);
        static void CreateLogIndexFileHandler(const String& path, std::map<time_t, String>& index);
-       static void CreateLogCache(std::map<time_t, String> index, HistoryTable *table, time_t from, time_t until);
+       static void CreateLogCache(std::map<time_t, String> index, HistoryTable *table, time_t from, time_t until, const AddRowFunction& addRowFn);
        static Dictionary::Ptr GetAttributes(const String& text);
 
 private:
index 371d8f458876c593525e4f9b4899c9b873fa7179..0eca997cbb9784936dab4fd1df9444d290d1871a 100644 (file)
@@ -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;
 
index 88c2170b8420f5b1d600f80c77d9dfe5f3c8dd3e..388de2bcb71604f0424afc9f38ea2d78f06a4356 100644 (file)
@@ -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);
index dd5a5abdb101c562ccc6d7079703c9efe2221623..01bb96de111bbbbdca9d88875fc1f57624240a4a 100644 (file)
@@ -28,6 +28,8 @@
 namespace icinga
 {
 
+typedef boost::function<void (const Value&)> AddRowFunction;
+
 class Filter;
 
 /**
@@ -38,8 +40,6 @@ class Table : public Object
 public:
        DECLARE_PTR_TYPEDEFS(Table);
 
-       typedef boost::function<void (const Value&)> 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;