compatutility: Add contact(group) getters.

refs #4735
This commit is contained in:
Michael Friedrich 2013-10-01 15:37:50 +02:00
parent de8522f500
commit b2f13c37e4
4 changed files with 52 additions and 69 deletions

View File

@ -25,6 +25,7 @@
#include "icinga/timeperiod.h"
#include "icinga/macroprocessor.h"
#include "icinga/icingaapplication.h"
#include "icinga/compatutility.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/convert.h"
@ -1087,28 +1088,7 @@ Value HostsTable::ContactsAccessor(const Value& row)
if (!hc)
return Empty;
std::set<User::Ptr> allUsers;
std::set<User::Ptr> users;
Array::Ptr contacts = boost::make_shared<Array>();
BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
ObjectLock olock(notification);
users = notification->GetUsers();
std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
std::set<User::Ptr> members = ug->GetMembers();
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
}
}
BOOST_FOREACH(const User::Ptr& user, allUsers) {
contacts->Add(user->GetName());
}
return contacts;
return CompatUtility::GetServiceNotificationUsers(hc);
}
Value HostsTable::DowntimesAccessor(const Value& row)
@ -1601,18 +1581,7 @@ Value HostsTable::ContactGroupsAccessor(const Value& row)
if (!hc)
return Empty;
/* XXX Service -> Notifications -> UserGroups */
Array::Ptr contactgroups = boost::make_shared<Array>();
BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
ObjectLock olock(notification);
BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
contactgroups->Add(ug->GetName());
}
}
return contactgroups;
return CompatUtility::GetServiceNotificationUserGroups(hc);
}
Value HostsTable::ServicesAccessor(const Value& row)

View File

@ -25,6 +25,7 @@
#include "icinga/timeperiod.h"
#include "icinga/macroprocessor.h"
#include "icinga/icingaapplication.h"
#include "icinga/compatutility.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/convert.h"
@ -750,29 +751,7 @@ Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
Value ServicesTable::ContactsAccessor(const Value& row)
{
/* XXX Service -> Notifications -> (Users + UserGroups -> Users) */
std::set<User::Ptr> allUsers;
std::set<User::Ptr> users;
Array::Ptr contacts = boost::make_shared<Array>();
BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
ObjectLock olock(notification);
users = notification->GetUsers();
std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
std::set<User::Ptr> members = ug->GetMembers();
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
}
}
BOOST_FOREACH(const User::Ptr& user, allUsers) {
contacts->Add(user->GetName());
}
return contacts;
return CompatUtility::GetServiceNotificationUsers(static_cast<Service::Ptr>(row));
}
Value ServicesTable::DowntimesAccessor(const Value& row)
@ -1023,18 +1002,7 @@ Value ServicesTable::GroupsAccessor(const Value& row)
Value ServicesTable::ContactGroupsAccessor(const Value& row)
{
/* XXX Service -> Notifications -> UserGroups */
Array::Ptr contactgroups = boost::make_shared<Array>();
BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
ObjectLock olock(notification);
BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
contactgroups->Add(ug->GetName());
}
}
return contactgroups;
return CompatUtility::GetServiceNotificationUserGroups(static_cast<Service::Ptr>(row));
}

View File

@ -483,6 +483,49 @@ Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr&
return customvars;
}
Value CompatUtility::GetServiceNotificationUsers(const Service::Ptr& service)
{
/* Service -> Notifications -> (Users + UserGroups -> Users) */
std::set<User::Ptr> allUsers;
std::set<User::Ptr> users;
Array::Ptr contacts = boost::make_shared<Array>();
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
ObjectLock olock(notification);
users = notification->GetUsers();
std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
std::set<User::Ptr> members = ug->GetMembers();
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
}
}
BOOST_FOREACH(const User::Ptr& user, allUsers) {
contacts->Add(user->GetName());
}
return contacts;
}
Value CompatUtility::GetServiceNotificationUserGroups(const Service::Ptr& service)
{
/* Service -> Notifications -> UserGroups */
Array::Ptr contactgroups = boost::make_shared<Array>();
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
ObjectLock olock(notification);
BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
contactgroups->Add(ug->GetName());
}
}
return contactgroups;
}
Dictionary::Ptr CompatUtility::GetCheckResultOutput(const Dictionary::Ptr& cr)
{
if (!cr)

View File

@ -56,6 +56,9 @@ public:
static Dictionary::Ptr GetCustomVariableConfig(const DynamicObject::Ptr& object);
static Value GetServiceNotificationUsers(const Service::Ptr& service);
static Value GetServiceNotificationUserGroups(const Service::Ptr& service);
static Dictionary::Ptr GetCheckResultOutput(const Dictionary::Ptr& cr);
static String GetCheckResultPerfdata(const Dictionary::Ptr& cr);