From ddc8a9cd7ec7b691c412de8e9f87d06cec228c30 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 5 Aug 2013 16:04:01 +0200 Subject: [PATCH] Fix missing insert IDs for service and contact groups. --- lib/ido/servicegroupdbobject.cpp | 12 ++++++++---- lib/ido/servicegroupdbobject.h | 3 ++- lib/ido/usergroupdbobject.cpp | 12 ++++++++---- lib/ido/usergroupdbobject.h | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/ido/servicegroupdbobject.cpp b/lib/ido/servicegroupdbobject.cpp index e527c264b..23ca8691a 100644 --- a/lib/ido/servicegroupdbobject.cpp +++ b/lib/ido/servicegroupdbobject.cpp @@ -20,7 +20,6 @@ #include "ido/servicegroupdbobject.h" #include "ido/dbtype.h" #include "ido/dbvalue.h" -#include "icinga/servicegroup.h" #include "base/objectlock.h" #include "base/initialize.h" #include @@ -36,7 +35,7 @@ ServiceGroupDbObject::ServiceGroupDbObject(const DbType::Ptr& type, const String void ServiceGroupDbObject::StaticInitialize(void) { - ServiceGroup::OnMembersChanged.connect(&ServiceGroupDbObject::MembersChangedHandler); + ServiceGroup::OnMembersChanged.connect(boost::bind(&ServiceGroupDbObject::MembersChangedHandler, ServiceGroup::Ptr())); } Dictionary::Ptr ServiceGroupDbObject::GetConfigFields(void) const @@ -56,10 +55,12 @@ Dictionary::Ptr ServiceGroupDbObject::GetStatusFields(void) const void ServiceGroupDbObject::OnConfigUpdate(void) { - MembersChangedHandler(); + ServiceGroup::Ptr group = static_pointer_cast(GetObject()); + + MembersChangedHandler(group); } -void ServiceGroupDbObject::MembersChangedHandler(void) +void ServiceGroupDbObject::MembersChangedHandler(const ServiceGroup::Ptr& sgfilter) { DbQuery query1; query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members"; @@ -71,6 +72,9 @@ void ServiceGroupDbObject::MembersChangedHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) { ServiceGroup::Ptr sg = static_pointer_cast(object); + if (sgfilter && sgfilter != sg) + continue; + BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { DbQuery query2; query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members"; diff --git a/lib/ido/servicegroupdbobject.h b/lib/ido/servicegroupdbobject.h index 229d6e28f..7f1cb8d9d 100644 --- a/lib/ido/servicegroupdbobject.h +++ b/lib/ido/servicegroupdbobject.h @@ -21,6 +21,7 @@ #define SERVICEGROUPDBOBJECT_H #include "ido/dbobject.h" +#include "icinga/servicegroup.h" #include "base/dynamicobject.h" namespace icinga @@ -47,7 +48,7 @@ protected: virtual void OnConfigUpdate(void); private: - static void MembersChangedHandler(void); + static void MembersChangedHandler(const ServiceGroup::Ptr& sgfilter); }; } diff --git a/lib/ido/usergroupdbobject.cpp b/lib/ido/usergroupdbobject.cpp index 39fd178b0..dabfc9809 100644 --- a/lib/ido/usergroupdbobject.cpp +++ b/lib/ido/usergroupdbobject.cpp @@ -20,7 +20,6 @@ #include "ido/usergroupdbobject.h" #include "ido/dbtype.h" #include "ido/dbvalue.h" -#include "icinga/usergroup.h" #include "base/objectlock.h" #include "base/initialize.h" #include "base/dynamictype.h" @@ -37,7 +36,7 @@ UserGroupDbObject::UserGroupDbObject(const DbType::Ptr& type, const String& name void UserGroupDbObject::StaticInitialize(void) { - UserGroup::OnMembersChanged.connect(&UserGroupDbObject::MembersChangedHandler); + UserGroup::OnMembersChanged.connect(boost::bind(&UserGroupDbObject::MembersChangedHandler, UserGroup::Ptr())); } Dictionary::Ptr UserGroupDbObject::GetConfigFields(void) const @@ -57,10 +56,12 @@ Dictionary::Ptr UserGroupDbObject::GetStatusFields(void) const void UserGroupDbObject::OnConfigUpdate(void) { - MembersChangedHandler(); + UserGroup::Ptr group = static_pointer_cast(GetObject()); + + MembersChangedHandler(group); } -void UserGroupDbObject::MembersChangedHandler(void) +void UserGroupDbObject::MembersChangedHandler(const UserGroup::Ptr& ugfilter) { DbQuery query1; query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members"; @@ -72,6 +73,9 @@ void UserGroupDbObject::MembersChangedHandler(void) BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) { UserGroup::Ptr ug = static_pointer_cast(object); + if (ugfilter && ugfilter != ug) + continue; + BOOST_FOREACH(const User::Ptr& user, ug->GetMembers()) { DbQuery query2; query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members"; diff --git a/lib/ido/usergroupdbobject.h b/lib/ido/usergroupdbobject.h index 4e5de55d1..8abcf9b88 100644 --- a/lib/ido/usergroupdbobject.h +++ b/lib/ido/usergroupdbobject.h @@ -21,6 +21,7 @@ #define USERGROUPDBOBJECT_H #include "ido/dbobject.h" +#include "icinga/usergroup.h" #include "base/dynamicobject.h" namespace icinga @@ -47,7 +48,7 @@ protected: virtual void OnConfigUpdate(void); private: - static void MembersChangedHandler(void); + static void MembersChangedHandler(const UserGroup::Ptr& ugfilter); }; }