mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
Removed NoData option
This commit is contained in:
parent
de0fa3d479
commit
638d3bcb42
@ -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"}
|
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{
|
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,
|
Key: key,
|
||||||
AlertingStates: alertingStates,
|
AlertOnExecError: model.Settings.Get("alertOnExecError").MustBool(),
|
||||||
log: log.New("alerting.notifier.pagerduty"),
|
log: log.New("alerting.notifier.pagerduty"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type PagerdutyNotifier struct {
|
type PagerdutyNotifier struct {
|
||||||
NotifierBase
|
NotifierBase
|
||||||
Key string
|
Key string
|
||||||
AlertingStates []m.AlertStateType
|
AlertOnExecError bool
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
|
func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||||
this.log.Info("Notifying Pagerduty")
|
this.log.Info("Notifying Pagerduty")
|
||||||
metrics.M_Alerting_Notification_Sent_PagerDuty.Inc(1)
|
metrics.M_Alerting_Notification_Sent_PagerDuty.Inc(1)
|
||||||
|
|
||||||
shouldNotify := false
|
if (evalContext.Rule.State == m.AlertStateAlerting) ||
|
||||||
|
((this.AlertOnExecError) && (evalContext.Rule.State == m.AlertStateExecError)) {
|
||||||
for _, state := range this.AlertingStates {
|
|
||||||
if evalContext.Rule.State == state {
|
|
||||||
shouldNotify = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if shouldNotify {
|
|
||||||
|
|
||||||
// Pagerduty Events API URL
|
// Pagerduty Events API URL
|
||||||
pgEventsUrl := "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
|
pgEventsUrl := "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
|
||||||
|
|
||||||
bodyJSON := simplejson.New()
|
bodyJSON := simplejson.New()
|
||||||
bodyJSON.Set("service_key", this.Key)
|
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("client", "Grafana")
|
||||||
bodyJSON.Set("event_type", "trigger")
|
bodyJSON.Set("event_type", "trigger")
|
||||||
|
|
||||||
ruleUrl, err := evalContext.GetRuleUrl()
|
ruleUrl, err := evalContext.GetRuleUrl()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.log.Error("Failed get rule link", "error", err)
|
this.log.Error("Failed get rule link", "error", err)
|
||||||
|
@ -26,59 +26,10 @@ func TestPagerdutyNotifier(t *testing.T) {
|
|||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("settings with only integrationKey should contain AlertStateAlerting", func() {
|
Convey("settings with alertOnExecError should trigger incident", 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 := `
|
json := `
|
||||||
{
|
{
|
||||||
"integrationKey": "abcdefgh0123456789",
|
"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() {
|
|
||||||
json := `
|
|
||||||
{
|
|
||||||
"integrationKey": "abcdefgh0123456789",
|
|
||||||
"alertOnNoData": true,
|
|
||||||
"alertOnExecError": true
|
"alertOnExecError": true
|
||||||
}`
|
}`
|
||||||
|
|
||||||
@ -96,9 +47,7 @@ func TestPagerdutyNotifier(t *testing.T) {
|
|||||||
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
|
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
|
||||||
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
|
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
|
||||||
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
|
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
|
||||||
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateNoData)
|
So(pagerdutyNotifier.AlertOnExecError, ShouldContain, true)
|
||||||
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateAlerting)
|
|
||||||
So(pagerdutyNotifier.AlertingStates, ShouldContain, m.AlertStateExecError)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -103,22 +103,13 @@
|
|||||||
<span class="gf-form-label width-12">Integration Key</span>
|
<span class="gf-form-label width-12">Integration Key</span>
|
||||||
<input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.integrationKey" placeholder="Pagerduty integeration Key"></input>
|
<input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.integrationKey" placeholder="Pagerduty integeration Key"></input>
|
||||||
</div>
|
</div>
|
||||||
<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">
|
<div class="gf-form">
|
||||||
<gf-form-switch
|
<gf-form-switch
|
||||||
class="gf-form"
|
class="gf-form"
|
||||||
label="Alert on Exec Error"
|
label="Alert on Exec Error"
|
||||||
label-class="width-12"
|
label-class="width-12"
|
||||||
checked="ctrl.model.settings.alertOnExecError"
|
checked="ctrl.model.settings.alertOnExecError"
|
||||||
tooltip="Trigger incident on Execution Error">
|
tooltip="Trigger incident on Exec Error">
|
||||||
</gf-form-switch>
|
</gf-form-switch>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user