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/contactgroupstable.hpp"
21 #include "icinga/usergroup.hpp"
22 #include "base/configtype.hpp"
23 #include <boost/foreach.hpp>
25 using namespace icinga;
27 ContactGroupsTable::ContactGroupsTable(void)
32 void ContactGroupsTable::AddColumns(Table *table, const String& prefix,
33 const Column::ObjectAccessor& objectAccessor)
35 table->AddColumn(prefix + "name", Column(&ContactGroupsTable::NameAccessor, objectAccessor));
36 table->AddColumn(prefix + "alias", Column(&ContactGroupsTable::AliasAccessor, objectAccessor));
37 table->AddColumn(prefix + "members", Column(&ContactGroupsTable::MembersAccessor, objectAccessor));
40 String ContactGroupsTable::GetName(void) const
42 return "contactgroups";
45 String ContactGroupsTable::GetPrefix(void) const
47 return "contactgroup";
50 void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
52 BOOST_FOREACH(const UserGroup::Ptr& ug, ConfigType::GetObjectsByType<UserGroup>()) {
53 if (!addRowFn(ug, LivestatusGroupByNone, Empty))
58 Value ContactGroupsTable::NameAccessor(const Value& row)
60 UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
65 return user_group->GetName();
68 Value ContactGroupsTable::AliasAccessor(const Value& row)
70 UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
75 return user_group->GetName();
78 Value ContactGroupsTable::MembersAccessor(const Value& row)
80 UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
85 Array::Ptr members = new Array();
87 BOOST_FOREACH(const User::Ptr& user, user_group->GetMembers()) {
88 members->Add(user->GetName());