2016-11-03 00:59:25 +00:00
|
|
|
package kapacitor
|
|
|
|
|
|
|
|
import (
|
2016-11-04 00:44:28 +00:00
|
|
|
"encoding/json"
|
2016-11-03 19:21:17 +00:00
|
|
|
"fmt"
|
2016-11-03 00:59:25 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/influxdata/chronograf"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerate(t *testing.T) {
|
|
|
|
alert := chronograf.AlertRule{
|
2016-11-03 22:27:58 +00:00
|
|
|
Name: "name",
|
|
|
|
Trigger: "relative",
|
2016-11-04 00:44:28 +00:00
|
|
|
Alerts: []string{"slack", "victorops", "email"},
|
2016-11-03 22:27:58 +00:00
|
|
|
TriggerValues: chronograf.TriggerValues{
|
2016-11-04 00:44:28 +00:00
|
|
|
Change: "change",
|
|
|
|
Period: "10m",
|
|
|
|
Shift: "1m",
|
|
|
|
Operator: "greater than",
|
|
|
|
Value: "90",
|
2016-11-03 22:27:58 +00:00
|
|
|
},
|
|
|
|
Every: "30s",
|
2016-11-03 00:59:25 +00:00
|
|
|
Query: chronograf.QueryConfig{
|
|
|
|
Database: "telegraf",
|
|
|
|
Measurement: "cpu",
|
|
|
|
RetentionPolicy: "autogen",
|
|
|
|
Fields: []struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
Funcs []string `json:"funcs"`
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Field: "usage_user",
|
|
|
|
Funcs: []string{"mean"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Tags: map[string][]string{
|
|
|
|
"host": []string{
|
|
|
|
"acc-0eabc309-eu-west-1-data-3",
|
|
|
|
"prod",
|
|
|
|
},
|
|
|
|
"cpu": []string{
|
|
|
|
"cpu_total",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
GroupBy: struct {
|
|
|
|
Time string `json:"time"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
}{
|
|
|
|
Time: "",
|
|
|
|
Tags: []string{"host", "cluster_id"},
|
|
|
|
},
|
|
|
|
AreTagsAccepted: true,
|
|
|
|
RawText: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
gen := Alert{}
|
2016-11-03 19:21:17 +00:00
|
|
|
tick, err := gen.Generate(alert)
|
2016-11-03 00:59:25 +00:00
|
|
|
if err != nil {
|
2016-11-03 19:21:17 +00:00
|
|
|
fmt.Printf("%s", tick)
|
2016-11-03 00:59:25 +00:00
|
|
|
t.Errorf("Error generating alert: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestThreshold(t *testing.T) {
|
|
|
|
alert := chronograf.AlertRule{
|
2016-11-03 22:27:58 +00:00
|
|
|
Name: "name",
|
|
|
|
Trigger: "threshold",
|
2016-11-04 00:44:28 +00:00
|
|
|
Alerts: []string{"slack", "victorops", "email"},
|
2016-11-03 22:27:58 +00:00
|
|
|
TriggerValues: chronograf.TriggerValues{
|
2016-11-04 00:44:28 +00:00
|
|
|
Relation: "once",
|
|
|
|
Period: "10m",
|
|
|
|
Percentile: "", // TODO: if relation is not once then this will have a number
|
|
|
|
Operator: "greater than",
|
|
|
|
Value: "90",
|
2016-11-03 22:27:58 +00:00
|
|
|
},
|
|
|
|
Every: "30s",
|
|
|
|
Message: "message",
|
2016-11-03 00:59:25 +00:00
|
|
|
Query: chronograf.QueryConfig{
|
|
|
|
Database: "telegraf",
|
|
|
|
Measurement: "cpu",
|
|
|
|
RetentionPolicy: "autogen",
|
|
|
|
Fields: []struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
Funcs []string `json:"funcs"`
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Field: "usage_user",
|
|
|
|
Funcs: []string{"mean"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Tags: map[string][]string{
|
|
|
|
"host": []string{
|
|
|
|
"acc-0eabc309-eu-west-1-data-3",
|
|
|
|
"prod",
|
|
|
|
},
|
|
|
|
"cpu": []string{
|
|
|
|
"cpu_total",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
GroupBy: struct {
|
|
|
|
Time string `json:"time"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
}{
|
|
|
|
Time: "",
|
|
|
|
Tags: []string{"host", "cluster_id"},
|
|
|
|
},
|
|
|
|
AreTagsAccepted: true,
|
|
|
|
RawText: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
alert chronograf.AlertRule
|
|
|
|
want chronograf.TICKScript
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test valid template alert",
|
|
|
|
alert: alert,
|
|
|
|
want: `var db = 'telegraf'
|
|
|
|
|
|
|
|
var rp = 'autogen'
|
|
|
|
|
|
|
|
var measurement = 'cpu'
|
|
|
|
|
|
|
|
var field = 'usage_user'
|
|
|
|
|
|
|
|
var groupby = ['host', 'cluster_id']
|
|
|
|
|
2016-11-03 02:05:21 +00:00
|
|
|
var where_filter = lambda: ("cpu" == 'cpu_total') AND ("host" == 'acc-0eabc309-eu-west-1-data-3' OR "host" == 'prod')
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var every = 30s
|
|
|
|
|
|
|
|
var name = 'name'
|
|
|
|
|
|
|
|
var idVar = name + ':{{.Group}}'
|
2016-11-03 01:50:16 +00:00
|
|
|
|
|
|
|
var message = 'message'
|
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var idtag = 'alertID'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var leveltag = 'level'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var messagefield = 'message'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var durationfield = 'duration'
|
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var value = 'value'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
var output_db = 'chronograf'
|
|
|
|
|
|
|
|
var output_rp = 'autogen'
|
|
|
|
|
|
|
|
var output_mt = 'alerts'
|
|
|
|
|
2016-11-03 19:21:17 +00:00
|
|
|
var triggerType = 'threshold'
|
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var period = 10m
|
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var crit = 90
|
|
|
|
|
2016-11-03 00:59:25 +00:00
|
|
|
var data = stream
|
|
|
|
|from()
|
|
|
|
.database(db)
|
|
|
|
.retentionPolicy(rp)
|
|
|
|
.measurement(measurement)
|
|
|
|
.groupBy(groupby)
|
2016-11-03 18:41:34 +00:00
|
|
|
.where(where_filter)
|
2016-11-03 00:59:25 +00:00
|
|
|
|window()
|
|
|
|
.period(period)
|
|
|
|
.every(every)
|
|
|
|
.align()
|
|
|
|
|mean(field)
|
2016-11-03 22:27:58 +00:00
|
|
|
.as(value)
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
var trigger = data
|
|
|
|
|alert()
|
|
|
|
.stateChangesOnly()
|
|
|
|
.crit(lambda: "value" > crit)
|
2016-11-03 18:41:34 +00:00
|
|
|
.message(message)
|
|
|
|
.id(idVar)
|
|
|
|
.idTag(idtag)
|
2016-11-03 22:27:58 +00:00
|
|
|
.levelTag(leveltag)
|
2016-11-03 18:41:34 +00:00
|
|
|
.messageField(messagefield)
|
|
|
|
.durationField(durationfield)
|
2016-11-03 00:59:25 +00:00
|
|
|
.slack()
|
|
|
|
.victorOps()
|
|
|
|
.email()
|
|
|
|
|
|
|
|
trigger
|
|
|
|
|influxDBOut()
|
|
|
|
.create()
|
|
|
|
.database(output_db)
|
|
|
|
.retentionPolicy(output_rp)
|
|
|
|
.measurement(output_mt)
|
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
|
|
|
`,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
gen := Alert{}
|
|
|
|
got, err := gen.Generate(tt.alert)
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("%q. Threshold() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if got != tt.want {
|
2016-11-03 22:27:58 +00:00
|
|
|
fmt.Printf("%s", got)
|
2016-11-03 00:59:25 +00:00
|
|
|
t.Errorf("%q. Threshold() = %v, want %v", tt.name, got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRelative(t *testing.T) {
|
|
|
|
alert := chronograf.AlertRule{
|
2016-11-03 22:27:58 +00:00
|
|
|
Name: "name",
|
|
|
|
Trigger: "relative",
|
2016-11-04 00:44:28 +00:00
|
|
|
Alerts: []string{"slack", "victorops", "email"},
|
2016-11-03 22:27:58 +00:00
|
|
|
TriggerValues: chronograf.TriggerValues{
|
2016-11-04 00:44:28 +00:00
|
|
|
Change: "change",
|
|
|
|
Period: "10m",
|
|
|
|
Shift: "1m",
|
|
|
|
Operator: "greater than",
|
|
|
|
Value: "90",
|
2016-11-03 22:27:58 +00:00
|
|
|
},
|
|
|
|
Every: "30s",
|
|
|
|
Message: "message",
|
2016-11-03 00:59:25 +00:00
|
|
|
Query: chronograf.QueryConfig{
|
|
|
|
Database: "telegraf",
|
|
|
|
Measurement: "cpu",
|
|
|
|
RetentionPolicy: "autogen",
|
|
|
|
Fields: []struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
Funcs []string `json:"funcs"`
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Field: "usage_user",
|
|
|
|
Funcs: []string{"mean"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Tags: map[string][]string{
|
|
|
|
"host": []string{
|
|
|
|
"acc-0eabc309-eu-west-1-data-3",
|
|
|
|
"prod",
|
|
|
|
},
|
|
|
|
"cpu": []string{
|
|
|
|
"cpu_total",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
GroupBy: struct {
|
|
|
|
Time string `json:"time"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
}{
|
|
|
|
Time: "",
|
|
|
|
Tags: []string{"host", "cluster_id"},
|
|
|
|
},
|
|
|
|
AreTagsAccepted: true,
|
|
|
|
RawText: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
alert chronograf.AlertRule
|
|
|
|
want chronograf.TICKScript
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test valid template alert",
|
|
|
|
alert: alert,
|
|
|
|
want: `var db = 'telegraf'
|
|
|
|
|
|
|
|
var rp = 'autogen'
|
|
|
|
|
|
|
|
var measurement = 'cpu'
|
|
|
|
|
|
|
|
var field = 'usage_user'
|
|
|
|
|
|
|
|
var groupby = ['host', 'cluster_id']
|
|
|
|
|
2016-11-03 02:05:21 +00:00
|
|
|
var where_filter = lambda: ("cpu" == 'cpu_total') AND ("host" == 'acc-0eabc309-eu-west-1-data-3' OR "host" == 'prod')
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var every = 30s
|
|
|
|
|
|
|
|
var name = 'name'
|
|
|
|
|
|
|
|
var idVar = name + ':{{.Group}}'
|
2016-11-03 01:50:16 +00:00
|
|
|
|
|
|
|
var message = 'message'
|
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var idtag = 'alertID'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var leveltag = 'level'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var messagefield = 'message'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var durationfield = 'duration'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var value = 'value'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
var output_db = 'chronograf'
|
|
|
|
|
|
|
|
var output_rp = 'autogen'
|
|
|
|
|
|
|
|
var output_mt = 'alerts'
|
|
|
|
|
2016-11-03 19:21:17 +00:00
|
|
|
var triggerType = 'relative'
|
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var period = 10m
|
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var shift = -1m
|
|
|
|
|
|
|
|
var crit = 90
|
|
|
|
|
2016-11-03 00:59:25 +00:00
|
|
|
var data = stream
|
|
|
|
|from()
|
|
|
|
.database(db)
|
|
|
|
.retentionPolicy(rp)
|
|
|
|
.measurement(measurement)
|
|
|
|
.groupBy(groupby)
|
2016-11-03 18:41:34 +00:00
|
|
|
.where(where_filter)
|
2016-11-03 00:59:25 +00:00
|
|
|
|window()
|
|
|
|
.period(period)
|
|
|
|
.every(every)
|
|
|
|
.align()
|
|
|
|
|mean(field)
|
2016-11-03 22:27:58 +00:00
|
|
|
.as(value)
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
var past = data
|
|
|
|
|shift(shift)
|
|
|
|
|
|
|
|
var current = data
|
|
|
|
|
|
|
|
var trigger = past
|
|
|
|
|join(current)
|
|
|
|
.as('past', 'current')
|
2016-11-03 22:27:58 +00:00
|
|
|
|eval(lambda: abs(float("current.value" - "past.value")) / float("past.value"))
|
2016-11-03 00:59:25 +00:00
|
|
|
.keep()
|
|
|
|
.as('value')
|
|
|
|
|alert()
|
|
|
|
.stateChangesOnly()
|
|
|
|
.crit(lambda: "value" > crit)
|
2016-11-03 18:41:34 +00:00
|
|
|
.message(message)
|
|
|
|
.id(idVar)
|
|
|
|
.idTag(idtag)
|
2016-11-03 22:27:58 +00:00
|
|
|
.levelTag(leveltag)
|
2016-11-03 18:41:34 +00:00
|
|
|
.messageField(messagefield)
|
|
|
|
.durationField(durationfield)
|
2016-11-03 00:59:25 +00:00
|
|
|
.slack()
|
|
|
|
.victorOps()
|
|
|
|
.email()
|
|
|
|
|
|
|
|
trigger
|
|
|
|
|influxDBOut()
|
|
|
|
.create()
|
|
|
|
.database(output_db)
|
|
|
|
.retentionPolicy(output_rp)
|
|
|
|
.measurement(output_mt)
|
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
|
|
|
`,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
gen := Alert{}
|
|
|
|
got, err := gen.Generate(tt.alert)
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("%q. Relative() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if got != tt.want {
|
2016-11-03 22:27:58 +00:00
|
|
|
fmt.Printf("%s", got)
|
2016-11-03 00:59:25 +00:00
|
|
|
t.Errorf("%q. Relative() = %v, want %v", tt.name, got, tt.want)
|
|
|
|
}
|
2016-11-04 00:44:28 +00:00
|
|
|
b, _ := json.Marshal(tt.alert)
|
|
|
|
fmt.Printf("%s", string(b))
|
2016-11-03 00:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeadman(t *testing.T) {
|
|
|
|
alert := chronograf.AlertRule{
|
2016-11-03 22:27:58 +00:00
|
|
|
Name: "name",
|
|
|
|
Trigger: "deadman",
|
2016-11-04 00:44:28 +00:00
|
|
|
Alerts: []string{"slack", "victorops", "email"},
|
2016-11-03 22:27:58 +00:00
|
|
|
TriggerValues: chronograf.TriggerValues{
|
2016-11-04 00:44:28 +00:00
|
|
|
Period: "10m",
|
2016-11-03 22:27:58 +00:00
|
|
|
},
|
|
|
|
Every: "30s",
|
|
|
|
Message: "message",
|
2016-11-03 00:59:25 +00:00
|
|
|
Query: chronograf.QueryConfig{
|
|
|
|
Database: "telegraf",
|
|
|
|
Measurement: "cpu",
|
|
|
|
RetentionPolicy: "autogen",
|
|
|
|
Fields: []struct {
|
|
|
|
Field string `json:"field"`
|
|
|
|
Funcs []string `json:"funcs"`
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Field: "usage_user",
|
|
|
|
Funcs: []string{"mean"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Tags: map[string][]string{
|
|
|
|
"host": []string{
|
|
|
|
"acc-0eabc309-eu-west-1-data-3",
|
|
|
|
"prod",
|
|
|
|
},
|
|
|
|
"cpu": []string{
|
|
|
|
"cpu_total",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
GroupBy: struct {
|
|
|
|
Time string `json:"time"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
}{
|
|
|
|
Time: "",
|
|
|
|
Tags: []string{"host", "cluster_id"},
|
|
|
|
},
|
|
|
|
AreTagsAccepted: true,
|
|
|
|
RawText: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
alert chronograf.AlertRule
|
|
|
|
want chronograf.TICKScript
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test valid template alert",
|
|
|
|
alert: alert,
|
|
|
|
want: `var db = 'telegraf'
|
|
|
|
|
|
|
|
var rp = 'autogen'
|
|
|
|
|
|
|
|
var measurement = 'cpu'
|
|
|
|
|
|
|
|
var field = 'usage_user'
|
|
|
|
|
|
|
|
var groupby = ['host', 'cluster_id']
|
|
|
|
|
2016-11-03 02:05:21 +00:00
|
|
|
var where_filter = lambda: ("cpu" == 'cpu_total') AND ("host" == 'acc-0eabc309-eu-west-1-data-3' OR "host" == 'prod')
|
2016-11-03 01:50:16 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var every = 30s
|
|
|
|
|
|
|
|
var name = 'name'
|
|
|
|
|
|
|
|
var idVar = name + ':{{.Group}}'
|
2016-11-03 01:50:16 +00:00
|
|
|
|
|
|
|
var message = 'message'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var idtag = 'alertID'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var leveltag = 'level'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var messagefield = 'message'
|
2016-11-03 01:50:16 +00:00
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var durationfield = 'duration'
|
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var value = 'value'
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
var output_db = 'chronograf'
|
|
|
|
|
|
|
|
var output_rp = 'autogen'
|
|
|
|
|
|
|
|
var output_mt = 'alerts'
|
|
|
|
|
2016-11-03 19:21:17 +00:00
|
|
|
var triggerType = 'deadman'
|
|
|
|
|
2016-11-03 18:41:34 +00:00
|
|
|
var threshold = 0.0
|
|
|
|
|
2016-11-03 22:27:58 +00:00
|
|
|
var period = 10m
|
|
|
|
|
2016-11-03 00:59:25 +00:00
|
|
|
var data = stream
|
|
|
|
|from()
|
|
|
|
.database(db)
|
|
|
|
.retentionPolicy(rp)
|
|
|
|
.measurement(measurement)
|
|
|
|
.groupBy(groupby)
|
2016-11-03 18:41:34 +00:00
|
|
|
.where(where_filter)
|
2016-11-03 22:27:58 +00:00
|
|
|
|eval(lambda: field)
|
|
|
|
.as(value)
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
var trigger = data
|
2016-11-03 18:41:34 +00:00
|
|
|
|deadman(threshold, every)
|
2016-11-03 00:59:25 +00:00
|
|
|
.stateChangesOnly()
|
|
|
|
.message(message)
|
2016-11-03 18:41:34 +00:00
|
|
|
.id(idVar)
|
|
|
|
.idTag(idtag)
|
2016-11-03 22:27:58 +00:00
|
|
|
.levelTag(leveltag)
|
2016-11-03 18:41:34 +00:00
|
|
|
.messageField(messagefield)
|
|
|
|
.durationField(durationfield)
|
2016-11-03 00:59:25 +00:00
|
|
|
.slack()
|
|
|
|
.victorOps()
|
|
|
|
.email()
|
|
|
|
|
|
|
|
trigger
|
|
|
|
|influxDBOut()
|
|
|
|
.create()
|
|
|
|
.database(output_db)
|
|
|
|
.retentionPolicy(output_rp)
|
|
|
|
.measurement(output_mt)
|
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
|
|
|
`,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
gen := Alert{}
|
|
|
|
got, err := gen.Generate(tt.alert)
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("%q. Deadman() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if got != tt.want {
|
2016-11-03 22:27:58 +00:00
|
|
|
fmt.Printf("%s", got)
|
2016-11-03 00:59:25 +00:00
|
|
|
t.Errorf("%q. Deadman() = %v, want %v", tt.name, got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|