-/******************************************************************************
- * Icinga 2 *
- * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License *
- * as published by the Free Software Foundation; either version 2 *
- * of the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software Foundation *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
- ******************************************************************************/
+/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
#include "livestatus/table.hpp"
#include "livestatus/statustable.hpp"
#include "livestatus/commentstable.hpp"
#include "livestatus/downtimestable.hpp"
#include "livestatus/endpointstable.hpp"
+#include "livestatus/zonestable.hpp"
#include "livestatus/timeperiodstable.hpp"
#include "livestatus/logtable.hpp"
#include "livestatus/statehisttable.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>
using namespace icinga;
-Table::Table(void)
+Table::Table(LivestatusGroupByType type)
+ : m_GroupByType(type), m_GroupByObject(Empty)
{ }
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>();
+ return new StatusTable();
else if (name == "contactgroups")
- return make_shared<ContactGroupsTable>();
+ return new ContactGroupsTable();
else if (name == "contacts")
- return make_shared<ContactsTable>();
+ return new ContactsTable();
else if (name == "hostgroups")
- return make_shared<HostGroupsTable>();
+ return new HostGroupsTable();
else if (name == "hosts")
- return make_shared<HostsTable>();
+ return new HostsTable();
+ else if (name == "hostsbygroup")
+ return new HostsTable(LivestatusGroupByHostGroup);
else if (name == "servicegroups")
- return make_shared<ServiceGroupsTable>();
+ return new ServiceGroupsTable();
else if (name == "services")
- return make_shared<ServicesTable>();
+ return new ServicesTable();
+ else if (name == "servicesbygroup")
+ return new ServicesTable(LivestatusGroupByServiceGroup);
+ else if (name == "servicesbyhostgroup")
+ return new ServicesTable(LivestatusGroupByHostGroup);
else if (name == "commands")
- return make_shared<CommandsTable>();
+ return new CommandsTable();
else if (name == "comments")
- return make_shared<CommentsTable>();
+ return new CommentsTable();
else if (name == "downtimes")
- return make_shared<DowntimesTable>();
+ return new DowntimesTable();
else if (name == "timeperiods")
- return make_shared<TimePeriodsTable>();
+ return new TimePeriodsTable();
else if (name == "log")
- return make_shared<LogTable>(compat_log_path, from, until);
+ return new LogTable(compat_log_path, from, until);
else if (name == "statehist")
- return make_shared<StateHistTable>(compat_log_path, from, until);
+ return new StateHistTable(compat_log_path, from, until);
else if (name == "endpoints")
- return make_shared<EndpointsTable>();
+ return new EndpointsTable();
+ else if (name == "zones")
+ return new ZonesTable();
- return Table::Ptr();
+ return nullptr;
}
void Table::AddColumn(const String& name, const Column& column)
{
std::pair<String, Column> item = std::make_pair(name, column);
- std::pair<std::map<String, Column>::iterator, bool> ret = m_Columns.insert(item);
+ auto ret = m_Columns.insert(item);
if (!ret.second)
ret.first->second = column;
if (dname.Find(prefix) == 0)
dname = dname.SubStr(prefix.GetLength());
- std::map<String, Column>::const_iterator it = m_Columns.find(dname);
+ auto it = m_Columns.find(dname);
if (it == m_Columns.end())
BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + dname + "' does not exist in table '" + GetName() + "'."));
return it->second;
}
-std::vector<String> Table::GetColumnNames(void) const
+std::vector<String> Table::GetColumnNames() const
{
std::vector<String> names;
- String name;
- BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), m_Columns) {
- names.push_back(name);
+ for (const auto& kv : m_Columns) {
+ names.push_back(kv.first);
}
return names;
}
-std::vector<Value> Table::FilterRows(const Filter::Ptr& filter)
+std::vector<LivestatusRowValue> Table::FilterRows(const Filter::Ptr& filter, int limit)
{
- std::vector<Value> rs;
+ std::vector<LivestatusRowValue> rs;
- FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1));
+ FetchRows(std::bind(&Table::FilteredAddRow, this, std::ref(rs), filter, limit, _1, _2, _3));
return rs;
}
-void Table::FilteredAddRow(std::vector<Value>& rs, const Filter::Ptr& filter, const Value& row)
+bool Table::FilteredAddRow(std::vector<LivestatusRowValue>& rs, const Filter::Ptr& filter, int limit, const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject)
{
- if (!filter || filter->Apply(GetSelf(), row))
- rs.push_back(row);
+ if (limit != -1 && static_cast<int>(rs.size()) == limit)
+ return false;
+
+ if (!filter || filter->Apply(this, row)) {
+ LivestatusRowValue rval;
+ rval.Row = row;
+ rval.GroupByType = groupByType;
+ rval.GroupByObject = groupByObject;
+
+ rs.emplace_back(std::move(rval));
+ }
+
+ return true;
}
Value Table::ZeroAccessor(const Value&)
Value Table::EmptyArrayAccessor(const Value&)
{
- return make_shared<Array>();
+ return new Array();
}
Value Table::EmptyDictionaryAccessor(const Value&)
{
- return make_shared<Dictionary>();
+ return new Dictionary();
+}
+
+LivestatusGroupByType Table::GetGroupByType() const
+{
+ return m_GroupByType;
}