mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +02:00
DB IDO: Fix group membership updates for runtime created objects
fixes #10604
This commit is contained in:
parent
b2364884d8
commit
0285bcefb5
@ -18,6 +18,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "db_ido/hostdbobject.hpp"
|
||||
#include "db_ido/hostgroupdbobject.hpp"
|
||||
#include "db_ido/dbtype.hpp"
|
||||
#include "db_ido/dbvalue.hpp"
|
||||
#include "db_ido/dbevents.hpp"
|
||||
@ -180,6 +181,36 @@ void HostDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
Host::Ptr host = static_pointer_cast<Host>(GetObject());
|
||||
|
||||
/* groups */
|
||||
Array::Ptr groups = host->GetGroups();
|
||||
|
||||
if (groups) {
|
||||
ObjectLock olock(groups);
|
||||
BOOST_FOREACH(const String& groupName, groups) {
|
||||
HostGroup::Ptr group = HostGroup::GetByName(groupName);
|
||||
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.Category = DbCatConfig;
|
||||
query1.WhereCriteria = new Dictionary();
|
||||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query1.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
|
||||
query1.WhereCriteria->Set("host_object_id", host);
|
||||
OnQuery(query1);
|
||||
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Category = DbCatConfig;
|
||||
query2.Fields = new Dictionary();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
|
||||
query2.Fields->Set("host_object_id", host);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
|
||||
/* parents */
|
||||
BOOST_FOREACH(const Checkable::Ptr& checkable, host->GetParents()) {
|
||||
Host::Ptr parent = dynamic_pointer_cast<Host>(checkable);
|
||||
|
@ -50,29 +50,3 @@ Dictionary::Ptr HostGroupDbObject::GetStatusFields(void) const
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
|
||||
void HostGroupDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
HostGroup::Ptr group = static_pointer_cast<HostGroup>(GetObject());
|
||||
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.Category = DbCatConfig;
|
||||
query1.WhereCriteria = new Dictionary();
|
||||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query1.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
|
||||
OnQuery(query1);
|
||||
|
||||
BOOST_FOREACH(const Host::Ptr& host, group->GetMembers()) {
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Category = DbCatConfig;
|
||||
query2.Fields = new Dictionary();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
|
||||
query2.Fields->Set("host_object_id", host);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,6 @@ public:
|
||||
virtual Dictionary::Ptr GetConfigFields(void) const override;
|
||||
virtual Dictionary::Ptr GetStatusFields(void) const override;
|
||||
|
||||
protected:
|
||||
virtual void OnConfigUpdate(void) override;
|
||||
|
||||
private:
|
||||
static void MembersChangedHandler(const HostGroup::Ptr& hgfilter);
|
||||
};
|
||||
|
@ -18,6 +18,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "db_ido/servicedbobject.hpp"
|
||||
#include "db_ido/servicegroupdbobject.hpp"
|
||||
#include "db_ido/dbtype.hpp"
|
||||
#include "db_ido/dbvalue.hpp"
|
||||
#include "db_ido/dbevents.hpp"
|
||||
@ -179,6 +180,36 @@ void ServiceDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
||||
|
||||
/* groups */
|
||||
Array::Ptr groups = service->GetGroups();
|
||||
|
||||
if (groups) {
|
||||
ObjectLock olock(groups);
|
||||
BOOST_FOREACH(const String& groupName, groups) {
|
||||
ServiceGroup::Ptr group = ServiceGroup::GetByName(groupName);
|
||||
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.Category = DbCatConfig;
|
||||
query1.WhereCriteria = new Dictionary();
|
||||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query1.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
||||
query1.WhereCriteria->Set("service_object_id", service);
|
||||
OnQuery(query1);
|
||||
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Category = DbCatConfig;
|
||||
query2.Fields = new Dictionary();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
||||
query2.Fields->Set("service_object_id", service);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
|
||||
/* service dependencies */
|
||||
Log(LogDebug, "ServiceDbObject")
|
||||
<< "service dependencies for '" << service->GetName() << "'";
|
||||
|
@ -49,29 +49,3 @@ Dictionary::Ptr ServiceGroupDbObject::GetStatusFields(void) const
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
|
||||
void ServiceGroupDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
|
||||
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.Category = DbCatConfig;
|
||||
query1.WhereCriteria = new Dictionary();
|
||||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query1.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
||||
OnQuery(query1);
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, group->GetMembers()) {
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Category = DbCatConfig;
|
||||
query2.Fields = new Dictionary();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
||||
query2.Fields->Set("service_object_id", service);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,6 @@ public:
|
||||
|
||||
virtual Dictionary::Ptr GetConfigFields(void) const override;
|
||||
virtual Dictionary::Ptr GetStatusFields(void) const override;
|
||||
|
||||
protected:
|
||||
virtual void OnConfigUpdate(void) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "db_ido/userdbobject.hpp"
|
||||
#include "db_ido/usergroupdbobject.hpp"
|
||||
#include "db_ido/dbtype.hpp"
|
||||
#include "db_ido/dbvalue.hpp"
|
||||
#include "icinga/user.hpp"
|
||||
@ -80,6 +81,36 @@ void UserDbObject::OnConfigUpdate(void)
|
||||
Dictionary::Ptr fields = new Dictionary();
|
||||
User::Ptr user = static_pointer_cast<User>(GetObject());
|
||||
|
||||
/* groups */
|
||||
Array::Ptr groups = user->GetGroups();
|
||||
|
||||
if (groups) {
|
||||
ObjectLock olock(groups);
|
||||
BOOST_FOREACH(const String& groupName, groups) {
|
||||
UserGroup::Ptr group = UserGroup::GetByName(groupName);
|
||||
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.Category = DbCatConfig;
|
||||
query1.WhereCriteria = new Dictionary();
|
||||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query1.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
|
||||
query1.WhereCriteria->Set("contact_object_id", user);
|
||||
OnQuery(query1);
|
||||
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Category = DbCatConfig;
|
||||
query2.Fields = new Dictionary();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
|
||||
query2.Fields->Set("contact_object_id", user);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
|
||||
/* contact addresses */
|
||||
Log(LogDebug, "UserDbObject")
|
||||
<< "contact addresses for '" << user->GetName() << "'";
|
||||
|
@ -47,29 +47,3 @@ Dictionary::Ptr UserGroupDbObject::GetStatusFields(void) const
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
|
||||
void UserGroupDbObject::OnConfigUpdate(void)
|
||||
{
|
||||
UserGroup::Ptr group = static_pointer_cast<UserGroup>(GetObject());
|
||||
|
||||
DbQuery query1;
|
||||
query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.Category = DbCatConfig;
|
||||
query1.WhereCriteria = new Dictionary();
|
||||
query1.WhereCriteria->Set("instance_id", 0);
|
||||
query1.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
|
||||
OnQuery(query1);
|
||||
|
||||
BOOST_FOREACH(const User::Ptr& user, group->GetMembers()) {
|
||||
DbQuery query2;
|
||||
query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
|
||||
query2.Type = DbQueryInsert;
|
||||
query2.Category = DbCatConfig;
|
||||
query2.Fields = new Dictionary();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
|
||||
query2.Fields->Set("contact_object_id", user);
|
||||
OnQuery(query2);
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,6 @@ public:
|
||||
|
||||
virtual Dictionary::Ptr GetConfigFields(void) const override;
|
||||
virtual Dictionary::Ptr GetStatusFields(void) const override;
|
||||
|
||||
protected:
|
||||
virtual void OnConfigUpdate(void) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user