|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | | - "slices" |
8 | 7 | "strconv" |
9 | 8 | "sync" |
10 | 9 | "time" |
@@ -401,32 +400,27 @@ func (i *Incident) applyMatchingRules(ctx context.Context, tx *sqlx.Tx, ev *even |
401 | 400 | i.Rules = make(map[int64]struct{}) |
402 | 401 | } |
403 | 402 |
|
404 | | - sourceRulesInfo, ok := i.runtimeConfig.RulesBySource[ev.SourceId] |
405 | | - if !ok { |
406 | | - i.logger.Errorw("Event refers to non-existing source", zap.Int64("source_id", ev.SourceId)) |
407 | | - return fmt.Errorf("cannot lookup event source %d", ev.SourceId) |
408 | | - } |
409 | | - |
410 | 403 | for _, ruleId := range ev.RuleIds { |
411 | 404 | ruleIdInt, err := strconv.ParseInt(ruleId, 10, 64) |
412 | 405 | if err != nil { |
413 | 406 | i.logger.Errorw("Event rule is not an integer", zap.String("rule_id", ruleId), zap.Error(err)) |
414 | 407 | return fmt.Errorf("cannot convert rule id %q to an int: %w", ruleId, err) |
415 | 408 | } |
416 | 409 |
|
417 | | - if !slices.Contains(sourceRulesInfo.RuleIDs, ruleIdInt) { |
418 | | - i.logger.Errorw("Event rule does not belong to source", |
419 | | - zap.Int64("source_id", ev.SourceId), |
420 | | - zap.Int64("rule_id", ruleIdInt)) |
421 | | - return fmt.Errorf("event rule %d does not belong to source %d", ruleIdInt, ev.SourceId) |
422 | | - } |
423 | | - |
424 | 410 | r, ok := i.runtimeConfig.Rules[ruleIdInt] |
425 | 411 | if !ok { |
426 | 412 | i.logger.Errorw("Event refers to non-existing event rule, might got deleted", zap.Int64("rule_id", ruleIdInt)) |
427 | 413 | return fmt.Errorf("cannot apply unknown rule %d", ruleIdInt) |
428 | 414 | } |
429 | 415 |
|
| 416 | + if r.SourceID != ev.SourceId { |
| 417 | + i.logger.Errorw("Rule source ID does not match event source ID", |
| 418 | + zap.Int64("event_source_id", ev.SourceId), |
| 419 | + zap.Int64("rule_source_id", r.SourceID), |
| 420 | + zap.Int64("rule_id", ruleIdInt)) |
| 421 | + return fmt.Errorf("rule %d source ID %d does not match event source %d", ruleIdInt, r.SourceID, ev.SourceId) |
| 422 | + } |
| 423 | + |
430 | 424 | if _, ok := i.Rules[r.ID]; !ok { |
431 | 425 | i.Rules[r.ID] = struct{}{} |
432 | 426 | i.logger.Infow("Rule matches", zap.Object("rule", r)) |
|
0 commit comments