mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-14 09:14:29 +02:00
parent
8033586f66
commit
2a097d0b04
@ -26,10 +26,10 @@ using namespace livestatus;
|
|||||||
AndFilter::AndFilter(void)
|
AndFilter::AndFilter(void)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool AndFilter::Apply(const Table::Ptr& table, const Object::Ptr& object)
|
bool AndFilter::Apply(const Table::Ptr& table, const Value& row)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) {
|
BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) {
|
||||||
if (!filter->Apply(table, object))
|
if (!filter->Apply(table, row))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
AndFilter(void);
|
AndFilter(void);
|
||||||
|
|
||||||
virtual bool Apply(const Table::Ptr& table, const Object::Ptr& object);
|
virtual bool Apply(const Table::Ptr& table, const Value& row);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,11 @@ AttributeFilter::AttributeFilter(const String& column, const String& op, const S
|
|||||||
: m_Column(column), m_Operator(op), m_Operand(operand)
|
: m_Column(column), m_Operator(op), m_Operand(operand)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool AttributeFilter::Apply(const Table::Ptr& table, const Object::Ptr& object)
|
bool AttributeFilter::Apply(const Table::Ptr& table, const Value& row)
|
||||||
{
|
{
|
||||||
Column column = table->GetColumn(m_Column);
|
Column column = table->GetColumn(m_Column);
|
||||||
|
|
||||||
Value value = column.ExtractValue(object);
|
Value value = column.ExtractValue(row);
|
||||||
|
|
||||||
if (value.IsObjectType<Array>()) {
|
if (value.IsObjectType<Array>()) {
|
||||||
if (m_Operator == ">=") {
|
if (m_Operator == ">=") {
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
AttributeFilter(const String& column, const String& op, const String& operand);
|
AttributeFilter(const String& column, const String& op, const String& operand);
|
||||||
|
|
||||||
virtual bool Apply(const Table::Ptr& table, const Object::Ptr& object);
|
virtual bool Apply(const Table::Ptr& table, const Value& row);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String m_Column;
|
String m_Column;
|
||||||
|
@ -26,14 +26,14 @@ Column::Column(const ValueAccessor& valueAccessor, const ObjectAccessor& objectA
|
|||||||
: m_ValueAccessor(valueAccessor), m_ObjectAccessor(objectAccessor)
|
: m_ValueAccessor(valueAccessor), m_ObjectAccessor(objectAccessor)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Value Column::ExtractValue(const Object::Ptr& uobject) const
|
Value Column::ExtractValue(const Value& urow) const
|
||||||
{
|
{
|
||||||
Object::Ptr object;
|
Value row;
|
||||||
|
|
||||||
if (!m_ObjectAccessor.empty())
|
if (!m_ObjectAccessor.empty())
|
||||||
object = m_ObjectAccessor(uobject);
|
row = m_ObjectAccessor(urow);
|
||||||
else
|
else
|
||||||
object = uobject;
|
row = urow;
|
||||||
|
|
||||||
return m_ValueAccessor(object);
|
return m_ValueAccessor(row);
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,12 @@ namespace livestatus
|
|||||||
class Column
|
class Column
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef boost::function<Value (const Object::Ptr&)> ValueAccessor;
|
typedef boost::function<Value (const Value&)> ValueAccessor;
|
||||||
typedef boost::function<Object::Ptr (const Object::Ptr&)> ObjectAccessor;
|
typedef boost::function<Value (const Value&)> ObjectAccessor;
|
||||||
|
|
||||||
Column(const ValueAccessor& valueAccessor, const ObjectAccessor& objectAccessor);
|
Column(const ValueAccessor& valueAccessor, const ObjectAccessor& objectAccessor);
|
||||||
|
|
||||||
Value ExtractValue(const Object::Ptr& uobject) const;
|
Value ExtractValue(const Value& urow) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueAccessor m_ValueAccessor;
|
ValueAccessor m_ValueAccessor;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "livestatus/commentstable.h"
|
#include "livestatus/commentstable.h"
|
||||||
#include "livestatus/servicestable.h"
|
#include "livestatus/servicestable.h"
|
||||||
#include "livestatus/hoststable.h"
|
|
||||||
#include "icinga/service.h"
|
#include "icinga/service.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
@ -49,8 +48,6 @@ void CommentsTable::AddColumns(Table *table, const String& prefix,
|
|||||||
table->AddColumn(prefix + "expires", Column(&CommentsTable::ExpiresAccessor, objectAccessor));
|
table->AddColumn(prefix + "expires", Column(&CommentsTable::ExpiresAccessor, objectAccessor));
|
||||||
table->AddColumn(prefix + "expire_time", Column(&CommentsTable::ExpireTimeAccessor, objectAccessor));
|
table->AddColumn(prefix + "expire_time", Column(&CommentsTable::ExpireTimeAccessor, objectAccessor));
|
||||||
|
|
||||||
// TODO: Join hosts and services table with prefix
|
|
||||||
HostsTable::AddColumns(table, "host_", &CommentsTable::HostAccessor);
|
|
||||||
ServicesTable::AddColumns(table, "service_", &CommentsTable::ServiceAccessor);
|
ServicesTable::AddColumns(table, "service_", &CommentsTable::ServiceAccessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,10 +67,6 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
|
|||||||
|
|
||||||
ObjectLock olock(comments);
|
ObjectLock olock(comments);
|
||||||
|
|
||||||
/*Value comment;
|
|
||||||
BOOST_FOREACH(boost::tie(boost::tuples::ignore, comment), comments) {
|
|
||||||
addRowFn(comment);
|
|
||||||
}*/
|
|
||||||
String id;
|
String id;
|
||||||
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), comments) {
|
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), comments) {
|
||||||
addRowFn(id);
|
addRowFn(id);
|
||||||
@ -81,16 +74,6 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr CommentsTable::HostAccessor(const Value& row)
|
|
||||||
{
|
|
||||||
Service::Ptr svc = Service::GetOwnerByCommentID(row);
|
|
||||||
|
|
||||||
if (!svc)
|
|
||||||
return Value();
|
|
||||||
|
|
||||||
return svc->GetHost();
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr CommentsTable::ServiceAccessor(const Value& row)
|
Object::Ptr CommentsTable::ServiceAccessor(const Value& row)
|
||||||
{
|
{
|
||||||
return Service::GetOwnerByCommentID(row);
|
return Service::GetOwnerByCommentID(row);
|
||||||
@ -100,6 +83,9 @@ Value CommentsTable::AuthorAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
||||||
|
|
||||||
|
if (!comment)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return comment->Get("author");
|
return comment->Get("author");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +93,9 @@ Value CommentsTable::CommentAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
||||||
|
|
||||||
|
if (!comment)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return comment->Get("text");
|
return comment->Get("text");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +103,9 @@ Value CommentsTable::IdAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
||||||
|
|
||||||
|
if (!comment)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return comment->Get("legacy_id");
|
return comment->Get("legacy_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +113,9 @@ Value CommentsTable::EntryTimeAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
||||||
|
|
||||||
|
if (!comment)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return comment->Get("entry_time");
|
return comment->Get("entry_time");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +129,9 @@ Value CommentsTable::IsServiceAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Service::Ptr svc = Service::GetOwnerByCommentID(row);
|
Service::Ptr svc = Service::GetOwnerByCommentID(row);
|
||||||
|
|
||||||
|
if (!svc)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return (svc->IsHostCheck() ? 0 : 1);
|
return (svc->IsHostCheck() ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +151,9 @@ Value CommentsTable::EntryTypeAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
||||||
|
|
||||||
|
if (!comment)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return comment->Get("entry_type");
|
return comment->Get("entry_type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,6 +161,9 @@ Value CommentsTable::ExpiresAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
||||||
|
|
||||||
|
if (!comment)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return comment->Get("expires");
|
return comment->Get("expires");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,5 +171,8 @@ Value CommentsTable::ExpireTimeAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
Dictionary::Ptr comment = Service::GetCommentByID(row);
|
||||||
|
|
||||||
|
if (!comment)
|
||||||
|
return Value();
|
||||||
|
|
||||||
return comment->Get("expire_time");
|
return comment->Get("expire_time");
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||||
|
|
||||||
static Object::Ptr HostAccessor(const Value& row);
|
private:
|
||||||
static Object::Ptr ServiceAccessor(const Value& row);
|
static Object::Ptr ServiceAccessor(const Value& row);
|
||||||
|
|
||||||
static Value AuthorAccessor(const Value& row);
|
static Value AuthorAccessor(const Value& row);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "livestatus/downtimestable.h"
|
#include "livestatus/downtimestable.h"
|
||||||
|
#include "livestatus/servicestable.h"
|
||||||
#include "icinga/service.h"
|
#include "icinga/service.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
@ -47,7 +48,7 @@ void DowntimesTable::AddColumns(Table *table, const String& prefix,
|
|||||||
table->AddColumn(prefix + "duration", Column(&DowntimesTable::DurationAccessor, objectAccessor));
|
table->AddColumn(prefix + "duration", Column(&DowntimesTable::DurationAccessor, objectAccessor));
|
||||||
table->AddColumn(prefix + "triggered_by", Column(&DowntimesTable::TriggeredByAccessor, objectAccessor));
|
table->AddColumn(prefix + "triggered_by", Column(&DowntimesTable::TriggeredByAccessor, objectAccessor));
|
||||||
|
|
||||||
// TODO: Join services table.
|
ServicesTable::AddColumns(table, "service_", &DowntimesTable::ServiceAccessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
String DowntimesTable::GetName(void) const
|
String DowntimesTable::GetName(void) const
|
||||||
@ -66,10 +67,6 @@ void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
|
|||||||
|
|
||||||
ObjectLock olock(downtimes);
|
ObjectLock olock(downtimes);
|
||||||
|
|
||||||
/*Value downtime;
|
|
||||||
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
|
|
||||||
addRowFn(downtime);
|
|
||||||
}*/
|
|
||||||
String id;
|
String id;
|
||||||
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
|
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
|
||||||
addRowFn(id);
|
addRowFn(id);
|
||||||
@ -77,6 +74,11 @@ void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object::Ptr DowntimesTable::ServiceAccessor(const Value& row)
|
||||||
|
{
|
||||||
|
return Service::GetOwnerByDowntimeID(row);
|
||||||
|
}
|
||||||
|
|
||||||
Value DowntimesTable::AuthorAccessor(const Value& row)
|
Value DowntimesTable::AuthorAccessor(const Value& row)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||||
@ -142,18 +144,14 @@ Value DowntimesTable::FixedAccessor(const Value& row)
|
|||||||
|
|
||||||
Value DowntimesTable::DurationAccessor(const Value& row)
|
Value DowntimesTable::DurationAccessor(const Value& row)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||||
|
|
||||||
return downtime->Get("duration");
|
return downtime->Get("duration");
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value DowntimesTable::TriggeredByAccessor(const Value& row)
|
Value DowntimesTable::TriggeredByAccessor(const Value& row)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||||
|
|
||||||
return downtime->Get("triggered_by");
|
return downtime->Get("triggered_by");
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static Object::Ptr ServiceAccessor(const Value& row);
|
||||||
|
|
||||||
static Value AuthorAccessor(const Value& row);
|
static Value AuthorAccessor(const Value& row);
|
||||||
static Value CommentAccessor(const Value& row);
|
static Value CommentAccessor(const Value& row);
|
||||||
static Value IdAccessor(const Value& row);
|
static Value IdAccessor(const Value& row);
|
||||||
|
@ -33,7 +33,7 @@ class Filter : public Object
|
|||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(Filter);
|
DECLARE_PTR_TYPEDEFS(Filter);
|
||||||
|
|
||||||
virtual bool Apply(const Table::Ptr& table, const Object::Ptr& object) = 0;
|
virtual bool Apply(const Table::Ptr& table, const Value& row) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Filter(void);
|
Filter(void);
|
||||||
|
@ -26,7 +26,7 @@ NegateFilter::NegateFilter(const Filter::Ptr& inner)
|
|||||||
: m_Inner(inner)
|
: m_Inner(inner)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool NegateFilter::Apply(const Table::Ptr& table, const Object::Ptr& object)
|
bool NegateFilter::Apply(const Table::Ptr& table, const Value& row)
|
||||||
{
|
{
|
||||||
return !m_Inner->Apply(table, object);
|
return !m_Inner->Apply(table, row);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
NegateFilter(const Filter::Ptr& inner);
|
NegateFilter(const Filter::Ptr& inner);
|
||||||
|
|
||||||
virtual bool Apply(const Table::Ptr& table, const Object::Ptr& object);
|
virtual bool Apply(const Table::Ptr& table, const Value& row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Filter::Ptr m_Inner;
|
Filter::Ptr m_Inner;
|
||||||
|
@ -26,13 +26,13 @@ using namespace livestatus;
|
|||||||
OrFilter::OrFilter(void)
|
OrFilter::OrFilter(void)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool OrFilter::Apply(const Table::Ptr& table, const Object::Ptr& object)
|
bool OrFilter::Apply(const Table::Ptr& table, const Value& row)
|
||||||
{
|
{
|
||||||
if (m_Filters.empty())
|
if (m_Filters.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) {
|
BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) {
|
||||||
if (filter->Apply(table, object))
|
if (filter->Apply(table, row))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
OrFilter(void);
|
OrFilter(void);
|
||||||
|
|
||||||
virtual bool Apply(const Table::Ptr& table, const Object::Ptr& object);
|
virtual bool Apply(const Table::Ptr& table, const Value& row);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "base/convert.h"
|
#include "base/convert.h"
|
||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
#include "base/logger_fwd.h"
|
#include "base/logger_fwd.h"
|
||||||
|
#include "base/exception.h"
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
@ -220,7 +221,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Object::Ptr> objects = table->FilterRows(m_Filter);
|
std::vector<Value> objects = table->FilterRows(m_Filter);
|
||||||
std::vector<String> columns;
|
std::vector<String> columns;
|
||||||
|
|
||||||
if (m_Columns.size() > 0)
|
if (m_Columns.size() > 0)
|
||||||
@ -231,7 +232,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream)
|
|||||||
Array::Ptr rs = boost::make_shared<Array>();
|
Array::Ptr rs = boost::make_shared<Array>();
|
||||||
|
|
||||||
if (m_Stats.empty()) {
|
if (m_Stats.empty()) {
|
||||||
BOOST_FOREACH(const Object::Ptr& object, objects) {
|
BOOST_FOREACH(const Value& object, objects) {
|
||||||
Array::Ptr row = boost::make_shared<Array>();
|
Array::Ptr row = boost::make_shared<Array>();
|
||||||
|
|
||||||
BOOST_FOREACH(const String& columnName, columns) {
|
BOOST_FOREACH(const String& columnName, columns) {
|
||||||
@ -245,7 +246,7 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream)
|
|||||||
} else {
|
} else {
|
||||||
std::vector<int> stats(m_Stats.size(), 0);
|
std::vector<int> stats(m_Stats.size(), 0);
|
||||||
|
|
||||||
BOOST_FOREACH(const Object::Ptr& object, objects) {
|
BOOST_FOREACH(const Value& object, objects) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
BOOST_FOREACH(const Filter::Ptr filter, m_Stats) {
|
BOOST_FOREACH(const Filter::Ptr filter, m_Stats) {
|
||||||
if (filter->Apply(table, object))
|
if (filter->Apply(table, object))
|
||||||
@ -316,6 +317,10 @@ bool Query::Execute(const Stream::Ptr& stream)
|
|||||||
else
|
else
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid livestatus query verb."));
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid livestatus query verb."));
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
|
StackTrace *st = Exception::GetLastStackTrace();
|
||||||
|
std::ostringstream info;
|
||||||
|
st->Print(info);
|
||||||
|
Log(LogWarning, "livestatus", info.str());
|
||||||
SendResponse(stream, 452, boost::diagnostic_information(ex));
|
SendResponse(stream, 452, boost::diagnostic_information(ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix,
|
|||||||
table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
|
table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
|
||||||
table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
|
table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
|
||||||
|
|
||||||
HostsTable::AddColumns(table, "host_", &ServicesTable::HostAccessor);
|
HostsTable::AddColumns(table, "host_", boost::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
|
||||||
}
|
}
|
||||||
|
|
||||||
String ServicesTable::GetName(void) const
|
String ServicesTable::GetName(void) const
|
||||||
@ -134,9 +134,9 @@ void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::Ptr ServicesTable::HostAccessor(const Value& row)
|
Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
|
||||||
{
|
{
|
||||||
return static_cast<Service::Ptr>(row)->GetHost();
|
return static_cast<Service::Ptr>(parentObjectAccessor(row))->GetHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ServicesTable::ShortNameAccessor(const Value& row)
|
Value ServicesTable::ShortNameAccessor(const Value& row)
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||||
|
|
||||||
static Object::Ptr HostAccessor(const Value& row);
|
static Object::Ptr HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor);
|
||||||
|
|
||||||
static Value ShortNameAccessor(const Value& row);
|
static Value ShortNameAccessor(const Value& row);
|
||||||
static Value DisplayNameAccessor(const Value& row);
|
static Value DisplayNameAccessor(const Value& row);
|
||||||
|
@ -101,19 +101,19 @@ std::vector<String> Table::GetColumnNames(void) const
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Object::Ptr> Table::FilterRows(const Filter::Ptr& filter)
|
std::vector<Value> Table::FilterRows(const Filter::Ptr& filter)
|
||||||
{
|
{
|
||||||
std::vector<Object::Ptr> rs;
|
std::vector<Value> rs;
|
||||||
|
|
||||||
FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1));
|
FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1));
|
||||||
|
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Table::FilteredAddRow(std::vector<Object::Ptr>& rs, const Filter::Ptr& filter, const Object::Ptr& object)
|
void Table::FilteredAddRow(std::vector<Value>& rs, const Filter::Ptr& filter, const Value& row)
|
||||||
{
|
{
|
||||||
if (!filter || filter->Apply(GetSelf(), object))
|
if (!filter || filter->Apply(GetSelf(), row))
|
||||||
rs.push_back(object);
|
rs.push_back(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Table::ZeroAccessor(const Object::Ptr&)
|
Value Table::ZeroAccessor(const Object::Ptr&)
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
|
|
||||||
virtual String GetName(void) const = 0;
|
virtual String GetName(void) const = 0;
|
||||||
|
|
||||||
std::vector<Object::Ptr> FilterRows(const shared_ptr<Filter>& filter);
|
std::vector<Value> FilterRows(const shared_ptr<Filter>& filter);
|
||||||
|
|
||||||
void AddColumn(const String& name, const Column& column);
|
void AddColumn(const String& name, const Column& column);
|
||||||
Column GetColumn(const String& name) const;
|
Column GetColumn(const String& name) const;
|
||||||
@ -65,7 +65,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::map<String, Column> m_Columns;
|
std::map<String, Column> m_Columns;
|
||||||
|
|
||||||
void FilteredAddRow(std::vector<Object::Ptr>& rs, const shared_ptr<Filter>& filter, const Object::Ptr& object);
|
void FilteredAddRow(std::vector<Value>& rs, const shared_ptr<Filter>& filter, const Value& row);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user