From 5caec8c5706efdef084175d155f2439c3924036e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 7 Nov 2013 14:04:13 +0100 Subject: [PATCH] Livestatus: Add compat_log_path config option for historical tables. Fixes #5017 --- components/livestatus/listener.cpp | 2 +- components/livestatus/listener.ti | 3 +++ components/livestatus/livestatus-type.conf | 2 ++ components/livestatus/logtable.cpp | 6 +++--- components/livestatus/logtable.h | 2 +- components/livestatus/query.cpp | 6 ++++-- components/livestatus/query.h | 3 ++- components/livestatus/statehisttable.cpp | 6 +++--- components/livestatus/statehisttable.h | 2 +- components/livestatus/table.cpp | 6 +++--- components/livestatus/table.h | 2 +- doc/2.5-setting-up-livestatus.md | 5 +++-- doc/4.3-object-types.md | 13 ++++++++----- 13 files changed, 35 insertions(+), 23 deletions(-) diff --git a/components/livestatus/listener.cpp b/components/livestatus/listener.cpp index c2ce431a0..b77fd0272 100644 --- a/components/livestatus/listener.cpp +++ b/components/livestatus/listener.cpp @@ -133,7 +133,7 @@ void LivestatusListener::ClientThreadProc(const Socket::Ptr& client) break; } - Query::Ptr query = make_shared(lines); + Query::Ptr query = make_shared(lines, GetCompatLogPath()); if (!query->Execute(stream)) break; } diff --git a/components/livestatus/listener.ti b/components/livestatus/listener.ti index 7f7c8455d..b49752d92 100644 --- a/components/livestatus/listener.ti +++ b/components/livestatus/listener.ti @@ -26,6 +26,9 @@ class livestatus::LivestatusListener : DynamicObject { [config] String bind_port { default {{{ return "6558"; }}} }; + [config] String compat_log_path { + default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}} + }; }; } diff --git a/components/livestatus/livestatus-type.conf b/components/livestatus/livestatus-type.conf index 9c7421cbf..846913ecd 100644 --- a/components/livestatus/livestatus-type.conf +++ b/components/livestatus/livestatus-type.conf @@ -25,4 +25,6 @@ type LivestatusListener { %attribute string "socket_path", %attribute string "bind_host", %attribute string "bind_port", + + %attribute string "compat_log_path", } diff --git a/components/livestatus/logtable.cpp b/components/livestatus/logtable.cpp index 947ced159..329bfc3cb 100644 --- a/components/livestatus/logtable.cpp +++ b/components/livestatus/logtable.cpp @@ -47,7 +47,7 @@ using namespace icinga; using namespace livestatus; -LogTable::LogTable(const unsigned long& from, const unsigned long& until) +LogTable::LogTable(const String& compat_log_path, const unsigned long& from, const unsigned long& until) { Log(LogInformation, "livestatus", "Pre-selecting log file from " + Convert::ToString(from) + " until " + Convert::ToString(until)); @@ -55,8 +55,8 @@ LogTable::LogTable(const unsigned long& from, const unsigned long& until) m_TimeFrom = from; m_TimeUntil = until; - /* create log file index - TODO config option */ - CreateLogIndex(Application::GetLocalStateDir() + "/log/icinga2/compat"); + /* create log file index */ + CreateLogIndex(compat_log_path); /* m_LogFileIndex map tells which log files are involved ordered by their start timestamp */ unsigned long ts; diff --git a/components/livestatus/logtable.h b/components/livestatus/logtable.h index e3f317470..02cbcd1ea 100644 --- a/components/livestatus/logtable.h +++ b/components/livestatus/logtable.h @@ -66,7 +66,7 @@ class LogTable : public Table public: DECLARE_PTR_TYPEDEFS(LogTable); - LogTable(const unsigned long& from, const unsigned long& until); + LogTable(const String& compat_log_path, const unsigned long& from, const unsigned long& until); static void AddColumns(Table *table, const String& prefix = String(), const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor()); diff --git a/components/livestatus/query.cpp b/components/livestatus/query.cpp index 28f3bf2ba..de43a2076 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/query.cpp @@ -47,7 +47,7 @@ using namespace livestatus; static int l_ExternalCommands = 0; static boost::mutex l_QueryMutex; -Query::Query(const std::vector& lines) +Query::Query(const std::vector& lines, const String& log_path) : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1), m_LogTimeFrom(0), m_LogTimeUntil(static_cast(Utility::GetTime())) { @@ -64,6 +64,8 @@ Query::Query(const std::vector& lines) } Log(LogDebug, "livestatus", msg); + m_CompatLogPath = log_path; + /* default separators */ m_Separators.push_back("\n"); m_Separators.push_back(";"); @@ -394,7 +396,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream) { Log(LogInformation, "livestatus", "Table: " + m_Table); - Table::Ptr table = Table::GetByName(m_Table, m_LogTimeFrom, m_LogTimeUntil); + Table::Ptr table = Table::GetByName(m_Table, m_CompatLogPath, m_LogTimeFrom, m_LogTimeUntil); if (!table) { SendResponse(stream, LivestatusErrorNotFound, "Table '" + m_Table + "' does not exist."); diff --git a/components/livestatus/query.h b/components/livestatus/query.h index 14e85eb94..adb3bd5e3 100644 --- a/components/livestatus/query.h +++ b/components/livestatus/query.h @@ -47,7 +47,7 @@ class Query : public Object public: DECLARE_PTR_TYPEDEFS(Query); - Query(const std::vector& lines); + Query(const std::vector& lines, const String& log_path); bool Execute(const Stream::Ptr& stream); @@ -81,6 +81,7 @@ private: unsigned long m_LogTimeFrom; unsigned long m_LogTimeUntil; + String m_CompatLogPath; void PrintResultSet(std::ostream& fp, const std::vector& columns, const Array::Ptr& rs); void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level); diff --git a/components/livestatus/statehisttable.cpp b/components/livestatus/statehisttable.cpp index 45a3ef1be..fca276a76 100644 --- a/components/livestatus/statehisttable.cpp +++ b/components/livestatus/statehisttable.cpp @@ -48,7 +48,7 @@ using namespace icinga; using namespace livestatus; -StateHistTable::StateHistTable(const unsigned long& from, const unsigned long& until) +StateHistTable::StateHistTable(const String& compat_log_path, const unsigned long& from, const unsigned long& until) { Log(LogInformation, "livestatus", "Pre-selecting log file from " + Convert::ToString(from) + " until " + Convert::ToString(until)); @@ -56,8 +56,8 @@ StateHistTable::StateHistTable(const unsigned long& from, const unsigned long& u m_TimeFrom = from; m_TimeUntil = until; - /* create log file index - TODO config option */ - CreateLogIndex(Application::GetLocalStateDir() + "/log/icinga2/compat"); + /* create log file index */ + CreateLogIndex(compat_log_path); /* m_LogFileIndex map tells which log files are involved ordered by their start timestamp */ unsigned long ts; diff --git a/components/livestatus/statehisttable.h b/components/livestatus/statehisttable.h index 69ec5cd15..14714316f 100644 --- a/components/livestatus/statehisttable.h +++ b/components/livestatus/statehisttable.h @@ -67,7 +67,7 @@ class StateHistTable : public Table public: DECLARE_PTR_TYPEDEFS(StateHistTable); - StateHistTable(const unsigned long& from, const unsigned long& until); + StateHistTable(const String& compat_log_path, const unsigned long& from, const unsigned long& until); static void AddColumns(Table *table, const String& prefix = String(), const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor()); diff --git a/components/livestatus/table.cpp b/components/livestatus/table.cpp index 57625fc31..ef0045961 100644 --- a/components/livestatus/table.cpp +++ b/components/livestatus/table.cpp @@ -44,7 +44,7 @@ using namespace livestatus; Table::Table(void) { } -Table::Ptr Table::GetByName(const String& name, const unsigned long& from, const unsigned long& until) +Table::Ptr Table::GetByName(const String& name, const String& compat_log_path, const unsigned long& from, const unsigned long& until) { if (name == "status") return make_shared(); @@ -69,9 +69,9 @@ Table::Ptr Table::GetByName(const String& name, const unsigned long& from, const else if (name == "timeperiods") return make_shared(); else if (name == "log") - return make_shared(from, until); + return make_shared(compat_log_path, from, until); else if (name == "statehist") - return make_shared(from, until); + return make_shared(compat_log_path, from, until); return Table::Ptr(); } diff --git a/components/livestatus/table.h b/components/livestatus/table.h index 745b62e8c..7d543c248 100644 --- a/components/livestatus/table.h +++ b/components/livestatus/table.h @@ -40,7 +40,7 @@ public: typedef boost::function AddRowFunction; - static Table::Ptr GetByName(const String& name, const unsigned long& from = 0, const unsigned long& until = 0); + 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; diff --git a/doc/2.5-setting-up-livestatus.md b/doc/2.5-setting-up-livestatus.md index 51241b2b1..0cdff2dcc 100644 --- a/doc/2.5-setting-up-livestatus.md +++ b/doc/2.5-setting-up-livestatus.md @@ -29,6 +29,7 @@ In order for queries and commands to work you will need to add your query user In order to use the historical tables provided by the livestatus feature (for example, the `log` table) you need to have the `CompatLogger` feature enabled. By default these logs -are expected in `/var/log/icinga2/compat`. +are expected in `/var/log/icinga2/compat`. A different path can be set using the `compat_log_path` +configuration attribute. - # icinga2-enable-feature compatlog \ No newline at end of file + # icinga2-enable-feature compatlog diff --git a/doc/4.3-object-types.md b/doc/4.3-object-types.md index 58f3e59da..aead93bc3 100644 --- a/doc/4.3-object-types.md +++ b/doc/4.3-object-types.md @@ -668,7 +668,9 @@ Multiple categories can be combined using the `|` operator. ### LiveStatusListener -Livestatus API interface available as TCP or UNIX socket. +Livestatus API interface available as TCP or UNIX socket. Historical table queries +require the `CompatLogger` feature enabled pointing to the log files using the +`compat_log_path` configuration attribute. Example: @@ -689,10 +691,11 @@ Attributes: Name |Description ----------------|---------------- - socket\_type |**Optional.** Specifies the socket type. Can be either "tcp" or "unix". Defaults to "unix". - bind\_host |**Optional.** Only valid when socket\_type is "tcp". Host address to listen on for connections. Defaults to "127.0.0.1". - bind\_port |**Optional.** Only valid when `socket\_type` is "tcp". Port to listen on for connections. Defaults to 6558. - socket\_path |**Optional.** Only valid when `socket\_type` is "unix". Specifies the path to the UNIX socket file. Defaults to IcingaLocalStateDir + "/run/icinga2/livestatus". + socket\_type |**Optional.** Specifies the socket type. Can be either "tcp" or "unix". Defaults to "unix". + bind\_host |**Optional.** Only valid when socket\_type is "tcp". Host address to listen on for connections. Defaults to "127.0.0.1". + bind\_port |**Optional.** Only valid when `socket\_type` is "tcp". Port to listen on for connections. Defaults to 6558. + socket\_path |**Optional.** Only valid when `socket\_type` is "unix". Specifies the path to the UNIX socket file. Defaults to IcingaLocalStateDir + "/run/icinga2/livestatus". + compat\_log\_path |**Optional.** Required for historical table queries. Requires `CompatLogger` feature enabled. Defaults to IcingaLocalStateDir + "/log/icinga2/compat" > **Note** >