From 4c8d7eea14a5f32369b997c9ccf4aee826d9f103 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 28 May 2014 14:25:12 +0200 Subject: [PATCH] Rename livestatus classes. Refs #6346 --- components/livestatus/CMakeLists.txt | 7 +-- .../{listener.cpp => livestatuslistener.cpp} | 4 +- .../{listener.hpp => livestatuslistener.hpp} | 4 +- .../{listener.ti => livestatuslistener.ti} | 0 ...ogutility.cpp => livestatuslogutility.cpp} | 22 ++++----- ...ogutility.hpp => livestatuslogutility.hpp} | 10 ++-- .../{query.cpp => livestatusquery.cpp} | 46 +++++++++---------- .../{query.hpp => livestatusquery.hpp} | 12 ++--- components/livestatus/logtable.cpp | 10 ++-- components/livestatus/statehisttable.cpp | 12 ++--- components/livestatus/statustable.cpp | 6 +-- 11 files changed, 67 insertions(+), 66 deletions(-) rename components/livestatus/{listener.cpp => livestatuslistener.cpp} (97%) rename components/livestatus/{listener.hpp => livestatuslistener.hpp} (96%) rename components/livestatus/{listener.ti => livestatuslistener.ti} (100%) rename components/livestatus/{logutility.cpp => livestatuslogutility.cpp} (90%) rename components/livestatus/{logutility.hpp => livestatuslogutility.hpp} (94%) rename components/livestatus/{query.cpp => livestatusquery.cpp} (88%) rename components/livestatus/{query.hpp => livestatusquery.hpp} (92%) diff --git a/components/livestatus/CMakeLists.txt b/components/livestatus/CMakeLists.txt index f706a4356..42d268271 100644 --- a/components/livestatus/CMakeLists.txt +++ b/components/livestatus/CMakeLists.txt @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(listener.ti listener.thpp) +mkclass_target(livestatuslistener.ti livestatuslistener.thpp) mkembedconfig_target(livestatus-type.conf livestatus-type.cpp) @@ -24,8 +24,9 @@ add_library(livestatus SHARED aggregator.cpp andfilter.cpp attributefilter.cpp commentstable.cpp contactgroupstable.cpp contactstable.cpp countaggregator.cpp downtimestable.cpp endpointstable.cpp filter.cpp historytable.cpp hostgroupstable.cpp hoststable.cpp invavgaggregator.cpp invsumaggregator.cpp - listener.cpp listener.thpp logutility.cpp logtable.cpp maxaggregator.cpp - minaggregator.cpp negatefilter.cpp orfilter.cpp query.cpp + livestatuslistener.cpp livestatuslistener.thpp livestatusquery.cpp + livestatuslogutility.cpp logtable.cpp maxaggregator.cpp + minaggregator.cpp negatefilter.cpp orfilter.cpp servicegroupstable.cpp servicestable.cpp statehisttable.cpp statustable.cpp stdaggregator.cpp sumaggregator.cpp table.cpp timeperiodstable.cpp livestatus-type.cpp) diff --git a/components/livestatus/listener.cpp b/components/livestatus/livestatuslistener.cpp similarity index 97% rename from components/livestatus/listener.cpp rename to components/livestatus/livestatuslistener.cpp index 776462597..f230fb349 100644 --- a/components/livestatus/listener.cpp +++ b/components/livestatus/livestatuslistener.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "livestatus/listener.hpp" +#include "livestatus/livestatuslistener.hpp" #include "config/configcompilercontext.hpp" #include "base/utility.hpp" #include "base/objectlock.hpp" @@ -155,7 +155,7 @@ void LivestatusListener::ClientHandler(const Socket::Ptr& client) if (lines.empty()) break; - Query::Ptr query = make_shared(lines, GetCompatLogPath()); + LivestatusQuery::Ptr query = make_shared(lines, GetCompatLogPath()); if (!query->Execute(stream)) break; } diff --git a/components/livestatus/listener.hpp b/components/livestatus/livestatuslistener.hpp similarity index 96% rename from components/livestatus/listener.hpp rename to components/livestatus/livestatuslistener.hpp index 6a4080ef3..63341dfbb 100644 --- a/components/livestatus/listener.hpp +++ b/components/livestatus/livestatuslistener.hpp @@ -20,8 +20,8 @@ #ifndef LIVESTATUSLISTENER_H #define LIVESTATUSLISTENER_H -#include "livestatus/listener.thpp" -#include "livestatus/query.hpp" +#include "livestatus/livestatuslistener.thpp" +#include "livestatus/livestatusquery.hpp" #include "base/socket.hpp" #include diff --git a/components/livestatus/listener.ti b/components/livestatus/livestatuslistener.ti similarity index 100% rename from components/livestatus/listener.ti rename to components/livestatus/livestatuslistener.ti diff --git a/components/livestatus/logutility.cpp b/components/livestatus/livestatuslogutility.cpp similarity index 90% rename from components/livestatus/logutility.cpp rename to components/livestatus/livestatuslogutility.cpp index 032d5b93f..1fcec9f99 100644 --- a/components/livestatus/logutility.cpp +++ b/components/livestatus/livestatuslogutility.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "livestatus/logutility.hpp" +#include "livestatus/livestatuslogutility.hpp" #include "icinga/service.hpp" #include "icinga/host.hpp" #include "icinga/user.hpp" @@ -38,13 +38,13 @@ using namespace icinga; -void LogUtility::CreateLogIndex(const String& path, std::map& index) +void LivestatusLogUtility::CreateLogIndex(const String& path, std::map& index) { - Utility::Glob(path + "/icinga.log", boost::bind(&LogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile); - Utility::Glob(path + "/archives/*.log", boost::bind(&LogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile); + Utility::Glob(path + "/icinga.log", boost::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile); + Utility::Glob(path + "/archives/*.log", boost::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile); } -void LogUtility::CreateLogIndexFileHandler(const String& path, std::map& index) +void LivestatusLogUtility::CreateLogIndexFileHandler(const String& path, std::map& index) { std::ifstream stream; stream.open(path.CStr(), std::ifstream::in); @@ -68,12 +68,12 @@ void LogUtility::CreateLogIndexFileHandler(const String& path, std::map index, HistoryTable *table, +void LivestatusLogUtility::CreateLogCache(std::map index, HistoryTable *table, time_t from, time_t until, const AddRowFunction& addRowFn) { ASSERT(table); @@ -100,11 +100,11 @@ void LogUtility::CreateLogCache(std::map index, HistoryTable *ta if (line.empty()) continue; /* Ignore empty lines */ - Dictionary::Ptr log_entry_attrs = LogUtility::GetAttributes(line); + Dictionary::Ptr log_entry_attrs = LivestatusLogUtility::GetAttributes(line); /* no attributes available - invalid log line */ if (!log_entry_attrs) { - Log(LogDebug, "LivestatusListener/LogUtility", "Skipping invalid log line: '" + line + "'."); + Log(LogDebug, "LivestatusLogUtility", "Skipping invalid log line: '" + line + "'."); continue; } @@ -118,7 +118,7 @@ void LogUtility::CreateLogCache(std::map index, HistoryTable *ta } } -Dictionary::Ptr LogUtility::GetAttributes(const String& text) +Dictionary::Ptr LivestatusLogUtility::GetAttributes(const String& text) { Dictionary::Ptr bag = make_shared(); @@ -127,7 +127,7 @@ Dictionary::Ptr LogUtility::GetAttributes(const String& text) */ unsigned long time = atoi(text.SubStr(1, 11).CStr()); - Log(LogDebug, "LivestatusListener/LogUtility", "Processing log line: '" + text + "'."); + Log(LogDebug, "LivestatusLogUtility", "Processing log line: '" + text + "'."); bag->Set("time", time); size_t colon = text.FindFirstOf(':'); diff --git a/components/livestatus/logutility.hpp b/components/livestatus/livestatuslogutility.hpp similarity index 94% rename from components/livestatus/logutility.hpp rename to components/livestatus/livestatuslogutility.hpp index 087073b3a..3f2b33bbb 100644 --- a/components/livestatus/logutility.hpp +++ b/components/livestatus/livestatuslogutility.hpp @@ -17,8 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#ifndef LOGUTILITY_H -#define LOGUTILITY_H +#ifndef LIVESTATUSLOGUTILITY_H +#define LIVESTATUSLOGUTILITY_H #include "livestatus/historytable.hpp" @@ -60,7 +60,7 @@ enum LogEntryClass { /** * @ingroup livestatus */ -class LogUtility +class LivestatusLogUtility { public: @@ -70,9 +70,9 @@ public: static Dictionary::Ptr GetAttributes(const String& text); private: - LogUtility(void); + LivestatusLogUtility(void); }; } -#endif /* LOGUTILITY_H */ +#endif /* LIVESTATUSLOGUTILITY_H */ diff --git a/components/livestatus/query.cpp b/components/livestatus/livestatusquery.cpp similarity index 88% rename from components/livestatus/query.cpp rename to components/livestatus/livestatusquery.cpp index 1584a96fa..00e5c4176 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/livestatusquery.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "livestatus/query.hpp" +#include "livestatus/livestatusquery.hpp" #include "livestatus/countaggregator.hpp" #include "livestatus/sumaggregator.hpp" #include "livestatus/minaggregator.hpp" @@ -47,7 +47,7 @@ using namespace icinga; static int l_ExternalCommands = 0; static boost::mutex l_QueryMutex; -Query::Query(const std::vector& lines, const String& compat_log_path) +LivestatusQuery::LivestatusQuery(const std::vector& lines, const String& compat_log_path) : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_LogTimeFrom(0), m_LogTimeUntil(static_cast(Utility::GetTime())) { @@ -62,7 +62,7 @@ Query::Query(const std::vector& lines, const String& compat_log_path) BOOST_FOREACH(const String& line, lines) { msg += line + "\n"; } - Log(LogDebug, "LivestatusListener/Query", msg); + Log(LogDebug, "LivestatusQuery", msg); m_CompatLogPath = compat_log_path; @@ -202,10 +202,10 @@ Query::Query(const std::vector& lines, const String& compat_log_path) if (header == "Or" || header == "StatsOr") { filter = make_shared(); - Log(LogDebug, "LivestatusListener/Query", "Add OR filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available."); + Log(LogDebug, "LivestatusQuery", "Add OR filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available."); } else { filter = make_shared(); - Log(LogDebug, "LivestatusListener/Query", "Add AND filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available."); + Log(LogDebug, "LivestatusQuery", "Add AND filter for " + params + " column(s). " + Convert::ToString(deq.size()) + " filters available."); } if (num > deq.size()) { @@ -217,7 +217,7 @@ Query::Query(const std::vector& lines, const String& compat_log_path) while (num > 0 && num--) { filter->AddSubFilter(deq.back()); - Log(LogDebug, "LivestatusListener/Query", "Add " + Convert::ToString(num) + " filter."); + Log(LogDebug, "LivestatusQuery", "Add " + Convert::ToString(num) + " filter."); deq.pop_back(); if (&deq == &stats) aggregators.pop_back(); @@ -269,14 +269,14 @@ Query::Query(const std::vector& lines, const String& compat_log_path) m_Aggregators.swap(aggregators); } -int Query::GetExternalCommands(void) +int LivestatusQuery::GetExternalCommands(void) { boost::mutex::scoped_lock lock(l_QueryMutex); return l_ExternalCommands; } -Filter::Ptr Query::ParseFilter(const String& params, unsigned long& from, unsigned long& until) +Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& from, unsigned long& until) { /* * time >= 1382696656 @@ -340,12 +340,12 @@ Filter::Ptr Query::ParseFilter(const String& params, unsigned long& from, unsign } } - Log(LogDebug, "LivestatusListener/Query", "Parsed filter with attr: '" + attr + "' op: '" + op + "' val: '" + val + "'."); + Log(LogDebug, "LivestatusQuery", "Parsed filter with attr: '" + attr + "' op: '" + op + "' val: '" + val + "'."); return filter; } -void Query::PrintResultSet(std::ostream& fp, const Array::Ptr& rs) +void LivestatusQuery::PrintResultSet(std::ostream& fp, const Array::Ptr& rs) { if (m_OutputFormat == "csv") { ObjectLock olock(rs); @@ -373,7 +373,7 @@ void Query::PrintResultSet(std::ostream& fp, const Array::Ptr& rs) } } -void Query::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level) +void LivestatusQuery::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level) { bool first = true; @@ -391,9 +391,9 @@ void Query::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level) } } -void Query::ExecuteGetHelper(const Stream::Ptr& stream) +void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream) { - Log(LogInformation, "LivestatusListener/Query", "Table: " + m_Table); + Log(LogInformation, "LivestatusQuery", "Table: " + m_Table); Table::Ptr table = Table::GetByName(m_Table, m_CompatLogPath, m_LogTimeFrom, m_LogTimeUntil); @@ -490,7 +490,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream) SendResponse(stream, LivestatusErrorOK, result.str()); } -void Query::ExecuteCommandHelper(const Stream::Ptr& stream) +void LivestatusQuery::ExecuteCommandHelper(const Stream::Ptr& stream) { { boost::mutex::scoped_lock lock(l_QueryMutex); @@ -498,18 +498,18 @@ void Query::ExecuteCommandHelper(const Stream::Ptr& stream) l_ExternalCommands++; } - Log(LogInformation, "LivestatusListener/Query", "Executing command: " + m_Command); + Log(LogInformation, "LivestatusQuery", "Executing command: " + m_Command); ExternalCommandProcessor::Execute(m_Command); SendResponse(stream, LivestatusErrorOK, ""); } -void Query::ExecuteErrorHelper(const Stream::Ptr& stream) +void LivestatusQuery::ExecuteErrorHelper(const Stream::Ptr& stream) { - Log(LogDebug, "LivestatusListener/Query", "ERROR: Code: '" + Convert::ToString(m_ErrorCode) + "' Message: '" + m_ErrorMessage + "'."); + Log(LogDebug, "LivestatusQuery", "ERROR: Code: '" + Convert::ToString(m_ErrorCode) + "' Message: '" + m_ErrorMessage + "'."); SendResponse(stream, m_ErrorCode, m_ErrorMessage); } -void Query::SendResponse(const Stream::Ptr& stream, int code, const String& data) +void LivestatusQuery::SendResponse(const Stream::Ptr& stream, int code, const String& data) { if (m_ResponseHeader == "fixed16") PrintFixed16(stream, code, data); @@ -521,12 +521,12 @@ void Query::SendResponse(const Stream::Ptr& stream, int code, const String& data std::ostringstream info; info << "Exception thrown while writing to the livestatus socket: " << std::endl << DiagnosticInformation(ex); - Log(LogCritical, "LivestatusListener/Query", info.str()); + Log(LogCritical, "LivestatusQuery", info.str()); } } } -void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data) +void LivestatusQuery::PrintFixed16(const Stream::Ptr& stream, int code, const String& data) { ASSERT(code >= 100 && code <= 999); @@ -541,14 +541,14 @@ void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data std::ostringstream info; info << "Exception thrown while writing to the livestatus socket: " << std::endl << DiagnosticInformation(ex); - Log(LogCritical, "LivestatusListener/Query", info.str()); + Log(LogCritical, "LivestatusQuery", info.str()); } } -bool Query::Execute(const Stream::Ptr& stream) +bool LivestatusQuery::Execute(const Stream::Ptr& stream) { try { - Log(LogInformation, "LivestatusListener/Query", "Executing livestatus query: " + m_Verb); + Log(LogInformation, "LivestatusQuery", "Executing livestatus query: " + m_Verb); if (m_Verb == "GET") ExecuteGetHelper(stream); diff --git a/components/livestatus/query.hpp b/components/livestatus/livestatusquery.hpp similarity index 92% rename from components/livestatus/query.hpp rename to components/livestatus/livestatusquery.hpp index a0f096e58..98f5c9a15 100644 --- a/components/livestatus/query.hpp +++ b/components/livestatus/livestatusquery.hpp @@ -17,8 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#ifndef QUERY_H -#define QUERY_H +#ifndef LIVESTATUSQUERY_H +#define LIVESTATUSQUERY_H #include "livestatus/filter.hpp" #include "livestatus/aggregator.hpp" @@ -42,12 +42,12 @@ enum LivestatusError /** * @ingroup livestatus */ -class Query : public Object +class LivestatusQuery : public Object { public: - DECLARE_PTR_TYPEDEFS(Query); + DECLARE_PTR_TYPEDEFS(LivestatusQuery); - Query(const std::vector& lines, const String& compat_log_path); + LivestatusQuery(const std::vector& lines, const String& compat_log_path); bool Execute(const Stream::Ptr& stream); @@ -97,4 +97,4 @@ private: } -#endif /* QUERY_H */ +#endif /* LIVESTATUSQUERY_H */ diff --git a/components/livestatus/logtable.cpp b/components/livestatus/logtable.cpp index 11138816b..7d86d8e4a 100644 --- a/components/livestatus/logtable.cpp +++ b/components/livestatus/logtable.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "livestatus/logtable.hpp" -#include "livestatus/logutility.hpp" +#include "livestatus/livestatuslogutility.hpp" #include "livestatus/hoststable.hpp" #include "livestatus/servicestable.hpp" #include "livestatus/contactstable.hpp" @@ -91,16 +91,16 @@ String LogTable::GetName(void) const void LogTable::FetchRows(const AddRowFunction& addRowFn) { - Log(LogNotice, "LivestatusListener/LogTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil)); + Log(LogDebug, "LogTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil)); /* create log file index */ - LogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex); + LivestatusLogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex); /* generate log cache */ - LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn); + LivestatusLogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn); } -/* gets called in LogUtility::CreateLogCache */ +/* gets called in LivestatusLogUtility::CreateLogCache */ void LogTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn) { /* additional attributes only for log table */ diff --git a/components/livestatus/statehisttable.cpp b/components/livestatus/statehisttable.cpp index 350ea93aa..c5b95cf0e 100644 --- a/components/livestatus/statehisttable.cpp +++ b/components/livestatus/statehisttable.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "livestatus/statehisttable.hpp" -#include "livestatus/logutility.hpp" +#include "livestatus/livestatuslogutility.hpp" #include "livestatus/hoststable.hpp" #include "livestatus/servicestable.hpp" #include "livestatus/contactstable.hpp" @@ -117,7 +117,7 @@ void StateHistTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, in state_hist_service_states->Add(state_hist_bag); - Log(LogDebug, "LivestatusListener/StateHistTable", "statehist: Adding new object '" + checkable->GetName() + "' to services cache."); + Log(LogDebug, "StateHistTable", "statehist: Adding new object '" + checkable->GetName() + "' to services cache."); } else { state_hist_service_states = m_CheckablesCache[checkable]; state_hist_bag = state_hist_service_states->Get(state_hist_service_states->GetLength()-1); /* fetch latest state from history */ @@ -173,7 +173,7 @@ void StateHistTable::UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, in state_hist_service_states->Add(state_hist_bag_new); - Log(LogDebug, "LivestatusListener/StateHistTable", "statehist: State change detected for object '" + + Log(LogDebug, "StateHistTable", "statehist: State change detected for object '" + checkable->GetName() + "' in '" + log_line + "'."); } break; @@ -252,13 +252,13 @@ String StateHistTable::GetName(void) const void StateHistTable::FetchRows(const AddRowFunction& addRowFn) { - Log(LogNotice, "LivestatusListener/StateHistTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil)); + Log(LogDebug, "StateHistTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil)); /* create log file index */ - LogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex); + LivestatusLogUtility::CreateLogIndex(m_CompatLogPath, m_LogFileIndex); /* generate log cache */ - LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn); + LivestatusLogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn); Checkable::Ptr checkable; diff --git a/components/livestatus/statustable.cpp b/components/livestatus/statustable.cpp index 306a6684b..eb5d3f600 100644 --- a/components/livestatus/statustable.cpp +++ b/components/livestatus/statustable.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "livestatus/statustable.hpp" -#include "livestatus/listener.hpp" +#include "livestatus/livestatuslistener.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/cib.hpp" #include "icinga/host.hpp" @@ -152,12 +152,12 @@ Value StatusTable::ServiceChecksRateAccessor(const Value&) Value StatusTable::ExternalCommandsAccessor(const Value&) { - return Query::GetExternalCommands(); + return LivestatusQuery::GetExternalCommands(); } Value StatusTable::ExternalCommandsRateAccessor(const Value&) { - return (Query::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime())); + return (LivestatusQuery::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime())); } Value StatusTable::NagiosPidAccessor(const Value&) -- 2.40.0