Livestatus: Add compat_log_path config option for historical tables.

Fixes #5017
This commit is contained in:
Michael Friedrich 2013-11-07 14:04:13 +01:00
parent 6acc017707
commit 5caec8c570
13 changed files with 35 additions and 23 deletions

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

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

View File

@ -25,4 +25,6 @@ type LivestatusListener {
%attribute string "socket_path",
%attribute string "bind_host",
%attribute string "bind_port",
%attribute string "compat_log_path",
}

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

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

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

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

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

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

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

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

View 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
# icinga2-enable-feature compatlog

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