mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
parent
de8522f500
commit
b2f13c37e4
@ -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)
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user