2016-11-03 00:59:25 +00:00
|
|
|
package kapacitor
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
import "github.com/influxdata/chronograf"
|
|
|
|
|
|
|
|
func TestInfluxOut(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
want chronograf.TICKScript
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test influxDBOut kapacitor node",
|
|
|
|
want: `trigger
|
2016-11-04 23:07:56 +00:00
|
|
|
|eval(lambda: "emitted")
|
2016-11-04 01:56:42 +00:00
|
|
|
.as('value')
|
2016-11-04 23:07:56 +00:00
|
|
|
.keep('value', messageField, durationField)
|
2017-12-01 17:53:28 +00:00
|
|
|
|eval(lambda: float("value"))
|
|
|
|
.as('value')
|
|
|
|
.keep()
|
2016-11-03 00:59:25 +00:00
|
|
|
|influxDBOut()
|
|
|
|
.create()
|
2016-11-04 23:07:56 +00:00
|
|
|
.database(outputDB)
|
|
|
|
.retentionPolicy(outputRP)
|
|
|
|
.measurement(outputMeasurement)
|
2016-11-03 22:27:58 +00:00
|
|
|
.tag('alertName', name)
|
2016-11-03 19:21:17 +00:00
|
|
|
.tag('triggerType', triggerType)
|
2016-11-03 00:59:25 +00:00
|
|
|
`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2016-11-04 21:28:28 +00:00
|
|
|
got, err := InfluxOut(chronograf.AlertRule{
|
2016-11-03 22:27:58 +00:00
|
|
|
Name: "name",
|
|
|
|
Trigger: "deadman",
|
2017-05-05 19:30:20 +00:00
|
|
|
Query: &chronograf.QueryConfig{
|
2016-11-10 17:27:42 +00:00
|
|
|
Fields: []chronograf.Field{
|
2016-11-04 21:28:28 +00:00
|
|
|
{
|
2017-10-16 15:56:12 +00:00
|
|
|
Value: "mean",
|
|
|
|
Type: "func",
|
2017-10-10 23:04:45 +00:00
|
|
|
Args: []chronograf.Field{
|
|
|
|
{
|
2017-10-16 15:56:12 +00:00
|
|
|
Value: "usage_user",
|
|
|
|
Type: "field",
|
2017-10-10 23:04:45 +00:00
|
|
|
},
|
|
|
|
},
|
2016-11-04 21:28:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-11-03 18:41:34 +00:00
|
|
|
})
|
2016-11-04 21:28:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%q. InfluxOut()) error = %v", tt.name, err)
|
|
|
|
continue
|
|
|
|
}
|
2016-11-03 00:59:25 +00:00
|
|
|
formatted, err := formatTick(got)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%q. formatTick() error = %v", tt.name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if formatted != tt.want {
|
|
|
|
t.Errorf("%q. InfluxOut() = %v, want %v", tt.name, formatted, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|