2023-11-02 11:53:18 -05:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RemoteSecondaryForkedAlertmanager struct {
|
|
|
|
internal notifier.Alertmanager
|
|
|
|
remote notifier.Alertmanager
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRemoteSecondaryForkedAlertmanager(internal, remote notifier.Alertmanager) *RemoteSecondaryForkedAlertmanager {
|
|
|
|
return &RemoteSecondaryForkedAlertmanager{
|
|
|
|
internal: internal,
|
|
|
|
remote: remote,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) ApplyConfig(ctx context.Context, config *models.AlertConfiguration) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) SaveAndApplyConfig(ctx context.Context, config *apimodels.PostableUserConfig) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) SaveAndApplyDefaultConfig(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) GetStatus() apimodels.GettableStatus {
|
2023-11-14 04:17:17 -06:00
|
|
|
return fam.internal.GetStatus()
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) CreateSilence(ctx context.Context, silence *apimodels.PostableSilence) (string, error) {
|
2023-11-08 05:03:40 -06:00
|
|
|
return fam.internal.CreateSilence(ctx, silence)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) DeleteSilence(ctx context.Context, id string) error {
|
2023-11-08 05:03:40 -06:00
|
|
|
return fam.internal.DeleteSilence(ctx, id)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) GetSilence(ctx context.Context, id string) (apimodels.GettableSilence, error) {
|
2023-11-08 05:03:40 -06:00
|
|
|
return fam.internal.GetSilence(ctx, id)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) ListSilences(ctx context.Context, filter []string) (apimodels.GettableSilences, error) {
|
2023-11-08 05:03:40 -06:00
|
|
|
return fam.internal.ListSilences(ctx, filter)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) GetAlerts(ctx context.Context, active, silenced, inhibited bool, filter []string, receiver string) (apimodels.GettableAlerts, error) {
|
2023-11-08 06:52:04 -06:00
|
|
|
return fam.internal.GetAlerts(ctx, active, silenced, inhibited, filter, receiver)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) GetAlertGroups(ctx context.Context, active, silenced, inhibited bool, filter []string, receiver string) (apimodels.AlertGroups, error) {
|
2023-11-08 06:52:04 -06:00
|
|
|
return fam.internal.GetAlertGroups(ctx, active, silenced, inhibited, filter, receiver)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) PutAlerts(ctx context.Context, alerts apimodels.PostableAlerts) error {
|
2023-11-08 06:52:04 -06:00
|
|
|
return fam.internal.PutAlerts(ctx, alerts)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) GetReceivers(ctx context.Context) ([]apimodels.Receiver, error) {
|
2023-11-09 04:38:16 -06:00
|
|
|
return fam.internal.GetReceivers(ctx)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error) {
|
2023-11-09 04:38:16 -06:00
|
|
|
return fam.internal.TestReceivers(ctx, c)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) TestTemplate(ctx context.Context, c apimodels.TestTemplatesConfigBodyParams) (*notifier.TestTemplatesResults, error) {
|
2023-11-09 05:35:24 -06:00
|
|
|
return fam.internal.TestTemplate(ctx, c)
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|
|
|
|
|
2023-11-14 04:17:17 -06:00
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) CleanUp() {
|
|
|
|
// No cleanup to do in the remote Alertmanager.
|
|
|
|
fam.internal.CleanUp()
|
|
|
|
}
|
2023-11-02 11:53:18 -05:00
|
|
|
|
2023-11-14 04:17:17 -06:00
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) StopAndWait() {
|
|
|
|
fam.internal.StopAndWait()
|
|
|
|
fam.remote.StopAndWait()
|
|
|
|
}
|
2023-11-02 11:53:18 -05:00
|
|
|
|
|
|
|
func (fam *RemoteSecondaryForkedAlertmanager) Ready() bool {
|
2023-11-14 04:17:17 -06:00
|
|
|
// Both Alertmanagers must be ready.
|
|
|
|
if ready := fam.remote.Ready(); !ready {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return fam.internal.Ready()
|
2023-11-02 11:53:18 -05:00
|
|
|
}
|