2021-03-24 09:20:44 -05:00
|
|
|
package notifier
|
|
|
|
|
|
|
|
import (
|
2021-04-13 07:02:44 -05:00
|
|
|
"encoding/json"
|
2021-03-24 09:20:44 -05:00
|
|
|
"fmt"
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
alertingNotify "github.com/grafana/alerting/notify"
|
2023-04-25 12:39:46 -05:00
|
|
|
alertingTemplates "github.com/grafana/alerting/templates"
|
2023-01-12 14:03:07 -06:00
|
|
|
|
2021-04-19 13:26:04 -05:00
|
|
|
api "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
2021-03-24 09:20:44 -05:00
|
|
|
)
|
|
|
|
|
2021-04-13 07:02:44 -05:00
|
|
|
func Load(rawConfig []byte) (*api.PostableUserConfig, error) {
|
2021-03-24 09:20:44 -05:00
|
|
|
cfg := &api.PostableUserConfig{}
|
|
|
|
|
2021-04-13 07:02:44 -05:00
|
|
|
if err := json.Unmarshal(rawConfig, cfg); err != nil {
|
2021-04-22 04:18:25 -05:00
|
|
|
return nil, fmt.Errorf("unable to parse Alertmanager configuration: %w", err)
|
2021-03-24 09:20:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return cfg, nil
|
|
|
|
}
|
2023-01-12 14:03:07 -06:00
|
|
|
|
|
|
|
// AlertingConfiguration provides configuration for an Alertmanager.
|
2023-02-03 10:36:49 -06:00
|
|
|
// It implements the notify.Configuration interface.
|
2023-01-12 14:03:07 -06:00
|
|
|
type AlertingConfiguration struct {
|
2024-03-04 12:12:49 -06:00
|
|
|
route *alertingNotify.Route
|
|
|
|
inhibitRules []alertingNotify.InhibitRule
|
|
|
|
muteTimeIntervals []alertingNotify.MuteTimeInterval
|
|
|
|
timeIntervals []alertingNotify.TimeInterval
|
|
|
|
templates []alertingTemplates.TemplateDefinition
|
2023-04-28 09:56:59 -05:00
|
|
|
rawAlertmanagerConfig []byte
|
2024-03-04 12:12:49 -06:00
|
|
|
configHash [16]byte
|
2023-01-12 14:03:07 -06:00
|
|
|
|
2023-04-28 09:56:59 -05:00
|
|
|
receivers []*alertingNotify.APIReceiver
|
|
|
|
receiverIntegrationsFunc func(r *alertingNotify.APIReceiver, tmpl *alertingTemplates.Template) ([]*alertingNotify.Integration, error)
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
|
2023-04-28 09:56:59 -05:00
|
|
|
func (a AlertingConfiguration) BuildReceiverIntegrationsFunc() func(next *alertingNotify.APIReceiver, tmpl *alertingTemplates.Template) ([]*alertingNotify.Integration, error) {
|
|
|
|
return func(next *alertingNotify.APIReceiver, tmpl *alertingTemplates.Template) ([]*alertingNotify.Integration, error) {
|
|
|
|
return a.receiverIntegrationsFunc(next, tmpl)
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
func (a AlertingConfiguration) DispatcherLimits() alertingNotify.DispatcherLimits {
|
2023-01-12 14:03:07 -06:00
|
|
|
return &nilLimits{}
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
func (a AlertingConfiguration) InhibitRules() []alertingNotify.InhibitRule {
|
2024-03-04 12:12:49 -06:00
|
|
|
return a.inhibitRules
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
func (a AlertingConfiguration) MuteTimeIntervals() []alertingNotify.MuteTimeInterval {
|
2024-03-04 12:12:49 -06:00
|
|
|
return a.muteTimeIntervals
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
|
2024-02-22 10:57:20 -06:00
|
|
|
func (a AlertingConfiguration) TimeIntervals() []alertingNotify.TimeInterval {
|
2024-03-04 12:12:49 -06:00
|
|
|
return a.timeIntervals
|
2024-02-22 10:57:20 -06:00
|
|
|
}
|
|
|
|
|
2023-04-28 09:56:59 -05:00
|
|
|
func (a AlertingConfiguration) Receivers() []*alertingNotify.APIReceiver {
|
|
|
|
return a.receivers
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
func (a AlertingConfiguration) RoutingTree() *alertingNotify.Route {
|
2024-03-04 12:12:49 -06:00
|
|
|
return a.route
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
|
2024-03-04 12:12:49 -06:00
|
|
|
func (a AlertingConfiguration) Templates() []alertingTemplates.TemplateDefinition {
|
|
|
|
return a.templates
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a AlertingConfiguration) Hash() [16]byte {
|
2024-03-04 12:12:49 -06:00
|
|
|
return a.configHash
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a AlertingConfiguration) Raw() []byte {
|
2023-04-28 09:56:59 -05:00
|
|
|
return a.rawAlertmanagerConfig
|
2023-01-12 14:03:07 -06:00
|
|
|
}
|