feat(alerting): refactoring

This commit is contained in:
Torkel Ödegaard
2016-07-27 17:07:44 +02:00
parent 6aaf4c97a2
commit 717cce014b
24 changed files with 214 additions and 523 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/grafana/grafana/pkg/setting"
)
func getRuleLink(rule *alerting.AlertRule) (string, error) {
func getRuleLink(rule *alerting.Rule) (string, error) {
slugQuery := &m.GetDashboardSlugByIdQuery{Id: rule.DashboardId}
if err := bus.Dispatch(slugQuery); err != nil {
return "", err
+2 -2
View File
@@ -23,7 +23,7 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
addressesString := model.Settings.Get("addresses").MustString()
if addressesString == "" {
return nil, alerting.AlertValidationError{Reason: "Could not find addresses in settings"}
return nil, alerting.ValidationError{Reason: "Could not find addresses in settings"}
}
return &EmailNotifier{
@@ -36,7 +36,7 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}, nil
}
func (this *EmailNotifier) Notify(context *alerting.AlertResultContext) {
func (this *EmailNotifier) Notify(context *alerting.EvalContext) {
this.log.Info("Sending alert notification to", "addresses", this.Addresses)
ruleLink, err := getRuleLink(context.Rule)
+2 -2
View File
@@ -17,7 +17,7 @@ func init() {
func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
url := model.Settings.Get("url").MustString()
if url == "" {
return nil, alerting.AlertValidationError{Reason: "Could not find url property in settings"}
return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
}
return &SlackNotifier{
@@ -36,7 +36,7 @@ type SlackNotifier struct {
log log.Logger
}
func (this *SlackNotifier) Notify(context *alerting.AlertResultContext) {
func (this *SlackNotifier) Notify(context *alerting.EvalContext) {
this.log.Info("Executing slack notification", "ruleId", context.Rule.Id, "notification", this.Name)
rule := context.Rule
+2 -2
View File
@@ -15,7 +15,7 @@ func init() {
func NewWebHookNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
url := model.Settings.Get("url").MustString()
if url == "" {
return nil, alerting.AlertValidationError{Reason: "Could not find url property in settings"}
return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
}
return &WebhookNotifier{
@@ -38,7 +38,7 @@ type WebhookNotifier struct {
log log.Logger
}
func (this *WebhookNotifier) Notify(context *alerting.AlertResultContext) {
func (this *WebhookNotifier) Notify(context *alerting.EvalContext) {
this.log.Info("Sending webhook")
bodyJSON := simplejson.New()