2013-03-10 03:09:01 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-01-09 00:32:11 +01:00
|
|
|
* Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) *
|
2013-03-10 03:09:01 +01:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "livestatus/table.h"
|
|
|
|
#include "livestatus/statustable.h"
|
|
|
|
#include "livestatus/contactgroupstable.h"
|
|
|
|
#include "livestatus/contactstable.h"
|
2013-07-11 12:43:27 +02:00
|
|
|
#include "livestatus/hostgroupstable.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "livestatus/hoststable.h"
|
2013-07-11 12:43:27 +02:00
|
|
|
#include "livestatus/servicegroupstable.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "livestatus/servicestable.h"
|
2013-07-09 18:09:03 +02:00
|
|
|
#include "livestatus/commandstable.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "livestatus/commentstable.h"
|
|
|
|
#include "livestatus/downtimestable.h"
|
2013-07-11 13:03:14 +02:00
|
|
|
#include "livestatus/timeperiodstable.h"
|
2013-07-09 17:46:48 +02:00
|
|
|
#include "livestatus/logtable.h"
|
2013-11-06 13:29:00 +01:00
|
|
|
#include "livestatus/statehisttable.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "livestatus/filter.h"
|
|
|
|
#include "base/array.h"
|
|
|
|
#include "base/dictionary.h"
|
2013-03-15 18:21:29 +01:00
|
|
|
#include <boost/tuple/tuple.hpp>
|
2013-03-16 21:18:53 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2013-03-17 20:19:29 +01:00
|
|
|
#include <boost/bind.hpp>
|
2013-03-10 03:09:01 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-03-10 09:23:13 +01:00
|
|
|
Table::Table(void)
|
2013-03-10 03:09:01 +01:00
|
|
|
{ }
|
|
|
|
|
2013-11-07 14:04:13 +01:00
|
|
|
Table::Ptr Table::GetByName(const String& name, const String& compat_log_path, const unsigned long& from, const unsigned long& until)
|
2013-03-10 03:09:01 +01:00
|
|
|
{
|
2013-03-10 09:23:13 +01:00
|
|
|
if (name == "status")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<StatusTable>();
|
2013-03-10 09:55:46 +01:00
|
|
|
else if (name == "contactgroups")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<ContactGroupsTable>();
|
2013-03-10 09:55:46 +01:00
|
|
|
else if (name == "contacts")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<ContactsTable>();
|
2013-07-09 18:33:27 +02:00
|
|
|
else if (name == "hostgroups")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<HostGroupsTable>();
|
2013-03-10 18:49:14 +01:00
|
|
|
else if (name == "hosts")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<HostsTable>();
|
2013-07-09 18:33:27 +02:00
|
|
|
else if (name == "servicegroups")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<ServiceGroupsTable>();
|
2013-03-10 22:20:13 +01:00
|
|
|
else if (name == "services")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<ServicesTable>();
|
2013-07-09 18:09:03 +02:00
|
|
|
else if (name == "commands")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<CommandsTable>();
|
2013-03-10 22:20:13 +01:00
|
|
|
else if (name == "comments")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<CommentsTable>();
|
2013-03-10 22:20:13 +01:00
|
|
|
else if (name == "downtimes")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<DowntimesTable>();
|
2013-07-11 13:03:14 +02:00
|
|
|
else if (name == "timeperiods")
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<TimePeriodsTable>();
|
2013-07-09 17:46:48 +02:00
|
|
|
else if (name == "log")
|
2013-11-07 14:04:13 +01:00
|
|
|
return make_shared<LogTable>(compat_log_path, from, until);
|
2013-11-06 13:29:00 +01:00
|
|
|
else if (name == "statehist")
|
2013-11-07 14:04:13 +01:00
|
|
|
return make_shared<StateHistTable>(compat_log_path, from, until);
|
2013-03-10 03:09:01 +01:00
|
|
|
|
2013-03-10 09:23:13 +01:00
|
|
|
return Table::Ptr();
|
|
|
|
}
|
|
|
|
|
2013-03-10 18:49:14 +01:00
|
|
|
void Table::AddColumn(const String& name, const Column& column)
|
2013-03-10 09:23:13 +01:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::pair<String, Column> item = std::make_pair(name, column);
|
2013-03-10 18:49:14 +01:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::pair<std::map<String, Column>::iterator, bool> ret = m_Columns.insert(item);
|
2013-03-10 18:49:14 +01:00
|
|
|
|
|
|
|
if (!ret.second)
|
|
|
|
ret.first->second = column;
|
2013-03-10 09:23:13 +01:00
|
|
|
}
|
|
|
|
|
2013-03-10 18:49:14 +01:00
|
|
|
Column Table::GetColumn(const String& name) const
|
2013-03-10 09:23:13 +01:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::map<String, Column>::const_iterator it = m_Columns.find(name);
|
2013-03-10 09:23:13 +01:00
|
|
|
|
|
|
|
if (it == m_Columns.end())
|
2013-07-11 14:20:43 +02:00
|
|
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + name + "' does not exist in table '" + GetName() + "'."));
|
2013-03-10 05:10:51 +01:00
|
|
|
|
2013-03-10 09:23:13 +01:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::vector<String> Table::GetColumnNames(void) const
|
2013-03-10 09:23:13 +01:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::vector<String> names;
|
2013-03-10 09:23:13 +01:00
|
|
|
|
|
|
|
String name;
|
2013-03-15 18:21:29 +01:00
|
|
|
BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), m_Columns) {
|
2013-03-10 09:23:13 +01:00
|
|
|
names.push_back(name);
|
2013-03-10 05:10:51 +01:00
|
|
|
}
|
|
|
|
|
2013-03-10 09:23:13 +01:00
|
|
|
return names;
|
|
|
|
}
|
2013-03-10 03:09:01 +01:00
|
|
|
|
2013-07-10 16:11:40 +02:00
|
|
|
std::vector<Value> Table::FilterRows(const Filter::Ptr& filter)
|
2013-03-10 09:23:13 +01:00
|
|
|
{
|
2013-07-10 16:11:40 +02:00
|
|
|
std::vector<Value> rs;
|
2013-03-10 05:10:51 +01:00
|
|
|
|
2013-03-10 15:11:32 +01:00
|
|
|
FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1));
|
2013-03-10 09:23:13 +01:00
|
|
|
|
|
|
|
return rs;
|
|
|
|
}
|
2013-03-10 05:10:51 +01:00
|
|
|
|
2013-07-10 16:11:40 +02:00
|
|
|
void Table::FilteredAddRow(std::vector<Value>& rs, const Filter::Ptr& filter, const Value& row)
|
2013-03-10 09:23:13 +01:00
|
|
|
{
|
2013-07-10 16:11:40 +02:00
|
|
|
if (!filter || filter->Apply(GetSelf(), row))
|
|
|
|
rs.push_back(row);
|
2013-03-10 09:23:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-05 13:39:40 +01:00
|
|
|
Value Table::ZeroAccessor(const Value&)
|
2013-03-10 09:23:13 +01:00
|
|
|
{
|
|
|
|
return 0;
|
2013-03-10 03:09:01 +01:00
|
|
|
}
|
2013-03-10 09:55:46 +01:00
|
|
|
|
2013-11-05 13:39:40 +01:00
|
|
|
Value Table::OneAccessor(const Value&)
|
2013-03-10 09:55:46 +01:00
|
|
|
{
|
2013-10-03 03:48:12 +02:00
|
|
|
return 1;
|
2013-03-10 09:55:46 +01:00
|
|
|
}
|
|
|
|
|
2013-11-05 13:39:40 +01:00
|
|
|
Value Table::EmptyStringAccessor(const Value&)
|
2013-03-10 09:55:46 +01:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-11-05 13:39:40 +01:00
|
|
|
Value Table::EmptyArrayAccessor(const Value&)
|
2013-03-10 09:55:46 +01:00
|
|
|
{
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<Array>();
|
2013-03-10 09:55:46 +01:00
|
|
|
}
|
|
|
|
|
2013-11-05 13:39:40 +01:00
|
|
|
Value Table::EmptyDictionaryAccessor(const Value&)
|
2013-03-10 09:55:46 +01:00
|
|
|
{
|
2013-11-06 08:51:56 +01:00
|
|
|
return make_shared<Dictionary>();
|
2013-03-10 09:55:46 +01:00
|
|
|
}
|