]> granicus.if.org Git - icinga2/commitdiff
Livestatus: Add compat_log_path config option for historical tables.
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 7 Nov 2013 13:04:13 +0000 (14:04 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 7 Nov 2013 13:16:10 +0000 (14:16 +0100)
Fixes #5017

13 files changed:
components/livestatus/listener.cpp
components/livestatus/listener.ti
components/livestatus/livestatus-type.conf
components/livestatus/logtable.cpp
components/livestatus/logtable.h
components/livestatus/query.cpp
components/livestatus/query.h
components/livestatus/statehisttable.cpp
components/livestatus/statehisttable.h
components/livestatus/table.cpp
components/livestatus/table.h
doc/2.5-setting-up-livestatus.md
doc/4.3-object-types.md

index c2ce431a0262c98c33d8e445034a1530b3273f7c..b77fd02724e3597e5ea5d14c07f346eb7a6d4861 100644 (file)
@@ -133,7 +133,7 @@ void LivestatusListener::ClientThreadProc(const Socket::Ptr& client)
                                break;
                }
 
-               Query::Ptr query = make_shared<Query>(lines);
+               Query::Ptr query = make_shared<Query>(lines, GetCompatLogPath());
                if (!query->Execute(stream))
                        break;
        }
index 7f7c8455dbfd41bed291584d36dbff0078c996bb..b49752d9259f090a3cfc800cecbee956bc51bdc4 100644 (file)
@@ -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"; }}}
+       };
 };
 
 }
index 9c7421cbf10f7cf75cef6f8df1cfd968ab6bc0dd..846913ecd508873ca8727d19c1730f86e75aeeb1 100644 (file)
@@ -25,4 +25,6 @@ type LivestatusListener {
        %attribute string "socket_path",
        %attribute string "bind_host",
        %attribute string "bind_port",
+
+        %attribute string "compat_log_path",
 }
index 947ced1599a56117bab0b6af8ee244c85a507331..329bfc3cb51b154d0dec0b631cc61ce84e66d133 100644 (file)
@@ -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;
index e3f317470b1f8da9c7812efd104a475d06e44bb5..02cbcd1ea74e01a65f8c49767c57f8a0e365fff1 100644 (file)
@@ -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());
index 28f3bf2bac1d17994ea034b2f7c43d6344bcf8c3..de43a20762dbba018b027519e344832f17c61f07 100644 (file)
@@ -47,7 +47,7 @@ using namespace livestatus;
 static int l_ExternalCommands = 0;
 static boost::mutex l_QueryMutex;
 
-Query::Query(const std::vector<String>& lines)
+Query::Query(const std::vector<String>& lines, const String& log_path)
        : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1),
          m_LogTimeFrom(0), m_LogTimeUntil(static_cast<long>(Utility::GetTime()))
 {
@@ -64,6 +64,8 @@ Query::Query(const std::vector<String>& 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.");
index 14e85eb94156ea64ba5217afbb4ff489d74b358a..adb3bd5e399bf908213f24160ceab86f141f188d 100644 (file)
@@ -47,7 +47,7 @@ class Query : public Object
 public:
        DECLARE_PTR_TYPEDEFS(Query);
 
-       Query(const std::vector<String>& lines);
+       Query(const std::vector<String>& 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<String>& columns, const Array::Ptr& rs);
        void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level);
index 45a3ef1be393dce2260b200882518f8706adc463..fca276a767055c37cac6a552eb33919b76490193 100644 (file)
@@ -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;
index 69ec5cd1595ce156648adc8c8152da90963f2705..14714316f6af59cf87a04b2d0369db46b825de4c 100644 (file)
@@ -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());
index 57625fc31432737cff9d45210774d91e8736d5c3..ef004596183ff3e6e87a1c68dbeaa27487e7079a 100644 (file)
@@ -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<StatusTable>();
@@ -69,9 +69,9 @@ Table::Ptr Table::GetByName(const String& name, const unsigned long& from, const
        else if (name == "timeperiods")
                return make_shared<TimePeriodsTable>();
        else if (name == "log")
-               return make_shared<LogTable>(from, until);
+               return make_shared<LogTable>(compat_log_path, from, until);
        else if (name == "statehist")
-               return make_shared<StateHistTable>(from, until);
+               return make_shared<StateHistTable>(compat_log_path, from, until);
 
        return Table::Ptr();
 }
index 745b62e8c2f9aace7565168753816bcb9a303bae..7d543c2481c050f445b72d2f9298489123562b97 100644 (file)
@@ -40,7 +40,7 @@ public:
 
        typedef boost::function<void (const Value&)> 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;
 
index 51241b2b17d500d71b8d8977dc95b6895099a97b..0cdff2dcc7ece08be84b23d3a6bea19e90eb835e 100644 (file)
@@ -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
index 58f3e59da62c7d83a7bdbc84073010dab70b2e8d..aead93bc35671db256b44ba854c4d71b4ddd7473 100644 (file)
@@ -668,7 +668,9 @@ Multiple categories can be combined using the `|` operator.
 
 ### <a id="objecttype-livestatuslistener"></a> 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**
 >