1 /******************************************************************************
3 * Copyright (C) 2012 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/hostgroupstable.h"
21 #include "icinga/hostgroup.h"
22 #include "base/dynamictype.h"
23 #include <boost/foreach.hpp>
25 using namespace icinga;
26 using namespace livestatus;
28 HostGroupsTable::HostGroupsTable(void)
33 void HostGroupsTable::AddColumns(Table *table, const String& prefix,
34 const Column::ObjectAccessor& objectAccessor)
36 table->AddColumn(prefix + "name", Column(&HostGroupsTable::NameAccessor, objectAccessor));
37 table->AddColumn(prefix + "alias", Column(&HostGroupsTable::AliasAccessor, objectAccessor));
38 table->AddColumn(prefix + "members", Column(&HostGroupsTable::MembersAccessor, objectAccessor));
41 String HostGroupsTable::GetName(void) const
46 void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
48 BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
53 Value HostGroupsTable::NameAccessor(const Value& row)
55 return static_cast<HostGroup::Ptr>(row)->GetName();
58 Value HostGroupsTable::AliasAccessor(const Value& row)
60 return static_cast<HostGroup::Ptr>(row)->GetName();
63 Value HostGroupsTable::MembersAccessor(const Value& row)
65 Array::Ptr members = boost::make_shared<Array>();
67 BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
68 members->Add(host->GetName());