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; }
bool HostGroup::EvaluateObjectRuleOne(const Host::Ptr& host, const ObjectRule& rule) { DebugInfo di = rule.GetDebugInfo(); std::ostringstream msgbuf; msgbuf << "Evaluating 'object' rule (" << di << ")"; CONTEXT(msgbuf.str()); Dictionary::Ptr locals = make_shared<Dictionary>(); locals->Set("host", host); if (!rule.EvaluateFilter(locals)) return false; std::ostringstream msgbuf2; msgbuf2 << "Assigning membership for group '" << rule.GetName() << "' to host '" << host->GetName() << "' for rule " << di; Log(LogDebug, "HostGroup", msgbuf2.str()); String group_name = rule.GetName(); HostGroup::Ptr group = HostGroup::GetByName(group_name); if (!group) { Log(LogCritical, "HostGroup", "Invalid membership assignment. Group '" + group_name + "' does not exist."); return false; } /* assign host group membership */ group->ResolveGroupMembership(host, true); /* update groups attribute for apply */ host->AddGroup(group_name); return true; }
void HostGroup::EvaluateObjectRule(const ObjectRule& rule) { BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType<Host>()) { CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for host '" + host->GetName() + "'"); EvaluateObjectRuleOne(host, rule); }
void UserGroup::EvaluateObjectRule(const ObjectRule& rule) { BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) { CONTEXT("Evaluating group membership in '" + rule.GetName() + "' for user '" + user->GetName() + "'"); EvaluateObjectRuleOne(user, rule); }