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 */
}
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);
};
}
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)
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)
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);
}
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);
continue;
}
- table->UpdateLogEntries(log_entry_attrs, line_count, lineno);
+ table->UpdateLogEntries(log_entry_attrs, line_count, lineno, addRowFn);
line_count++;
lineno++;
}
}
-
-
Dictionary::Ptr LogUtility::GetAttributes(const String& text)
{
Dictionary::Ptr bag = make_shared<Dictionary>();
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);
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);
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:
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");
}
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,
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;
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);
namespace icinga
{
+typedef boost::function<void (const Value&)> AddRowFunction;
+
class Filter;
/**
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;