alertmanager: code style

This commit is contained in:
bergquist 2017-12-13 19:13:23 +01:00
parent 1240db31d3
commit 3691faf136
2 changed files with 7 additions and 15 deletions

View File

@ -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)
} }

View File

@ -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{