]> granicus.if.org Git - icinga2/blob - lib/livestatus/contactgroupstable.cpp
Update copyright headers for 2016
[icinga2] / lib / livestatus / contactgroupstable.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/)  *
4  *                                                                            *
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.                     *
9  *                                                                            *
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.                               *
14  *                                                                            *
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  ******************************************************************************/
19
20 #include "livestatus/contactgroupstable.hpp"
21 #include "icinga/usergroup.hpp"
22 #include "base/configtype.hpp"
23 #include <boost/foreach.hpp>
24
25 using namespace icinga;
26
27 ContactGroupsTable::ContactGroupsTable(void)
28 {
29         AddColumns(this);
30 }
31
32 void ContactGroupsTable::AddColumns(Table *table, const String& prefix,
33     const Column::ObjectAccessor& objectAccessor)
34 {
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));
38 }
39
40 String ContactGroupsTable::GetName(void) const
41 {
42         return "contactgroups";
43 }
44
45 String ContactGroupsTable::GetPrefix(void) const
46 {
47         return "contactgroup";
48 }
49
50 void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
51 {
52         BOOST_FOREACH(const UserGroup::Ptr& ug, ConfigType::GetObjectsByType<UserGroup>()) {
53                 if (!addRowFn(ug, LivestatusGroupByNone, Empty))
54                         return;
55         }
56 }
57
58 Value ContactGroupsTable::NameAccessor(const Value& row)
59 {
60         UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
61
62         if (!user_group)
63                 return Empty;
64
65         return user_group->GetName();
66 }
67
68 Value ContactGroupsTable::AliasAccessor(const Value& row)
69 {
70         UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
71
72         if (!user_group)
73                 return Empty;
74
75         return user_group->GetName();
76 }
77
78 Value ContactGroupsTable::MembersAccessor(const Value& row)
79 {
80         UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
81
82         if (!user_group)
83                 return Empty;
84
85         Array::Ptr members = new Array();
86
87         BOOST_FOREACH(const User::Ptr& user, user_group->GetMembers()) {
88                 members->Add(user->GetName());
89         }
90
91         return members;
92 }