]> granicus.if.org Git - icinga2/commitdiff
compatutility: Add contact(group) getters.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 13:37:50 +0000 (15:37 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 13:39:00 +0000 (15:39 +0200)
refs #4735

components/livestatus/hoststable.cpp
components/livestatus/servicestable.cpp
lib/icinga/compatutility.cpp
lib/icinga/compatutility.h

index 2ea1a990dfdd14271e44ce3963ad64625747768b..42df97add6e9fc9087c12c855db1e82bf0bd1d4a 100644 (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)
index e0706d1eb2ecd97e41b1198183fb73b7b0883b7d..89a0d0d15c0859616286f2e6276efc7d316ae589 100644 (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));
 }
 
 
index 4e59d739ba2ac44cce282a9313c1599aef5bba5a..e59346e2d6ce0ca08b559da9f556a64c2a8f4d5a 100644 (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)
index ba506f1c6648f2660e529255fb5a38fa7e4c515d..0635ceff13a52f7429921869df75f52d0411980d 100644 (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);