mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
alertmanager: code style
This commit is contained in:
parent
1240db31d3
commit
3691faf136
@ -12,9 +12,9 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
alerting.RegisterNotifier(&alerting.NotifierPlugin{
|
alerting.RegisterNotifier(&alerting.NotifierPlugin{
|
||||||
Type: "alertmanager",
|
Type: "prometheus-alertmanager",
|
||||||
Name: "alertmanager",
|
Name: "Prometheus Alertmanager",
|
||||||
Description: "Sends alert to Alertmanager",
|
Description: "Sends alert to Prometheus Alertmanager",
|
||||||
Factory: NewAlertmanagerNotifier,
|
Factory: NewAlertmanagerNotifier,
|
||||||
OptionsTemplate: `
|
OptionsTemplate: `
|
||||||
<h3 class="page-heading">Alertmanager settings</h3>
|
<h3 class="page-heading">Alertmanager settings</h3>
|
||||||
@ -35,7 +35,7 @@ func NewAlertmanagerNotifier(model *m.AlertNotification) (alerting.Notifier, err
|
|||||||
return &AlertmanagerNotifier{
|
return &AlertmanagerNotifier{
|
||||||
NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings),
|
NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings),
|
||||||
Url: url,
|
Url: url,
|
||||||
log: log.New("alerting.notifier.alertmanager"),
|
log: log.New("alerting.notifier.prometheus-alertmanager"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,14 +46,10 @@ type AlertmanagerNotifier struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *AlertmanagerNotifier) ShouldNotify(evalContext *alerting.EvalContext) bool {
|
func (this *AlertmanagerNotifier) ShouldNotify(evalContext *alerting.EvalContext) bool {
|
||||||
if evalContext.Rule.State == m.AlertStateAlerting {
|
return evalContext.Rule.State == m.AlertStateAlerting
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error {
|
func (this *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||||
this.log.Info("Sending alertmanager")
|
|
||||||
|
|
||||||
alerts := make([]interface{}, 0)
|
alerts := make([]interface{}, 0)
|
||||||
for _, match := range evalContext.EvalMatches {
|
for _, match := range evalContext.EvalMatches {
|
||||||
@ -62,8 +58,7 @@ func (this *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) erro
|
|||||||
// Rule state should always be alerting if notifying.
|
// Rule state should always be alerting if notifying.
|
||||||
alertJSON.Set("endsAt", "0001-01-01T00:00:00Z")
|
alertJSON.Set("endsAt", "0001-01-01T00:00:00Z")
|
||||||
|
|
||||||
ruleUrl, err := evalContext.GetRuleUrl()
|
if ruleUrl, err := evalContext.GetRuleUrl(); err == nil {
|
||||||
if err == nil {
|
|
||||||
alertJSON.Set("generatorURL", ruleUrl)
|
alertJSON.Set("generatorURL", ruleUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,10 +27,7 @@ func TestAlertmanagerNotifier(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("from settings", func() {
|
Convey("from settings", func() {
|
||||||
json := `
|
json := `{ "url": "http://127.0.0.1:9093/" }`
|
||||||
{
|
|
||||||
"url": "http://127.0.0.1:9093/"
|
|
||||||
}`
|
|
||||||
|
|
||||||
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
||||||
model := &m.AlertNotification{
|
model := &m.AlertNotification{
|
||||||
|
Loading…
Reference in New Issue
Block a user