mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -06:00
b76a9e4d31
* 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)
25 lines
796 B
Go
25 lines
796 B
Go
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(_ 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), nil
|
|
}
|
|
|
|
if err := json.Unmarshal(status, config); err != nil {
|
|
return apimodels.GettableStatus{}, fmt.Errorf("unable to unmarshal alertmanager config: %w", err)
|
|
}
|
|
|
|
return *apimodels.NewGettableStatus(&config.AlertmanagerConfig), nil
|
|
}
|