Livestatus: Call addRowFn directly in UpdateLogEntries().

Refs #5351
Refs #5369
This commit is contained in:
Michael Friedrich 2013-12-18 17:19:16 +01:00
parent 333ba6ee7e
commit be78579dea
9 changed files with 25 additions and 29 deletions

View 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 */
}

View 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);
};
}

View 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)

View 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);

View 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);

View 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:

View 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;

View 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);

View 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;