break;
}
- Query::Ptr query = make_shared<Query>(lines);
+ Query::Ptr query = make_shared<Query>(lines, GetCompatLogPath());
if (!query->Execute(stream))
break;
}
[config] String bind_port {
default {{{ return "6558"; }}}
};
+ [config] String compat_log_path {
+ default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}}
+ };
};
}
%attribute string "socket_path",
%attribute string "bind_host",
%attribute string "bind_port",
+
+ %attribute string "compat_log_path",
}
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));
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;
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());
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()))
{
}
Log(LogDebug, "livestatus", msg);
+ m_CompatLogPath = log_path;
+
/* default separators */
m_Separators.push_back("\n");
m_Separators.push_back(";");
{
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.");
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);
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);
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));
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;
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());
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>();
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();
}
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;
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
### <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:
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**
>