1 /******************************************************************************
3 * Copyright (C) 2012-2017 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/contactgroupstable.hpp"
21 #include "icinga/usergroup.hpp"
22 #include "base/configtype.hpp"
24 using namespace icinga;
26 ContactGroupsTable::ContactGroupsTable(void)
31 void ContactGroupsTable::AddColumns(Table *table, const String& prefix,
32 const Column::ObjectAccessor& objectAccessor)
34 table->AddColumn(prefix + "name", Column(&ContactGroupsTable::NameAccessor, objectAccessor));
35 table->AddColumn(prefix + "alias", Column(&ContactGroupsTable::AliasAccessor, objectAccessor));
36 table->AddColumn(prefix + "members", Column(&ContactGroupsTable::MembersAccessor, objectAccessor));
39 String ContactGroupsTable::GetName(void) const
41 return "contactgroups";
44 String ContactGroupsTable::GetPrefix(void) const
46 return "contactgroup";
49 void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
51 for (const UserGroup::Ptr& ug : ConfigType::GetObjectsByType<UserGroup>()) {
52 if (!addRowFn(ug, LivestatusGroupByNone, Empty))
57 Value ContactGroupsTable::NameAccessor(const Value& row)
59 UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
64 return user_group->GetName();
67 Value ContactGroupsTable::AliasAccessor(const Value& row)
69 UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
74 return user_group->GetName();
77 Value ContactGroupsTable::MembersAccessor(const Value& row)
79 UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
84 Array::Ptr members = new Array();
86 for (const User::Ptr& user : user_group->GetMembers()) {
87 members->Add(user->GetName());