2016-11-03 00:59:25 +00:00
|
|
|
package kapacitor
|
|
|
|
|
2016-11-04 01:56:42 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/influxdata/chronograf"
|
|
|
|
)
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
// InfluxOut creates a kapacitor influxDBOut node to write alert data to Database, RP, Measurement.
|
|
|
|
func InfluxOut(rule chronograf.AlertRule) string {
|
2016-11-04 01:56:42 +00:00
|
|
|
// For some of the alert, the data needs to be renamed (normalized)
|
|
|
|
// before being sent to influxdb.
|
|
|
|
rename := ""
|
|
|
|
if rule.Trigger == "deadman" {
|
|
|
|
rename = `|eval(lambda: field).as('value')`
|
|
|
|
}
|
|
|
|
return fmt.Sprintf(`
|
2016-11-03 00:59:25 +00:00
|
|
|
trigger
|
2016-11-04 01:56:42 +00:00
|
|
|
%s
|
2016-11-03 00:59:25 +00:00
|
|
|
|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-04 01:56:42 +00:00
|
|
|
`, rename)
|
2016-11-03 00:59:25 +00:00
|
|
|
}
|