From b2f13c37e41bd618c2ee51100d577ed30152d1fb Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 1 Oct 2013 15:37:50 +0200 Subject: [PATCH] compatutility: Add contact(group) getters. refs #4735 --- components/livestatus/hoststable.cpp | 37 ++------------------- components/livestatus/servicestable.cpp | 38 ++-------------------- lib/icinga/compatutility.cpp | 43 +++++++++++++++++++++++++ lib/icinga/compatutility.h | 3 ++ 4 files changed, 52 insertions(+), 69 deletions(-) diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 2ea1a990d..42df97add 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -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 allUsers; - std::set users; - Array::Ptr contacts = boost::make_shared(); - - 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 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(); - - 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) diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index e0706d1eb..89a0d0d15 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -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 allUsers; - std::set users; - Array::Ptr contacts = boost::make_shared(); - - BOOST_FOREACH(const Notification::Ptr& notification, static_cast(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 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(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(); - - BOOST_FOREACH(const Notification::Ptr& notification, static_cast(row)->GetNotifications()) { - ObjectLock olock(notification); - - BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) { - contactgroups->Add(ug->GetName()); - } - } - - return contactgroups; + return CompatUtility::GetServiceNotificationUserGroups(static_cast(row)); } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 4e59d739b..e59346e2d 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -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 allUsers; + std::set users; + Array::Ptr contacts = boost::make_shared(); + + 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 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(); + + 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) diff --git a/lib/icinga/compatutility.h b/lib/icinga/compatutility.h index ba506f1c6..0635ceff1 100644 --- a/lib/icinga/compatutility.h +++ b/lib/icinga/compatutility.h @@ -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); -- 2.40.0