@@ -32,7 +32,6 @@ import (
3232 "github.com/prometheus/common/version"
3333 "github.com/rs/cors"
3434
35- "github.com/prometheus/alertmanager/api/metrics"
3635 open_api_models "github.com/prometheus/alertmanager/api/v2/models"
3736 "github.com/prometheus/alertmanager/api/v2/restapi"
3837 "github.com/prometheus/alertmanager/api/v2/restapi/operations"
@@ -41,9 +40,12 @@ import (
4140 general_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/general"
4241 receiver_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/receiver"
4342 silence_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/silence"
43+
44+ "github.com/prometheus/alertmanager/api/metrics"
4445 "github.com/prometheus/alertmanager/cluster"
4546 "github.com/prometheus/alertmanager/config"
4647 "github.com/prometheus/alertmanager/dispatch"
48+ "github.com/prometheus/alertmanager/notify"
4749 "github.com/prometheus/alertmanager/pkg/labels"
4850 "github.com/prometheus/alertmanager/provider"
4951 "github.com/prometheus/alertmanager/silence"
@@ -71,7 +73,8 @@ type API struct {
7173 logger log.Logger
7274 m * metrics.Alerts
7375
74- Handler http.Handler
76+ Handler http.Handler
77+ receivers []* notify.Receiver
7578}
7679
7780type (
@@ -153,13 +156,14 @@ func (api *API) requestLogger(req *http.Request) log.Logger {
153156}
154157
155158// Update sets the API struct members that may change between reloads of alertmanager.
156- func (api * API ) Update (cfg * config.Config , setAlertStatus setAlertStatusFn ) {
159+ func (api * API ) Update (cfg * config.Config , setAlertStatus setAlertStatusFn , receivers [] * notify. Receiver ) {
157160 api .mtx .Lock ()
158161 defer api .mtx .Unlock ()
159162
160163 api .alertmanagerConfig = cfg
161164 api .route = dispatch .NewRoute (cfg .Route , nil )
162165 api .setAlertStatus = setAlertStatus
166+ api .receivers = receivers
163167}
164168
165169func (api * API ) getStatusHandler (params general_ops.GetStatusParams ) middleware.Responder {
@@ -220,11 +224,40 @@ func (api *API) getStatusHandler(params general_ops.GetStatusParams) middleware.
220224
221225func (api * API ) getReceiversHandler (params receiver_ops.GetReceiversParams ) middleware.Responder {
222226 api .mtx .RLock ()
223- defer api .mtx .RUnlock ()
227+ configReceivers := api .receivers
228+ api .mtx .RUnlock ()
229+
230+ receivers := make ([]* open_api_models.Receiver , 0 , len (configReceivers ))
231+ for _ , r := range configReceivers {
232+ integrations := make ([]* open_api_models.Integration , 0 , len (r .Integrations ()))
233+
234+ for _ , integration := range r .Integrations () {
235+ notify , duration , err := integration .GetReport ()
236+ iname := integration .String ()
237+ sendResolved := integration .SendResolved ()
238+ integrations = append (integrations , & open_api_models.Integration {
239+ Name : & iname ,
240+ SendResolved : & sendResolved ,
241+ LastNotifyAttempt : strfmt .DateTime (notify .UTC ()),
242+ LastNotifyAttemptDuration : duration .String (),
243+ LastNotifyAttemptError : func () string {
244+ if err != nil {
245+ return err .Error ()
246+ }
247+ return ""
248+ }(),
249+ })
250+ }
251+
252+ rName := r .Name ()
253+ active := r .Active ()
254+ model := & open_api_models.Receiver {
255+ Name : & rName ,
256+ Active : & active ,
257+ Integrations : integrations ,
258+ }
224259
225- receivers := make ([]* open_api_models.Receiver , 0 , len (api .alertmanagerConfig .Receivers ))
226- for i := range api .alertmanagerConfig .Receivers {
227- receivers = append (receivers , & open_api_models.Receiver {Name : & api .alertmanagerConfig .Receivers [i ].Name })
260+ receivers = append (receivers , model )
228261 }
229262
230263 return receiver_ops .NewGetReceiversOK ().WithPayload (receivers )
0 commit comments