Commit 638d3bcb by utkarshcmu

Removed NoData option

parent de0fa3d4
......@@ -19,54 +19,37 @@ func NewPagerdutyNotifier(model *m.AlertNotification) (alerting.Notifier, error)
return nil, alerting.ValidationError{Reason: "Could not find integration key property in settings"}
}
alertingStates := make([]m.AlertStateType, 0)
alertingStates = append(alertingStates, m.AlertStateAlerting)
if model.Settings.Get("alertOnExecError").MustBool() {
alertingStates = append(alertingStates, m.AlertStateExecError)
}
if model.Settings.Get("alertOnNoData").MustBool() {
alertingStates = append(alertingStates, m.AlertStateNoData)
}
return &PagerdutyNotifier{
NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings),
NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings),
Key: key,
AlertingStates: alertingStates,
AlertOnExecError: model.Settings.Get("alertOnExecError").MustBool(),
log: log.New("alerting.notifier.pagerduty"),
}, nil
}
type PagerdutyNotifier struct {
NotifierBase
Key string
AlertingStates []m.AlertStateType
log log.Logger
Key string
AlertOnExecError bool
log log.Logger
}
func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
this.log.Info("Notifying Pagerduty")
metrics.M_Alerting_Notification_Sent_PagerDuty.Inc(1)
shouldNotify := false
for _, state := range this.AlertingStates {
if evalContext.Rule.State == state {
shouldNotify = true
break
}
}
if shouldNotify {
if (evalContext.Rule.State == m.AlertStateAlerting) ||
((this.AlertOnExecError) && (evalContext.Rule.State == m.AlertStateExecError)) {
// Pagerduty Events API URL
pgEventsUrl := "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
bodyJSON := simplejson.New()
bodyJSON.Set("service_key", this.Key)
bodyJSON.Set("description", evalContext.Rule.Name + "-" + evalContext.Rule.Message)
bodyJSON.Set("description", evalContext.Rule.Name+"-"+evalContext.Rule.Message)
bodyJSON.Set("client", "Grafana")
bodyJSON.Set("event_type", "trigger")
ruleUrl, err := evalContext.GetRuleUrl()
if err != nil {
this.log.Error("Failed get rule link", "error", err)
......
......@@ -26,59 +26,10 @@ func TestPagerdutyNotifier(t *testing.T) {
So(err, ShouldNotBeNil)
})
Convey("settings with only integrationKey should contain AlertStateAlerting", func() {
json := `
{
"integrationKey": "abcdefgh0123456789"
}`
settingsJSON, _ := simplejson.NewJson([]byte(json))
model := &m.AlertNotification{
Name: "pagerduty_testing",
Type: "pagerduty",
Settings: settingsJSON,
}
not, err := NewPagerdutyNotifier(model)
pagerdutyNotifier := not.(*PagerdutyNotifier)
So(err, ShouldBeNil)
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateAlerting)
})
Convey("settings with alertOnNoData should contain AlertStateNoData too", func() {
json := `
{
"integrationKey": "abcdefgh0123456789",
"alertOnNoData": true
}`
settingsJSON, _ := simplejson.NewJson([]byte(json))
model := &m.AlertNotification{
Name: "pagerduty_testing",
Type: "pagerduty",
Settings: settingsJSON,
}
not, err := NewPagerdutyNotifier(model)
pagerdutyNotifier := not.(*PagerdutyNotifier)
So(err, ShouldBeNil)
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateNoData)
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateAlerting)
})
Convey("settings with alertOnNoData, alertOnExecError should contain both", func() {
Convey("settings with alertOnExecError should trigger incident", func() {
json := `
{
"integrationKey": "abcdefgh0123456789",
"alertOnNoData": true,
"alertOnExecError": true
}`
......@@ -96,9 +47,7 @@ func TestPagerdutyNotifier(t *testing.T) {
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateNoData)
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateAlerting)
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateExecError)
So(pagerdutyNotifier.AlertOnExecError, ShouldContain, true)
})
})
......
......@@ -106,19 +106,10 @@
<div class="gf-form">
<gf-form-switch
class="gf-form"
label="Alert on No Data"
label-class="width-12"
checked="ctrl.model.settings.alertOnNoData"
tooltip="Trigger incident on No Data">
</gf-form-switch>
</div>
<div class="gf-form">
<gf-form-switch
class="gf-form"
label="Alert on Exec Error"
label-class="width-12"
checked="ctrl.model.settings.alertOnExecError"
tooltip="Trigger incident on Execution Error">
tooltip="Trigger incident on Exec Error">
</gf-form-switch>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment