1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
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"
24 using namespace icinga;
26 ZonesTable::ZonesTable()
31 void ZonesTable::AddColumns(Table *table, const String& prefix,
32 const Column::ObjectAccessor& objectAccessor)
34 table->AddColumn(prefix + "name", Column(&ZonesTable::NameAccessor, objectAccessor));
35 table->AddColumn(prefix + "parent", Column(&ZonesTable::ParentAccessor, objectAccessor));
36 table->AddColumn(prefix + "endpoints", Column(&ZonesTable::EndpointsAccessor, objectAccessor));
37 table->AddColumn(prefix + "global", Column(&ZonesTable::GlobalAccessor, objectAccessor));
40 String ZonesTable::GetName() const
45 String ZonesTable::GetPrefix() const
50 void ZonesTable::FetchRows(const AddRowFunction& addRowFn)
52 for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
53 if (!addRowFn(zone, LivestatusGroupByNone, Empty))
58 Value ZonesTable::NameAccessor(const Value& row)
60 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
65 return zone->GetName();
68 Value ZonesTable::ParentAccessor(const Value& row)
70 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
75 Zone::Ptr parent_zone = zone->GetParent();
80 return parent_zone->GetName();
83 Value ZonesTable::EndpointsAccessor(const Value& row)
85 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
90 std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
92 Array::Ptr endpoint_names = new Array();
94 for (const Endpoint::Ptr& endpoint : endpoints) {
95 endpoint_names->Add(endpoint->GetName());
101 return endpoint_names;
104 Value ZonesTable::GlobalAccessor(const Value& row)
106 Zone::Ptr zone = static_cast<Zone::Ptr>(row);
111 return zone->GetGlobal() ? 1 : 0;