void CommandsTable::FetchRows(const AddRowFunction& addRowFn)
{
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjectsByType<CheckCommand>()) {
- addRowFn(object, LivestatusGroupByNone, Empty);
+ if (!addRowFn(object, LivestatusGroupByNone, Empty))
+ return;
}
+
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjectsByType<EventCommand>()) {
- addRowFn(object, LivestatusGroupByNone, Empty);
+ if (!addRowFn(object, LivestatusGroupByNone, Empty))
+ return;
}
+
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjectsByType<NotificationCommand>()) {
- addRowFn(object, LivestatusGroupByNone, Empty);
+ if (!addRowFn(object, LivestatusGroupByNone, Empty))
+ return;
}
}
String id;
Comment::Ptr comment;
BOOST_FOREACH(tie(id, comment), comments) {
- if (Host::GetOwnerByCommentID(id) == host)
- addRowFn(comment, LivestatusGroupByNone, Empty);
+ if (Host::GetOwnerByCommentID(id) == host) {
+ if (!addRowFn(comment, LivestatusGroupByNone, Empty))
+ return;
+ }
}
}
String id;
Comment::Ptr comment;
BOOST_FOREACH(tie(id, comment), comments) {
- if (Service::GetOwnerByCommentID(id) == service)
- addRowFn(comment, LivestatusGroupByNone, Empty);
+ if (Service::GetOwnerByCommentID(id) == service) {
+ if (!addRowFn(comment, LivestatusGroupByNone, Empty))
+ return;
+ }
}
}
}
void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
{
BOOST_FOREACH(const UserGroup::Ptr& ug, DynamicType::GetObjectsByType<UserGroup>()) {
- addRowFn(ug, LivestatusGroupByNone, Empty);
+ if (!addRowFn(ug, LivestatusGroupByNone, Empty))
+ return;
}
}
void ContactsTable::FetchRows(const AddRowFunction& addRowFn)
{
BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjectsByType<User>()) {
- addRowFn(user, LivestatusGroupByNone, Empty);
+ if (!addRowFn(user, LivestatusGroupByNone, Empty))
+ return;
}
}
String id;
Downtime::Ptr downtime;
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
- if (Host::GetOwnerByDowntimeID(id) == host)
- addRowFn(downtime, LivestatusGroupByNone, Empty);
+ if (Host::GetOwnerByDowntimeID(id) == host) {
+ if (!addRowFn(downtime, LivestatusGroupByNone, Empty))
+ return;
+ }
}
}
String id;
Downtime::Ptr downtime;
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
- if (Service::GetOwnerByDowntimeID(id) == service)
- addRowFn(downtime, LivestatusGroupByNone, Empty);
+ if (Service::GetOwnerByDowntimeID(id) == service) {
+ if (!addRowFn(downtime, LivestatusGroupByNone, Empty))
+ return;
+ }
}
}
}
void EndpointsTable::FetchRows(const AddRowFunction& addRowFn)
{
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjectsByType<Endpoint>()) {
- addRowFn(endpoint, LivestatusGroupByNone, Empty);
+ if (!addRowFn(endpoint, LivestatusGroupByNone, Empty))
+ return;
}
}
void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
{
BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjectsByType<HostGroup>()) {
- addRowFn(hg, LivestatusGroupByNone, Empty);
+ if (!addRowFn(hg, LivestatusGroupByNone, Empty))
+ return;
}
}
BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjectsByType<HostGroup>()) {
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
/* the caller must know which groupby type and value are set for this row */
- addRowFn(host, LivestatusGroupByHostGroup, hg);
+ if (!addRowFn(host, LivestatusGroupByHostGroup, hg))
+ return;
}
}
} else {
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType<Host>()) {
- addRowFn(host, LivestatusGroupByNone, Empty);
+ if (!addRowFn(host, LivestatusGroupByNone, Empty))
+ return;
}
}
}
INITIALIZE_ONCE(InitScriptFrameCleanup);
LivestatusQuery::LivestatusQuery(const std::vector<String>& lines, const String& compat_log_path)
- : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_ErrorCode(0),
+ : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1), m_ErrorCode(0),
m_LogTimeFrom(0), m_LogTimeUntil(static_cast<long>(Utility::GetTime()))
{
if (lines.size() == 0) {
m_Separators[3] = String(1, static_cast<char>(Convert::ToLong(separators[3])));
} else if (header == "ColumnHeaders")
m_ColumnHeaders = (params == "on");
+ else if (header == "Limit")
+ m_Limit = Convert::ToLong(params);
else if (header == "Filter") {
Filter::Ptr filter = ParseFilter(params, m_LogTimeFrom, m_LogTimeUntil);
return;
}
- std::vector<LivestatusRowValue> objects = table->FilterRows(m_Filter);
+ std::vector<LivestatusRowValue> objects = table->FilterRows(m_Filter, m_Limit);
std::vector<String> columns;
if (m_Columns.size() > 0)
String m_OutputFormat;
bool m_ColumnHeaders;
+ int m_Limit;
String m_ResponseHeader;
void ServiceGroupsTable::FetchRows(const AddRowFunction& addRowFn)
{
BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjectsByType<ServiceGroup>()) {
- addRowFn(sg, LivestatusGroupByNone, Empty);
+ if (!addRowFn(sg, LivestatusGroupByNone, Empty))
+ return;
}
}
BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjectsByType<ServiceGroup>()) {
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
/* the caller must know which groupby type and value are set for this row */
- addRowFn(service, LivestatusGroupByServiceGroup, sg);
+ if (!addRowFn(service, LivestatusGroupByServiceGroup, sg))
+ return;
}
}
} else if (GetGroupByType() == LivestatusGroupByHostGroup) {
ObjectLock ylock(host);
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
/* the caller must know which groupby type and value are set for this row */
- addRowFn(service, LivestatusGroupByHostGroup, hg);
+ if (!addRowFn(service, LivestatusGroupByHostGroup, hg))
+ return;
}
}
}
} else {
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType<Service>()) {
- addRowFn(service, LivestatusGroupByNone, Empty);
+ if (!addRowFn(service, LivestatusGroupByNone, Empty))
+ return;
}
}
}
BOOST_FOREACH(boost::tie(checkable, boost::tuples::ignore), m_CheckablesCache) {
BOOST_FOREACH(const Dictionary::Ptr& state_hist_bag, m_CheckablesCache[checkable]) {
/* pass a dictionary from state history array */
- addRowFn(state_hist_bag, LivestatusGroupByNone, Empty);
+ if (!addRowFn(state_hist_bag, LivestatusGroupByNone, Empty))
+ return;
}
}
}
return names;
}
-std::vector<LivestatusRowValue> Table::FilterRows(const Filter::Ptr& filter)
+std::vector<LivestatusRowValue> Table::FilterRows(const Filter::Ptr& filter, int limit)
{
std::vector<LivestatusRowValue> rs;
- FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1, _2, _3));
+ FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, limit, _1, _2, _3));
return rs;
}
-void Table::FilteredAddRow(std::vector<LivestatusRowValue>& rs, const Filter::Ptr& filter, const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject)
+bool Table::FilteredAddRow(std::vector<LivestatusRowValue>& rs, const Filter::Ptr& filter, int limit, const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject)
{
+ if (limit != -1 && rs.size() == limit)
+ return false;
+
if (!filter || filter->Apply(this, row)) {
LivestatusRowValue rval;
rval.Row = row;
rval.GroupByObject = groupByObject;
rs.push_back(rval);
+
}
+
+ return true;
}
Value Table::ZeroAccessor(const Value&)
};
-typedef boost::function<void (const Value&, LivestatusGroupByType, const Object::Ptr&)> AddRowFunction;
+typedef boost::function<bool (const Value&, LivestatusGroupByType, const Object::Ptr&)> AddRowFunction;
class Filter;
virtual String GetName(void) const = 0;
virtual String GetPrefix(void) const = 0;
- std::vector<LivestatusRowValue> FilterRows(const intrusive_ptr<Filter>& filter);
+ std::vector<LivestatusRowValue> FilterRows(const intrusive_ptr<Filter>& filter, int limit = -1);
void AddColumn(const String& name, const Column& column);
Column GetColumn(const String& name) const;
private:
std::map<String, Column> m_Columns;
- void FilteredAddRow(std::vector<LivestatusRowValue>& rs, const intrusive_ptr<Filter>& filter, const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject);
+ bool FilteredAddRow(std::vector<LivestatusRowValue>& rs, const intrusive_ptr<Filter>& filter, int limit, const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject);
};
}
void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
{
BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjectsByType<TimePeriod>()) {
- addRowFn(tp, LivestatusGroupByNone, Empty);
+ if (!addRowFn(tp, LivestatusGroupByNone, Empty))
+ return;
}
}