2021-06-15 11:14:02 -05:00
|
|
|
package notifier
|
|
|
|
|
|
|
|
import (
|
2024-05-03 06:59:02 -05:00
|
|
|
"context"
|
2023-01-13 10:54:38 -06:00
|
|
|
"encoding/json"
|
2024-05-03 06:59:02 -05:00
|
|
|
"fmt"
|
2023-01-13 10:54:38 -06:00
|
|
|
|
2021-06-15 11:14:02 -05:00
|
|
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
|
|
|
)
|
|
|
|
|
2023-01-13 10:54:38 -06:00
|
|
|
// TODO: We no longer do apimodels at this layer, move it to the API.
|
2024-05-03 06:59:02 -05:00
|
|
|
func (am *alertmanager) GetStatus(_ context.Context) (apimodels.GettableStatus, error) {
|
2024-03-04 12:12:49 -06:00
|
|
|
config := &apimodels.PostableUserConfig{}
|
|
|
|
status := am.Base.GetStatus() // TODO: This should return a GettableStatus, for now it returns PostableUserConfig.
|
2023-01-13 10:54:38 -06:00
|
|
|
if status == nil {
|
2024-05-03 06:59:02 -05:00
|
|
|
return *apimodels.NewGettableStatus(&config.AlertmanagerConfig), nil
|
2023-01-13 10:54:38 -06:00
|
|
|
}
|
2021-06-15 11:14:02 -05:00
|
|
|
|
2023-01-13 10:54:38 -06:00
|
|
|
if err := json.Unmarshal(status, config); err != nil {
|
2024-05-03 06:59:02 -05:00
|
|
|
return apimodels.GettableStatus{}, fmt.Errorf("unable to unmarshal alertmanager config: %w", err)
|
2021-06-15 11:14:02 -05:00
|
|
|
}
|
2023-01-13 10:54:38 -06:00
|
|
|
|
2024-05-03 06:59:02 -05:00
|
|
|
return *apimodels.NewGettableStatus(&config.AlertmanagerConfig), nil
|
2021-06-15 11:14:02 -05:00
|
|
|
}
|