Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CWS] fix rule in error reported twice #15084

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pkg/security/module/policy_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,15 @@ func NewRuleSetLoadedEvent(rs *rules.RuleSet, err *multierror.Error) (*rules.Rul
var policyState *PolicyState
var exists bool

for _, policy := range rs.GetPolicies() {
// rule successfully loaded
for _, ruleDef := range policy.Rules {
policyName := ruleDef.Policy.Name

if policyState, exists = mp[policyName]; !exists {
policyState = PolicyStateFromRuleDefinition(ruleDef)
mp[policyName] = policyState
}
policyState.Rules = append(policyState.Rules, RuleStateFromDefinition(ruleDef, "loaded", ""))
for _, rule := range rs.GetRules() {
ruleDef := rule.Definition
policyName := ruleDef.Policy.Name

if policyState, exists = mp[policyName]; !exists {
policyState = PolicyStateFromRuleDefinition(ruleDef)
mp[policyName] = policyState
}
policyState.Rules = append(policyState.Rules, RuleStateFromDefinition(ruleDef, "loaded", ""))
}

// rules ignored due to errors
Expand All @@ -211,6 +209,8 @@ func NewRuleSetLoadedEvent(rs *rules.RuleSet, err *multierror.Error) (*rules.Rul
if _, exists := mp[policyName]; !exists {
policyState = PolicyStateFromRuleDefinition(rerr.Definition)
mp[policyName] = policyState
} else {
policyState = mp[policyName]
}
policyState.Rules = append(policyState.Rules, RuleStateFromDefinition(rerr.Definition, string(rerr.Type()), rerr.Err.Error()))
}
Expand Down