mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 15:44:11 +02:00
Livestatus: Add compat_log_path config option for historical tables.
Fixes #5017
This commit is contained in:
parent
6acc017707
commit
5caec8c570
@ -133,7 +133,7 @@ void LivestatusListener::ClientThreadProc(const Socket::Ptr& client)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Query::Ptr query = make_shared<Query>(lines);
|
Query::Ptr query = make_shared<Query>(lines, GetCompatLogPath());
|
||||||
if (!query->Execute(stream))
|
if (!query->Execute(stream))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ class livestatus::LivestatusListener : DynamicObject {
|
|||||||
[config] String bind_port {
|
[config] String bind_port {
|
||||||
default {{{ return "6558"; }}}
|
default {{{ return "6558"; }}}
|
||||||
};
|
};
|
||||||
|
[config] String compat_log_path {
|
||||||
|
default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,6 @@ type LivestatusListener {
|
|||||||
%attribute string "socket_path",
|
%attribute string "socket_path",
|
||||||
%attribute string "bind_host",
|
%attribute string "bind_host",
|
||||||
%attribute string "bind_port",
|
%attribute string "bind_port",
|
||||||
|
|
||||||
|
%attribute string "compat_log_path",
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
using namespace livestatus;
|
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));
|
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_TimeFrom = from;
|
||||||
m_TimeUntil = until;
|
m_TimeUntil = until;
|
||||||
|
|
||||||
/* create log file index - TODO config option */
|
/* create log file index */
|
||||||
CreateLogIndex(Application::GetLocalStateDir() + "/log/icinga2/compat");
|
CreateLogIndex(compat_log_path);
|
||||||
|
|
||||||
/* m_LogFileIndex map tells which log files are involved ordered by their start timestamp */
|
/* m_LogFileIndex map tells which log files are involved ordered by their start timestamp */
|
||||||
unsigned long ts;
|
unsigned long ts;
|
||||||
|
@ -66,7 +66,7 @@ class LogTable : public Table
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(LogTable);
|
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(),
|
static void AddColumns(Table *table, const String& prefix = String(),
|
||||||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||||
|
@ -47,7 +47,7 @@ using namespace livestatus;
|
|||||||
static int l_ExternalCommands = 0;
|
static int l_ExternalCommands = 0;
|
||||||
static boost::mutex l_QueryMutex;
|
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_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1),
|
||||||
m_LogTimeFrom(0), m_LogTimeUntil(static_cast<long>(Utility::GetTime()))
|
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);
|
Log(LogDebug, "livestatus", msg);
|
||||||
|
|
||||||
|
m_CompatLogPath = log_path;
|
||||||
|
|
||||||
/* default separators */
|
/* default separators */
|
||||||
m_Separators.push_back("\n");
|
m_Separators.push_back("\n");
|
||||||
m_Separators.push_back(";");
|
m_Separators.push_back(";");
|
||||||
@ -394,7 +396,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream)
|
|||||||
{
|
{
|
||||||
Log(LogInformation, "livestatus", "Table: " + m_Table);
|
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) {
|
if (!table) {
|
||||||
SendResponse(stream, LivestatusErrorNotFound, "Table '" + m_Table + "' does not exist.");
|
SendResponse(stream, LivestatusErrorNotFound, "Table '" + m_Table + "' does not exist.");
|
||||||
|
@ -47,7 +47,7 @@ class Query : public Object
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(Query);
|
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);
|
bool Execute(const Stream::Ptr& stream);
|
||||||
|
|
||||||
@ -81,6 +81,7 @@ private:
|
|||||||
|
|
||||||
unsigned long m_LogTimeFrom;
|
unsigned long m_LogTimeFrom;
|
||||||
unsigned long m_LogTimeUntil;
|
unsigned long m_LogTimeUntil;
|
||||||
|
String m_CompatLogPath;
|
||||||
|
|
||||||
void PrintResultSet(std::ostream& fp, const std::vector<String>& columns, const Array::Ptr& rs);
|
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);
|
void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level);
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
using namespace livestatus;
|
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));
|
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_TimeFrom = from;
|
||||||
m_TimeUntil = until;
|
m_TimeUntil = until;
|
||||||
|
|
||||||
/* create log file index - TODO config option */
|
/* create log file index */
|
||||||
CreateLogIndex(Application::GetLocalStateDir() + "/log/icinga2/compat");
|
CreateLogIndex(compat_log_path);
|
||||||
|
|
||||||
/* m_LogFileIndex map tells which log files are involved ordered by their start timestamp */
|
/* m_LogFileIndex map tells which log files are involved ordered by their start timestamp */
|
||||||
unsigned long ts;
|
unsigned long ts;
|
||||||
|
@ -67,7 +67,7 @@ class StateHistTable : public Table
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(StateHistTable);
|
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(),
|
static void AddColumns(Table *table, const String& prefix = String(),
|
||||||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||||
|
@ -44,7 +44,7 @@ using namespace livestatus;
|
|||||||
Table::Table(void)
|
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")
|
if (name == "status")
|
||||||
return make_shared<StatusTable>();
|
return make_shared<StatusTable>();
|
||||||
@ -69,9 +69,9 @@ Table::Ptr Table::GetByName(const String& name, const unsigned long& from, const
|
|||||||
else if (name == "timeperiods")
|
else if (name == "timeperiods")
|
||||||
return make_shared<TimePeriodsTable>();
|
return make_shared<TimePeriodsTable>();
|
||||||
else if (name == "log")
|
else if (name == "log")
|
||||||
return make_shared<LogTable>(from, until);
|
return make_shared<LogTable>(compat_log_path, from, until);
|
||||||
else if (name == "statehist")
|
else if (name == "statehist")
|
||||||
return make_shared<StateHistTable>(from, until);
|
return make_shared<StateHistTable>(compat_log_path, from, until);
|
||||||
|
|
||||||
return Table::Ptr();
|
return Table::Ptr();
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
|
|
||||||
typedef boost::function<void (const Value&)> AddRowFunction;
|
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;
|
virtual String GetName(void) const = 0;
|
||||||
|
|
||||||
|
@ -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
|
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
|
`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
|
||||||
|
@ -668,7 +668,9 @@ Multiple categories can be combined using the `|` operator.
|
|||||||
|
|
||||||
### <a id="objecttype-livestatuslistener"></a> LiveStatusListener
|
### <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:
|
Example:
|
||||||
|
|
||||||
@ -689,10 +691,11 @@ Attributes:
|
|||||||
|
|
||||||
Name |Description
|
Name |Description
|
||||||
----------------|----------------
|
----------------|----------------
|
||||||
socket\_type |**Optional.** Specifies the socket type. Can be either "tcp" or "unix". Defaults to "unix".
|
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\_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.
|
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\_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**
|
> **Note**
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user