func NewRuleSetLoadedEvent(rs *rules.RuleSet, err *multierror.Error) (*rules.Rule, *CustomEvent) {
	mp := make(map[string]*PolicyLoaded)

	var policy *PolicyLoaded
	var exists bool

	// rule successfully loaded
	for _, rule := range rs.GetRules() {
		policyName := rule.Definition.Policy.Name

		if policy, exists = mp[policyName]; !exists {
			policy = &PolicyLoaded{Version: rule.Definition.Policy.Version}
			mp[policyName] = policy
		}
		policy.RulesLoaded = append(policy.RulesLoaded, &RuleLoaded{
			ID:         rule.ID,
			Expression: rule.Definition.Expression,
		})
	}

	// rules ignored due to errors
	if err != nil && err.Errors != nil {
		for _, err := range err.Errors {
			if rerr, ok := err.(*rules.ErrRuleLoad); ok {
				policyName := rerr.Definition.Policy.Name

				if policy, exists = mp[policyName]; !exists {
					policy = &PolicyLoaded{}
					mp[policyName] = policy
				}
				policy.RulesIgnored = append(policy.RulesIgnored, &RuleIgnored{
					ID:         rerr.Definition.ID,
					Expression: rerr.Definition.Expression,
					Reason:     rerr.Err.Error(),
				})
			}
		}
	}

	var policies []*PolicyLoaded
	for _, policy := range mp {
		policies = append(policies, policy)
	}

	return newRule(&rules.RuleDefinition{
			ID: RulesetLoadedRuleID,
		}), newCustomEvent(model.CustomRulesetLoadedEventType, RulesetLoadedEvent{
			Timestamp:       time.Now(),
			PoliciesLoaded:  policies,
			PoliciesIgnored: &PoliciesIgnored{Errors: err},
			MacrosLoaded:    rs.ListMacroIDs(),
		}.MarshalJSON)
}
// NewRuleSetLoadedEvent returns the rule and a populated custom event for a new_rules_loaded event
NewRuleSetLoadedEvent returns the rule and a populated custom event for a new_rules_loaded event
// NewRuleSetLoadedEvent returns the rule and a populated custom event for a new_rules_loaded event
func NewRuleSetLoadedEvent(rs *rules.RuleSet, err *multierror.Error) (*rules.Rule, *CustomEvent) {
	mp := make(map[string]*PolicyLoaded)
	var policy *PolicyLoaded
	var exists bool
	for _, rule := range rs.GetRules() {
		policyName := rule.Definition.Policy.Name
		if policy, exists = mp[policyName]; !exists {
			policy = &PolicyLoaded{Version: rule.Definition.Policy.Version}
			mp[policyName] = policy
		}
		policy.RulesLoaded = append(policy.RulesLoaded, &RuleLoaded{
			ID:         rule.ID,
			Expression: rule.Definition.Expression,
		})
	}
	if err != nil && err.Errors != nil {
		for _, err := range err.Errors {
			if rerr, ok := err.(*rules.ErrRuleLoad); ok {
				policyName := rerr.Definition.Policy.Name
				if policy, exists = mp[policyName]; !exists {
					policy = &PolicyLoaded{}
					mp[policyName] = policy
				}
				policy.RulesIgnored = append(policy.RulesIgnored, &RuleIgnored{
					ID:         rerr.Definition.ID,
					Expression: rerr.Definition.Expression,
					Reason:     rerr.Err.Error(),
				})
			}
		}
	}
	var policies []*PolicyLoaded
	for _, policy := range mp {
		policies = append(policies, policy)
	}
	return newRule(&rules.RuleDefinition{
			ID: RulesetLoadedRuleID,
		}), newCustomEvent(model.CustomRulesetLoadedEventType, RulesetLoadedEvent{
			Timestamp:       time.Now(),
			PoliciesLoaded:  policies,
			PoliciesIgnored: &PoliciesIgnored{Errors: err},
			MacrosLoaded:    rs.ListMacroIDs(),
		}.MarshalJSON)
}
func NewRuleSetLoadedEvent ( rs * rules . RuleSet , err * multierror . Error ) ( * rules . Rule , * CustomEvent ) { mp := make ( map [ string ] * PolicyLoaded ) var policy * PolicyLoaded var exists bool for _ , rule := range rs . GetRules ( ) { policyName := rule . Definition . Policy . Name if policy , exists = mp [ policyName ] ; ! exists { policy = & PolicyLoaded { Version : rule . Definition . Policy . Version } mp [ policyName ] = policy } policy . RulesLoaded = append ( policy . RulesLoaded , & RuleLoaded { ID : rule . ID , Expression : rule . Definition . Expression , } ) } if err != nil && err . Errors != nil { for _ , err := range err . Errors { if rerr , ok := err . ( * rules . ErrRuleLoad ) ; ok { policyName := rerr . Definition . Policy . Name if policy , exists = mp [ policyName ] ; ! exists { policy = & PolicyLoaded { } mp [ policyName ] = policy } policy . RulesIgnored = append ( policy . RulesIgnored , & RuleIgnored { ID : rerr . Definition . ID , Expression : rerr . Definition . Expression , Reason : rerr . Err . Error ( ) , } ) } } } var policies [ ] * PolicyLoaded for _ , policy := range mp { policies = append ( policies , policy ) } return newRule ( & rules . RuleDefinition { ID : RulesetLoadedRuleID , } ) , newCustomEvent ( model . CustomRulesetLoadedEventType , RulesetLoadedEvent { Timestamp : time . Now ( ) , PoliciesLoaded : policies , PoliciesIgnored : & PoliciesIgnored { Errors : err } , MacrosLoaded : rs . ListMacroIDs ( ) , } . MarshalJSON ) }
NewRuleSetLoadedEvent returns the rule and a populated custom event for a new_rules_loaded event
NewRuleSetLoadedEvent returns the rule and a populated custom event for a new_rules_loaded event
// rule successfully loaded // rules ignored due to errors