@@ -7,19 +7,20 @@ import (
77
88 "github.com/go-kit/kit/log"
99 "github.com/go-kit/kit/log/level"
10+ "github.com/modern-go/reflect2"
11+
1012 "github.com/kubesphere/notification-manager/apis/v2beta2"
1113 "github.com/kubesphere/notification-manager/pkg/constants"
1214 "github.com/kubesphere/notification-manager/pkg/controller"
1315 "github.com/kubesphere/notification-manager/pkg/internal"
1416 "github.com/kubesphere/notification-manager/pkg/stage"
1517 "github.com/kubesphere/notification-manager/pkg/template"
1618 "github.com/kubesphere/notification-manager/pkg/utils"
17- "github.com/modern-go/reflect2"
1819)
1920
2021const (
21- RouterPolicyAll = "All "
22- RouterFirst = "RouterFirst "
22+ RouterFirst = "RouterFirst "
23+ RouterOnly = "RouterOnly "
2324)
2425
2526type routeStage struct {
@@ -56,9 +57,14 @@ func (s *routeStage) Exec(ctx context.Context, l log.Logger, data interface{}) (
5657 // Grouping alerts by cluster and namespace
5758 alertMap := make (map [string ][]* template.Alert )
5859 for _ , alert := range input {
59- ns := alert .Labels [constants .Namespace ]
60- cluster := alert .Labels [constants .Cluster ]
61- key := fmt .Sprintf ("%s|%s" , cluster , ns )
60+ key := ""
61+ rl := alert .Labels [constants .RuleLevel ]
62+ if rl == constants .RuleLevelNamespace {
63+ ns := alert .Labels [constants .Namespace ]
64+ cluster := alert .Labels [constants .Cluster ]
65+ key = fmt .Sprintf ("%s|%s" , cluster , ns )
66+ }
67+
6268 as := alertMap [key ]
6369 as = append (as , alert )
6470 alertMap [key ] = as
@@ -67,18 +73,19 @@ func (s *routeStage) Exec(ctx context.Context, l log.Logger, data interface{}) (
6773 m := make (map [string ]* packet )
6874 routePolicy := s .notifierCtl .GetRoutePolicy ()
6975 for key , alerts := range alertMap {
70- flag := false
71- pair := strings .Split (key , "|" )
72- cluster := pair [0 ]
73- ns := pair [1 ]
7476 var tenantRcvs []internal.Receiver
77+ if routePolicy != RouterOnly {
78+ pair := strings .Split (key , "|" )
79+ cluster := pair [0 ]
80+ ns := ""
81+ if len (pair ) > 1 {
82+ ns = pair [1 ]
83+ }
84+ tenantRcvs = s .notifierCtl .RcvsFromNs (cluster , & ns )
85+ }
7586 for _ , alert := range alerts {
7687 rcvs := s .rcvsFromRouter (alert , routers )
77- if routePolicy == RouterPolicyAll || (routePolicy == RouterFirst && len (rcvs ) == 0 ) {
78- if len (tenantRcvs ) == 0 && ! flag {
79- tenantRcvs = s .notifierCtl .RcvsFromNs (cluster , & ns )
80- flag = true
81- }
88+ if ! (routePolicy == RouterFirst && len (rcvs ) != 0 ) {
8289 rcvs = append (rcvs , tenantRcvs ... )
8390 }
8491
0 commit comments