icinga2/lib/livestatus/contactgroupstable.cpp

75 lines
1.7 KiB
C++
Raw Normal View History

/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2014-05-25 16:23:35 +02:00
#include "livestatus/contactgroupstable.hpp"
#include "icinga/usergroup.hpp"
#include "base/configtype.hpp"
using namespace icinga;
ContactGroupsTable::ContactGroupsTable()
{
2013-03-10 18:49:14 +01:00
AddColumns(this);
}
void ContactGroupsTable::AddColumns(Table *table, const String& prefix,
const Column::ObjectAccessor& objectAccessor)
2013-03-10 18:49:14 +01:00
{
table->AddColumn(prefix + "name", Column(&ContactGroupsTable::NameAccessor, objectAccessor));
table->AddColumn(prefix + "alias", Column(&ContactGroupsTable::AliasAccessor, objectAccessor));
2013-03-10 18:49:14 +01:00
table->AddColumn(prefix + "members", Column(&ContactGroupsTable::MembersAccessor, objectAccessor));
}
String ContactGroupsTable::GetName() const
{
return "contactgroups";
}
String ContactGroupsTable::GetPrefix() const
{
return "contactgroup";
}
2013-03-15 18:21:29 +01:00
void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
{
for (const UserGroup::Ptr& ug : ConfigType::GetObjectsByType<UserGroup>()) {
if (!addRowFn(ug, LivestatusGroupByNone, Empty))
return;
}
}
Value ContactGroupsTable::NameAccessor(const Value& row)
{
2013-10-29 13:44:43 +01:00
UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
2015-02-11 15:47:45 +01:00
if (!user_group)
2013-10-29 13:44:43 +01:00
return Empty;
return user_group->GetName();
}
Value ContactGroupsTable::AliasAccessor(const Value& row)
{
2013-10-29 13:44:43 +01:00
UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
2015-02-11 15:47:45 +01:00
if (!user_group)
2013-10-29 13:44:43 +01:00
return Empty;
return user_group->GetName();
}
Value ContactGroupsTable::MembersAccessor(const Value& row)
{
2013-10-29 13:44:43 +01:00
UserGroup::Ptr user_group = static_cast<UserGroup::Ptr>(row);
2015-02-11 15:47:45 +01:00
if (!user_group)
2013-10-29 13:44:43 +01:00
return Empty;
ArrayData result;
for (const User::Ptr& user : user_group->GetMembers()) {
result.push_back(user->GetName());
}
return new Array(std::move(result));
2013-03-15 18:21:29 +01:00
}