2016-05-27 16:02:59 +00:00
|
|
|
package pagerduty
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/influxdata/telegraf/testutil"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-08-21 08:37:56 +00:00
|
|
|
func TestPDAlert(t *testing.T) {
|
|
|
|
metric := testutil.TestMetric(2.0, "foo")
|
|
|
|
var err error
|
|
|
|
var tripped bool
|
2016-05-27 16:02:59 +00:00
|
|
|
p := PD{
|
|
|
|
Metric: "foo",
|
|
|
|
Field: "value",
|
2016-08-21 08:37:56 +00:00
|
|
|
Expression: "> 5",
|
2016-05-27 16:02:59 +00:00
|
|
|
}
|
2016-08-21 08:37:56 +00:00
|
|
|
if !p.isMatch(metric) {
|
|
|
|
t.Error("Metric should match when name is same")
|
2016-05-27 16:02:59 +00:00
|
|
|
}
|
2016-08-21 08:37:56 +00:00
|
|
|
tripped, err = p.isTripped(metric)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2016-05-27 16:02:59 +00:00
|
|
|
}
|
2016-08-21 08:37:56 +00:00
|
|
|
if tripped {
|
|
|
|
t.Error("Metric should not trigger alert when its expression evaluates to false")
|
|
|
|
}
|
|
|
|
p.Expression = "> 1"
|
|
|
|
tripped, err = p.isTripped(metric)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if !tripped {
|
|
|
|
t.Error("Metric should trigger alert when expression evaluates to true")
|
2016-05-27 16:02:59 +00:00
|
|
|
}
|
|
|
|
}
|