2016-11-03 00:59:25 +00:00
|
|
|
package kapacitor
|
|
|
|
|
2016-11-04 01:56:42 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-01-08 00:37:16 +00:00
|
|
|
"github.com/influxdata/influxdb/chronograf"
|
2016-11-04 01:56:42 +00:00
|
|
|
)
|
2016-11-03 00:59:25 +00:00
|
|
|
|
|
|
|
// InfluxOut creates a kapacitor influxDBOut node to write alert data to Database, RP, Measurement.
|
2016-11-04 21:28:28 +00:00
|
|
|
func InfluxOut(rule chronograf.AlertRule) (string, error) {
|
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.
|
2016-11-04 21:28:28 +00:00
|
|
|
|
2016-11-04 01:56:42 +00:00
|
|
|
rename := ""
|
|
|
|
if rule.Trigger == "deadman" {
|
2016-11-04 23:07:56 +00:00
|
|
|
rename = `|eval(lambda: "emitted")
|
|
|
|
.as('value')
|
|
|
|
.keep('value', messageField, durationField)`
|
2016-11-04 01:56:42 +00:00
|
|
|
}
|
|
|
|
return fmt.Sprintf(`
|
2016-11-03 00:59:25 +00:00
|
|
|
trigger
|
2016-11-04 01:56:42 +00:00
|
|
|
%s
|
2017-12-01 17:53:28 +00:00
|
|
|
|eval(lambda: float("value"))
|
|
|
|
.as('value')
|
|
|
|
.keep()
|
2016-11-03 00:59:25 +00:00
|
|
|
|influxDBOut()
|
2017-12-01 17:53:28 +00:00
|
|
|
.create()
|
|
|
|
.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-04 21:28:28 +00:00
|
|
|
`, rename), nil
|
2016-11-03 00:59:25 +00:00
|
|
|
}
|