1 /******************************************************************************
3 * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "livestatus/zonestable.hpp"
21 #include "remote/zone.hpp"
22 #include "base/configtype.hpp"
23 #include <boost/foreach.hpp>
25 using namespace icinga;
27 ZonesTable::ZonesTable(void)
32 void ZonesTable::AddColumns(Table *table, const String& prefix,
33 const Column::ObjectAccessor& objectAccessor)
35 table->AddColumn(prefix + "name", Column(&ZonesTable::NameAccessor, objectAccessor));
36 table->AddColumn(prefix + "parent", Column(&ZonesTable::ParentAccessor, objectAccessor));
37 table->AddColumn(prefix + "endpoints", Column(&ZonesTable::EndpointsAccessor, objectAccessor));
38 table->AddColumn(prefix + "global", Column(&ZonesTable::GlobalAccessor, objectAccessor));
41 String ZonesTable::GetName(void) const
46 String ZonesTable::GetPrefix(void) const
51 void ZonesTable::FetchRows(const AddRowFunction& addRowFn)
53 BOOST_FOREACH(const Zone::Ptr& zone, ConfigType::GetObjectsByType<Zone>()) {
54 if (!addRowFn(zone, LivestatusGroupByNone, Empty))
59 Value ZonesTable::NameAccessor(const Value& row)
61 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
66 return zone->GetName();
69 Value ZonesTable::ParentAccessor(const Value& row)
71 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
76 Zone::Ptr parent_zone = zone->GetParent();
81 return parent_zone->GetName();
84 Value ZonesTable::EndpointsAccessor(const Value& row)
86 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
91 std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
93 Array::Ptr endpoint_names = new Array();
95 BOOST_FOREACH(const Endpoint::Ptr endpoint, endpoints) {
96 endpoint_names->Add(endpoint->GetName());
102 return endpoint_names;
105 Value ZonesTable::GlobalAccessor(const Value& row)
107 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
112 return zone->GetGlobal() ? 1 : 0;