mirror of https://github.com/Icinga/icinga2.git
parent
726a55fedb
commit
876c482ab8
|
@ -40,14 +40,16 @@ bool AttributeFilter::Apply(const Table::Ptr& table, const Value& row)
|
|||
if (value.IsObjectType<Array>()) {
|
||||
Array::Ptr array = value;
|
||||
|
||||
if (m_Operator == ">=") {
|
||||
if (m_Operator == ">=" || m_Operator == "<") {
|
||||
bool negate = (m_Operator == "<");
|
||||
|
||||
ObjectLock olock(array);
|
||||
BOOST_FOREACH(const String& item, array) {
|
||||
if (item == m_Operand)
|
||||
return true; /* Item found in list. */
|
||||
return !negate; /* Item found in list. */
|
||||
}
|
||||
|
||||
return false; /* Item not found in list. */
|
||||
return negate; /* Item not found in list. */
|
||||
} else if (m_Operator == "=") {
|
||||
return (array->GetLength() == 0);
|
||||
} else {
|
||||
|
|
|
@ -49,6 +49,11 @@ void CommandsTable::AddColumns(Table *table, const String& prefix,
|
|||
}
|
||||
|
||||
String CommandsTable::GetName(void) const
|
||||
{
|
||||
return "commands";
|
||||
}
|
||||
|
||||
String CommandsTable::GetPrefix(void) const
|
||||
{
|
||||
return "command";
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -55,6 +55,11 @@ String CommentsTable::GetName(void) const
|
|||
return "comments";
|
||||
}
|
||||
|
||||
String CommentsTable::GetPrefix(void) const
|
||||
{
|
||||
return "comment";
|
||||
}
|
||||
|
||||
void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -42,6 +42,11 @@ String ContactGroupsTable::GetName(void) const
|
|||
return "contactgroups";
|
||||
}
|
||||
|
||||
String ContactGroupsTable::GetPrefix(void) const
|
||||
{
|
||||
return "contactgroup";
|
||||
}
|
||||
|
||||
void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const UserGroup::Ptr& ug, DynamicType::GetObjects<UserGroup>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -60,6 +60,11 @@ String ContactsTable::GetName(void) const
|
|||
return "contacts";
|
||||
}
|
||||
|
||||
String ContactsTable::GetPrefix(void) const
|
||||
{
|
||||
return "contact";
|
||||
}
|
||||
|
||||
void ContactsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -55,6 +55,11 @@ String DowntimesTable::GetName(void) const
|
|||
return "downtimes";
|
||||
}
|
||||
|
||||
String DowntimesTable::GetPrefix(void) const
|
||||
{
|
||||
return "downtime";
|
||||
}
|
||||
|
||||
void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -53,6 +53,11 @@ String EndpointsTable::GetName(void) const
|
|||
return "endpoints";
|
||||
}
|
||||
|
||||
String EndpointsTable::GetPrefix(void) const
|
||||
{
|
||||
return "endpoint";
|
||||
}
|
||||
|
||||
void EndpointsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -66,6 +66,11 @@ String HostGroupsTable::GetName(void) const
|
|||
return "hostgroups";
|
||||
}
|
||||
|
||||
String HostGroupsTable::GetPrefix(void) const
|
||||
{
|
||||
return "hostgroup";
|
||||
}
|
||||
|
||||
void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjects<HostGroup>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -167,6 +167,11 @@ String HostsTable::GetName(void) const
|
|||
return "hosts";
|
||||
}
|
||||
|
||||
String HostsTable::GetPrefix(void) const
|
||||
{
|
||||
return "host";
|
||||
}
|
||||
|
||||
void HostsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -353,7 +353,7 @@ Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& fr
|
|||
return filter;
|
||||
}
|
||||
|
||||
void LivestatusQuery::PrintResultSet(std::ostream& fp, const Array::Ptr& rs)
|
||||
void LivestatusQuery::PrintResultSet(std::ostream& fp, const Array::Ptr& rs) const
|
||||
{
|
||||
if (m_OutputFormat == "csv") {
|
||||
ObjectLock olock(rs);
|
||||
|
@ -378,10 +378,12 @@ void LivestatusQuery::PrintResultSet(std::ostream& fp, const Array::Ptr& rs)
|
|||
}
|
||||
} else if (m_OutputFormat == "json") {
|
||||
fp << JsonSerialize(rs);
|
||||
} else if (m_OutputFormat == "python") {
|
||||
PrintPythonArray(fp, rs);
|
||||
}
|
||||
}
|
||||
|
||||
void LivestatusQuery::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level)
|
||||
void LivestatusQuery::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level) const
|
||||
{
|
||||
bool first = true;
|
||||
|
||||
|
@ -399,6 +401,35 @@ void LivestatusQuery::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, i
|
|||
}
|
||||
}
|
||||
|
||||
void LivestatusQuery::PrintPythonArray(std::ostream& fp, const Array::Ptr& rs) const
|
||||
{
|
||||
fp << "[ ";
|
||||
|
||||
bool first = true;
|
||||
|
||||
BOOST_FOREACH(const Value& value, rs) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
fp << ", ";
|
||||
|
||||
if (value.IsObjectType<Array>())
|
||||
PrintPythonArray(fp, value);
|
||||
else if (value.IsNumber())
|
||||
fp << value;
|
||||
else
|
||||
fp << QuoteStringPython(value);
|
||||
}
|
||||
|
||||
fp << " ]";
|
||||
}
|
||||
|
||||
String LivestatusQuery::QuoteStringPython(const String& str) {
|
||||
String result = str;
|
||||
boost::algorithm::replace_all(result, "\"", "\\\"");
|
||||
return "r\"" + result + "\"";
|
||||
}
|
||||
|
||||
void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
|
||||
{
|
||||
Log(LogInformation, "LivestatusQuery", "Table: " + m_Table);
|
||||
|
|
|
@ -82,8 +82,10 @@ private:
|
|||
unsigned long m_LogTimeUntil;
|
||||
String m_CompatLogPath;
|
||||
|
||||
void PrintResultSet(std::ostream& fp, const Array::Ptr& rs);
|
||||
void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level);
|
||||
void PrintResultSet(std::ostream& fp, const Array::Ptr& rs) const;
|
||||
void PrintCsvArray(std::ostream& fp, const Array::Ptr& array, int level) const;
|
||||
void PrintPythonArray(std::ostream& fp, const Array::Ptr& array) const;
|
||||
static String QuoteStringPython(const String& str);
|
||||
|
||||
void ExecuteGetHelper(const Stream::Ptr& stream);
|
||||
void ExecuteCommandHelper(const Stream::Ptr& stream);
|
||||
|
|
|
@ -89,6 +89,11 @@ String LogTable::GetName(void) const
|
|||
return "log";
|
||||
}
|
||||
|
||||
String LogTable::GetPrefix(void) const
|
||||
{
|
||||
return "log";
|
||||
}
|
||||
|
||||
void LogTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
Log(LogDebug, "LogTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil));
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
void UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn);
|
||||
|
||||
|
|
|
@ -57,6 +57,11 @@ String ServiceGroupsTable::GetName(void) const
|
|||
return "servicegroups";
|
||||
}
|
||||
|
||||
String ServiceGroupsTable::GetPrefix(void) const
|
||||
{
|
||||
return "servicegroup";
|
||||
}
|
||||
|
||||
void ServiceGroupsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjects<ServiceGroup>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -138,6 +138,11 @@ String ServicesTable::GetName(void) const
|
|||
return "services";
|
||||
}
|
||||
|
||||
String ServicesTable::GetPrefix(void) const
|
||||
{
|
||||
return "service";
|
||||
}
|
||||
|
||||
void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -250,6 +250,11 @@ String StateHistTable::GetName(void) const
|
|||
return "log";
|
||||
}
|
||||
|
||||
String StateHistTable::GetPrefix(void) const
|
||||
{
|
||||
return "log";
|
||||
}
|
||||
|
||||
void StateHistTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
Log(LogDebug, "StateHistTable", "Pre-selecting log file from " + Convert::ToString(m_TimeFrom) + " until " + Convert::ToString(m_TimeUntil));
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
void UpdateLogEntries(const Dictionary::Ptr& log_entry_attrs, int line_count, int lineno, const AddRowFunction& addRowFn);
|
||||
|
||||
|
|
|
@ -108,6 +108,11 @@ String StatusTable::GetName(void) const
|
|||
return "status";
|
||||
}
|
||||
|
||||
String StatusTable::GetPrefix(void) const
|
||||
{
|
||||
return "status";
|
||||
}
|
||||
|
||||
void StatusTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
Object::Ptr obj = make_shared<Object>();
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "livestatus/filter.hpp"
|
||||
#include "base/array.hpp"
|
||||
#include "base/dictionary.hpp"
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -90,10 +91,16 @@ void Table::AddColumn(const String& name, const Column& column)
|
|||
|
||||
Column Table::GetColumn(const String& name) const
|
||||
{
|
||||
std::map<String, Column>::const_iterator it = m_Columns.find(name);
|
||||
String dname = name;
|
||||
String prefix = GetPrefix() + "_";
|
||||
|
||||
if (dname.Find(prefix) == 0)
|
||||
dname = dname.SubStr(prefix.GetLength());
|
||||
|
||||
std::map<String, Column>::const_iterator it = m_Columns.find(dname);
|
||||
|
||||
if (it == m_Columns.end())
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + name + "' does not exist in table '" + GetName() + "'."));
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + dname + "' does not exist in table '" + GetName() + "'."));
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
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 GetPrefix(void) const = 0;
|
||||
|
||||
std::vector<Value> FilterRows(const shared_ptr<Filter>& filter);
|
||||
|
||||
|
|
|
@ -47,6 +47,11 @@ String TimePeriodsTable::GetName(void) const
|
|||
return "timeperiod";
|
||||
}
|
||||
|
||||
String TimePeriodsTable::GetPrefix(void) const
|
||||
{
|
||||
return "timeperiod";
|
||||
}
|
||||
|
||||
void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
virtual String GetPrefix(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
|
Loading…
Reference in New Issue