@@ -27,7 +27,7 @@ func Setup(ctx context.Context, logger log.Logger, conf *config.Config) (*Instan
27
27
"check_name" : log .String (check .Name ),
28
28
})
29
29
30
- client , err := provider .NewClient (checkLogger , cmp . Or (check .Alert , conf .Alert ))
30
+ client , err := provider .NewClient (checkLogger , mergeAlertConfigs (check .Alert , conf .Alert ))
31
31
if err != nil {
32
32
return nil , fmt .Errorf ("setting up check[%d] provider: %w" , idx , err )
33
33
}
@@ -67,7 +67,7 @@ func (xs *Instances) CheckIn(ctx context.Context, logger log.Logger, checkID str
67
67
})
68
68
69
69
// Grab the provider client for the check
70
- client , err := provider .NewClient (logger , cmp . Or (found .Alert , xs .conf .Alert ))
70
+ client , err := provider .NewClient (logger , mergeAlertConfigs (found .Alert , xs .conf .Alert ))
71
71
if err != nil {
72
72
return nil , fmt .Errorf ("problem getting client for check-in: %w" , err )
73
73
}
@@ -82,3 +82,23 @@ func (xs *Instances) CheckIn(ctx context.Context, logger log.Logger, checkID str
82
82
NextExpectedCheckIn : checkInExpected ,
83
83
}, nil
84
84
}
85
+
86
+ func mergeAlertConfigs (local , global config.Alert ) config.Alert {
87
+ var out config.Alert
88
+
89
+ // PagerDuty config merging
90
+ out .PagerDuty = cmp .Or (local .PagerDuty , global .PagerDuty )
91
+
92
+ if local .PagerDuty != nil && global .PagerDuty != nil {
93
+ // Prefer the local config over the global config
94
+ out .PagerDuty = & config.PagerDuty {
95
+ ApiKey : cmp .Or (local .PagerDuty .ApiKey , global .PagerDuty .ApiKey ),
96
+ EscalationPolicy : cmp .Or (local .PagerDuty .EscalationPolicy , global .PagerDuty .EscalationPolicy ),
97
+ From : cmp .Or (local .PagerDuty .From , global .PagerDuty .From ),
98
+ RoutingKey : cmp .Or (local .PagerDuty .RoutingKey , global .PagerDuty .RoutingKey ),
99
+ Urgency : cmp .Or (local .PagerDuty .Urgency , global .PagerDuty .Urgency ),
100
+ }
101
+ }
102
+
103
+ return out
104
+ }
0 commit comments