本文整理汇总了C++中servicegroup::Ptr::ResolveGroupMembership方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::ResolveGroupMembership方法的具体用法?C++ Ptr::ResolveGroupMembership怎么用?C++ Ptr::ResolveGroupMembership使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类servicegroup::Ptr
的用法示例。
在下文中一共展示了Ptr::ResolveGroupMembership方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvaluateObjectRule
bool ServiceGroup::EvaluateObjectRule(const Service::Ptr service, const ObjectRule& rule)
{
DebugInfo di = rule.GetDebugInfo();
std::ostringstream msgbuf;
msgbuf << "Evaluating 'object' rule (" << di << ")";
CONTEXT(msgbuf.str());
Host::Ptr host = service->GetHost();
Dictionary::Ptr locals = make_shared<Dictionary>();
locals->Set("host", host);
locals->Set("service", service);
if (!rule.EvaluateFilter(locals))
return false;
std::ostringstream msgbuf2;
msgbuf2 << "Assigning membership for group '" << rule.GetName() << "' to service '" << service->GetName() << "' for rule " << di;
Log(LogDebug, "icinga", msgbuf2.str());
String group_name = rule.GetName();
ServiceGroup::Ptr group = ServiceGroup::GetByName(group_name);
if (!group) {
Log(LogCritical, "icinga", "Invalid membership assignment. Group '" + group_name + "' does not exist.");
return false;
}
/* assign service group membership */
group->ResolveGroupMembership(service, true);
return true;
}
示例2: ResolveGroupMembership
bool ServiceGroup::ResolveGroupMembership(const Service::Ptr& service, bool add, int rstack) {
if (add && rstack > 20) {
Log(LogWarning, "ServiceGroup")
<< "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);
for (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;
}