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
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
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
HostGroup::Ptr hg = HostGroup::GetByName(name);
if (hg)
- hg->AddMember(GetSelf());
+ hg->ResolveGroupMembership(GetSelf(), true);
}
}
}
HostGroup::Ptr hg = HostGroup::GetByName(name);
if (hg)
- hg->RemoveMember(GetSelf());
+ hg->ResolveGroupMembership(GetSelf(), false);
}
}
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;
+}
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;
return m_DisplayName;
}}}
};
+
+ [config] Array::Ptr groups;
};
}
%type HostGroup {
%attribute %string "display_name"
+
+ %attribute %array "groups" {
+ %attribute %name(HostGroup) "*"
+ },
}
%type Service %inherits Checkable {
%type ServiceGroup {
%attribute %string "display_name"
+
+ %attribute %array "groups" {
+ %attribute %name(ServiceGroup) "*"
+ },
}
%type Notification {
}
%type UserGroup {
- %attribute %string "display_name"
+ %attribute %string "display_name",
+
+ %attribute %array "groups" {
+ %attribute %name(UserGroup) "*"
+ },
}
%type TimePeriod {
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
if (sg)
- sg->AddMember(GetSelf());
+ sg->ResolveGroupMembership(GetSelf(), true);
}
}
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;
+}
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;
return m_DisplayName;
}}}
};
+
+ [config] Array::Ptr groups;
};
}
UserGroup::Ptr ug = UserGroup::GetByName(name);
if (ug)
- ug->AddMember(GetSelf());
+ ug->ResolveGroupMembership(GetSelf(), true);
}
}
}
+
void User::Stop(void)
{
DynamicObject::Stop();
UserGroup::Ptr ug = UserGroup::GetByName(name);
if (ug)
- ug->RemoveMember(GetSelf());
+ ug->ResolveGroupMembership(GetSelf(), false);
}
}
}
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;
+}
+
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;
return m_DisplayName;
}}}
};
+
+ [config] Array::Ptr groups;
};
}