mirror of https://github.com/Icinga/icinga2.git
ido: Implement contactgroup members.
This commit is contained in:
parent
5d09af0a6e
commit
bd0ad338f8
|
@ -32,6 +32,7 @@ static boost::mutex l_Mutex;
|
|||
static std::map<String, std::vector<User::WeakPtr> > l_MembersCache;
|
||||
static bool l_MembersCacheNeedsUpdate = false;
|
||||
static Timer::Ptr l_MembersCacheTimer;
|
||||
boost::signals2::signal<void (void)> UserGroup::OnMembersChanged;
|
||||
|
||||
REGISTER_TYPE(UserGroup);
|
||||
|
||||
|
@ -136,6 +137,10 @@ void UserGroup::RefreshMembersCache(void)
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(l_Mutex);
|
||||
l_MembersCache.swap(newMembersCache);
|
||||
}
|
||||
|
||||
OnMembersChanged();
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
|
||||
static void InvalidateMembersCache(void);
|
||||
|
||||
static boost::signals2::signal<void (void)> OnMembersChanged;
|
||||
|
||||
protected:
|
||||
virtual void OnRegistrationCompleted(void);
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "icinga/hostgroup.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/initialize.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include "base/dynamictype.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ Dictionary::Ptr ServiceGroupDbObject::GetStatusFields(void) const
|
|||
return Empty;
|
||||
}
|
||||
|
||||
|
||||
void ServiceGroupDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
MembersChangedHandler();
|
||||
|
|
|
@ -22,11 +22,14 @@
|
|||
#include "ido/dbvalue.h"
|
||||
#include "icinga/usergroup.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/initialize.h"
|
||||
#include "base/dynamictype.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_DBTYPE(UserGroup, "contactgroup", DbObjectTypeContactGroup, "contactgroup_object_id", UserGroupDbObject);
|
||||
INITIALIZE_ONCE(UserGroupDbObject, &UserGroupDbObject::StaticInitialize);
|
||||
|
||||
UserGroupDbObject::UserGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
|
||||
: DbObject(type, name1, name2)
|
||||
|
@ -46,3 +49,33 @@ Dictionary::Ptr UserGroupDbObject::GetStatusFields(void) const
|
|||
{
|
||||
return Empty;
|
||||
}
|
||||
|
||||
void UserGroupDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
MembersChangedHandler();
|
||||
}
|
||||
|
||||
void UserGroupDbObject::MembersChangedHandler(void)
|
||||
{
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.WhereCriteria = boost::make_shared<Dictionary>();
|
||||
query1.WhereCriteria->Set("instance_id", 0);
|
||||
OnQuery(query1);
|
||||
|
||||
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
|
||||
UserGroup::Ptr ug = static_pointer_cast<UserGroup>(object);
|
||||
|
||||
BOOST_FOREACH(const User::Ptr& user, ug->GetMembers()) {
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Fields = boost::make_shared<Dictionary>();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(ug));
|
||||
query2.Fields->Set("contact_object_id", user);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,16 @@ public:
|
|||
|
||||
UserGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
|
||||
|
||||
static void StaticInitialize(void);
|
||||
|
||||
virtual Dictionary::Ptr GetConfigFields(void) const;
|
||||
virtual Dictionary::Ptr GetStatusFields(void) const;
|
||||
|
||||
protected:
|
||||
virtual void OnConfigUpdate(void);
|
||||
|
||||
private:
|
||||
static void MembersChangedHandler(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue