コード例 #1
0
ファイル: configtype.cpp プロジェクト: CSRedRat/icinga2
void ConfigType::ValidateItem(const ConfigItem::Ptr& item)
{
	/* Don't validate abstract items. */
	if (item->IsAbstract())
		return;

	Dictionary::Ptr attrs;
	DebugInfo debugInfo;
	String type, name;

	{
		ObjectLock olock(item);

		attrs = item->GetProperties();
		debugInfo = item->GetDebugInfo();
		type = item->GetType();
		name = item->GetName();
	}

	std::vector<String> locations;
	locations.push_back("Object '" + name + "' (Type: '" + type + "') at " + debugInfo.Path + ":" + Convert::ToString(debugInfo.FirstLine));

	std::vector<TypeRuleList::Ptr> ruleLists;
	AddParentRules(ruleLists, GetSelf());
	ruleLists.push_back(m_RuleList);

	ValidateDictionary(attrs, ruleLists, locations);
}
コード例 #2
0
ファイル: servicegroup.cpp プロジェクト: LMNetworks/icinga2
bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigItem::Ptr& group)
{
	String group_name = group->GetName();

	CONTEXT("Evaluating rule for group '" + group_name + "'");

	Host::Ptr host = service->GetHost();

	ScriptFrame frame;
	if (group->GetScope())
		group->GetScope()->CopyTo(frame.Locals);
	frame.Locals->Set("host", host);
	frame.Locals->Set("service", service);

	if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool())
		return false;

	Log(LogDebug, "ServiceGroup")
	    << "Assigning membership for group '" << group_name << "' to service '" << service->GetName() << "'";

	Array::Ptr groups = service->GetGroups();
	groups->Add(group_name);

	return true;
}
コード例 #3
0
ファイル: templatequeryhandler.cpp プロジェクト: b0e/icinga2
	static Dictionary::Ptr GetTargetForTemplate(const ConfigItem::Ptr& item)
	{
		Dictionary::Ptr target = new Dictionary();
		target->Set("name", item->GetName());
		target->Set("type", item->GetType());
		return target;
	}
コード例 #4
0
ファイル: usergroup.cpp プロジェクト: TheFlyingCorpse/icinga2
bool UserGroup::EvaluateObjectRule(const User::Ptr& user, const ConfigItem::Ptr& group)
{
	String group_name = group->GetName();

	CONTEXT("Evaluating rule for group '" + group_name + "'");

	ScriptFrame frame;
	if (group->GetScope())
		group->GetScope()->CopyTo(frame.Locals);
	frame.Locals->Set("user", user);

	if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool())
		return false;

	Log(LogDebug, "UserGroup")
	    << "Assigning membership for group '" << group_name << "' to user '" << user->GetName() << "'";

	Array::Ptr groups = user->GetGroups();
	groups->Add(group_name);

	return true;
}
コード例 #5
0
ファイル: hostgroup.cpp プロジェクト: dupondje/icinga2
bool HostGroup::EvaluateObjectRule(const Host::Ptr& host, const ConfigItem::Ptr& group)
{
	String groupName = group->GetName();

	CONTEXT("Evaluating rule for group '" + groupName + "'");

	ScriptFrame frame(true);
	if (group->GetScope())
		group->GetScope()->CopyTo(frame.Locals);
	frame.Locals->Set("host", host);

	if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool())
		return false;

	Log(LogDebug, "HostGroup")
		<< "Assigning membership for group '" << groupName << "' to host '" << host->GetName() << "'";

	Array::Ptr groups = host->GetGroups();

	if (groups && !groups->Contains(groupName))
		groups->Add(groupName);

	return true;
}