mirror of https://github.com/grafana/grafana
Alerting: Implement GetStatus in the remote Alertmanager struct (#84887)
* Alerting: Implement GetStatus in the remote Alertmanager struct * update tests * fix tests, extract AlertmanagerConfig from PostableConfig * get the remote AM config instead of the Grafana one from the remote AM * pass grafana AM config in test * return error in GetStatus instead of logging it (internal AM)pull/87304/head
parent
b6f899d953
commit
b76a9e4d31
@ -1,22 +1,24 @@ |
||||
package notifier |
||||
|
||||
import ( |
||||
"context" |
||||
"encoding/json" |
||||
"fmt" |
||||
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" |
||||
) |
||||
|
||||
// TODO: We no longer do apimodels at this layer, move it to the API.
|
||||
func (am *alertmanager) GetStatus() apimodels.GettableStatus { |
||||
func (am *alertmanager) GetStatus(_ context.Context) (apimodels.GettableStatus, error) { |
||||
config := &apimodels.PostableUserConfig{} |
||||
status := am.Base.GetStatus() // TODO: This should return a GettableStatus, for now it returns PostableUserConfig.
|
||||
if status == nil { |
||||
return *apimodels.NewGettableStatus(&config.AlertmanagerConfig) |
||||
return *apimodels.NewGettableStatus(&config.AlertmanagerConfig), nil |
||||
} |
||||
|
||||
if err := json.Unmarshal(status, config); err != nil { |
||||
am.logger.Error("Unable to unmarshall alertmanager config", "Err", err) |
||||
return apimodels.GettableStatus{}, fmt.Errorf("unable to unmarshal alertmanager config: %w", err) |
||||
} |
||||
|
||||
return *apimodels.NewGettableStatus(&config.AlertmanagerConfig) |
||||
return *apimodels.NewGettableStatus(&config.AlertmanagerConfig), nil |
||||
} |
||||
|
Loading…
Reference in new issue