mirror of https://github.com/Icinga/icinga2.git
parent
3b2f931dcb
commit
f48a6b429b
|
@ -53,6 +53,7 @@ Attributes:
|
|||
Name |Description
|
||||
----------------|----------------
|
||||
display_name |**Optional.** A short description of the host group.
|
||||
groups |**Optional.** An array of nested group names.
|
||||
|
||||
### <a id="objecttype-service"></a> Service
|
||||
|
||||
|
@ -113,6 +114,7 @@ Attributes:
|
|||
Name |Description
|
||||
----------------|----------------
|
||||
display_name |**Optional.** A short description of the service group.
|
||||
groups |**Optional.** An array of nested group names.
|
||||
|
||||
### <a id="objecttype-notification"></a> Notification
|
||||
|
||||
|
@ -299,6 +301,7 @@ Attributes:
|
|||
Name |Description
|
||||
----------------|----------------
|
||||
display_name |**Optional.** A short description of the user group.
|
||||
groups |**Optional.** An array of nested group names.
|
||||
|
||||
### <a id="objecttype-timeperiod"></a> TimePeriod
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ void Host::OnConfigLoaded(void)
|
|||
HostGroup::Ptr hg = HostGroup::GetByName(name);
|
||||
|
||||
if (hg)
|
||||
hg->AddMember(GetSelf());
|
||||
hg->ResolveGroupMembership(GetSelf(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ void Host::Stop(void)
|
|||
HostGroup::Ptr hg = HostGroup::GetByName(name);
|
||||
|
||||
if (hg)
|
||||
hg->RemoveMember(GetSelf());
|
||||
hg->ResolveGroupMembership(GetSelf(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,3 +46,33 @@ void HostGroup::RemoveMember(const Host::Ptr& host)
|
|||
boost::mutex::scoped_lock lock(m_HostGroupMutex);
|
||||
m_Members.erase(host);
|
||||
}
|
||||
|
||||
bool HostGroup::ResolveGroupMembership(Host::Ptr const& host, bool add, int rstack) {
|
||||
|
||||
if (add && rstack > 20) {
|
||||
Log(LogWarning, "icinga", "Too many nested groups for group '" + GetName() + "': Host '" +
|
||||
host->GetName() + "' membership assignment failed.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Array::Ptr groups = GetGroups();
|
||||
|
||||
if (groups && groups->GetLength() > 0) {
|
||||
ObjectLock olock(groups);
|
||||
|
||||
BOOST_FOREACH(const String& name, groups) {
|
||||
HostGroup::Ptr group = HostGroup::GetByName(name);
|
||||
|
||||
if (group && !group->ResolveGroupMembership(host, add, rstack + 1))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (add)
|
||||
AddMember(host);
|
||||
else
|
||||
RemoveMember(host);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
void AddMember(const Host::Ptr& host);
|
||||
void RemoveMember(const Host::Ptr& host);
|
||||
|
||||
bool ResolveGroupMembership(Host::Ptr const& host, bool add = true, int rstack = 0);
|
||||
|
||||
private:
|
||||
mutable boost::mutex m_HostGroupMutex;
|
||||
std::set<Host::Ptr> m_Members;
|
||||
|
|
|
@ -13,6 +13,8 @@ class HostGroup : DynamicObject
|
|||
return m_DisplayName;
|
||||
}}}
|
||||
};
|
||||
|
||||
[config] Array::Ptr groups;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -72,6 +72,10 @@
|
|||
|
||||
%type HostGroup {
|
||||
%attribute %string "display_name"
|
||||
|
||||
%attribute %array "groups" {
|
||||
%attribute %name(HostGroup) "*"
|
||||
},
|
||||
}
|
||||
|
||||
%type Service %inherits Checkable {
|
||||
|
@ -87,6 +91,10 @@
|
|||
|
||||
%type ServiceGroup {
|
||||
%attribute %string "display_name"
|
||||
|
||||
%attribute %array "groups" {
|
||||
%attribute %name(ServiceGroup) "*"
|
||||
},
|
||||
}
|
||||
|
||||
%type Notification {
|
||||
|
@ -149,7 +157,11 @@
|
|||
}
|
||||
|
||||
%type UserGroup {
|
||||
%attribute %string "display_name"
|
||||
%attribute %string "display_name",
|
||||
|
||||
%attribute %array "groups" {
|
||||
%attribute %name(UserGroup) "*"
|
||||
},
|
||||
}
|
||||
|
||||
%type TimePeriod {
|
||||
|
|
|
@ -57,7 +57,7 @@ void Service::OnConfigLoaded(void)
|
|||
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
|
||||
|
||||
if (sg)
|
||||
sg->AddMember(GetSelf());
|
||||
sg->ResolveGroupMembership(GetSelf(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,3 +47,33 @@ void ServiceGroup::RemoveMember(const Service::Ptr& service)
|
|||
boost::mutex::scoped_lock lock(m_ServiceGroupMutex);
|
||||
m_Members.erase(service);
|
||||
}
|
||||
|
||||
bool ServiceGroup::ResolveGroupMembership(Service::Ptr const& service, bool add, int rstack) {
|
||||
|
||||
if (add && rstack > 20) {
|
||||
Log(LogWarning, "icinga", "Too many nested groups for group '" + GetName() + "': Service '" +
|
||||
service->GetName() + "' membership assignment failed.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Array::Ptr groups = GetGroups();
|
||||
|
||||
if (groups && groups->GetLength() > 0) {
|
||||
ObjectLock olock(groups);
|
||||
|
||||
BOOST_FOREACH(const String& name, groups) {
|
||||
ServiceGroup::Ptr group = ServiceGroup::GetByName(name);
|
||||
|
||||
if (group && !group->ResolveGroupMembership(service, add, rstack + 1))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (add)
|
||||
AddMember(service);
|
||||
else
|
||||
RemoveMember(service);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
void AddMember(const Service::Ptr& service);
|
||||
void RemoveMember(const Service::Ptr& service);
|
||||
|
||||
bool ResolveGroupMembership(Service::Ptr const& service, bool add = true, int rstack = 0);
|
||||
|
||||
private:
|
||||
mutable boost::mutex m_ServiceGroupMutex;
|
||||
std::set<Service::Ptr> m_Members;
|
||||
|
|
|
@ -13,6 +13,8 @@ class ServiceGroup : DynamicObject
|
|||
return m_DisplayName;
|
||||
}}}
|
||||
};
|
||||
|
||||
[config] Array::Ptr groups;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -45,11 +45,12 @@ void User::OnConfigLoaded(void)
|
|||
UserGroup::Ptr ug = UserGroup::GetByName(name);
|
||||
|
||||
if (ug)
|
||||
ug->AddMember(GetSelf());
|
||||
ug->ResolveGroupMembership(GetSelf(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void User::Stop(void)
|
||||
{
|
||||
DynamicObject::Stop();
|
||||
|
@ -63,7 +64,7 @@ void User::Stop(void)
|
|||
UserGroup::Ptr ug = UserGroup::GetByName(name);
|
||||
|
||||
if (ug)
|
||||
ug->RemoveMember(GetSelf());
|
||||
ug->ResolveGroupMembership(GetSelf(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,3 +46,34 @@ void UserGroup::RemoveMember(const User::Ptr& user)
|
|||
boost::mutex::scoped_lock lock(m_UserGroupMutex);
|
||||
m_Members.erase(user);
|
||||
}
|
||||
|
||||
bool UserGroup::ResolveGroupMembership(User::Ptr const& user, bool add, int rstack) {
|
||||
|
||||
if (add && rstack > 20) {
|
||||
Log(LogWarning, "icinga", "Too many nested groups for group '" + GetName() + "': User '" +
|
||||
user->GetName() + "' membership assignment failed.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Array::Ptr groups = GetGroups();
|
||||
|
||||
if (groups && groups->GetLength() > 0) {
|
||||
ObjectLock olock(groups);
|
||||
|
||||
BOOST_FOREACH(const String& name, groups) {
|
||||
UserGroup::Ptr group = UserGroup::GetByName(name);
|
||||
|
||||
if (group && !group->ResolveGroupMembership(user, add, rstack + 1))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (add)
|
||||
AddMember(user);
|
||||
else
|
||||
RemoveMember(user);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
void AddMember(const User::Ptr& user);
|
||||
void RemoveMember(const User::Ptr& user);
|
||||
|
||||
bool ResolveGroupMembership(User::Ptr const& user, bool add = true, int rstack = 0);
|
||||
|
||||
private:
|
||||
mutable boost::mutex m_UserGroupMutex;
|
||||
std::set<User::Ptr> m_Members;
|
||||
|
|
|
@ -13,6 +13,8 @@ class UserGroup : DynamicObject
|
|||
return m_DisplayName;
|
||||
}}}
|
||||
};
|
||||
|
||||
[config] Array::Ptr groups;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue