2019-07-23 22:35:19 +00:00
|
|
|
package notification
|
|
|
|
|
|
|
|
import (
|
2019-08-19 11:31:46 +00:00
|
|
|
"github.com/influxdata/flux/ast"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
"github.com/influxdata/influxdb/v2/notification/flux"
|
2019-07-23 22:35:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TagRule is the struct of tag rule.
|
2019-09-23 16:00:03 +00:00
|
|
|
type TagRule influxdb.TagRule
|
|
|
|
|
|
|
|
// Valid returns error for invalid operators.
|
|
|
|
func (tr TagRule) Valid() error {
|
|
|
|
return influxdb.TagRule(tr).Valid()
|
2019-07-23 22:35:19 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 11:31:46 +00:00
|
|
|
// GenerateFluxAST generates the AST expression for a tag rule.
|
2019-08-28 16:25:54 +00:00
|
|
|
func (tr TagRule) GenerateFluxAST() ast.Expression {
|
|
|
|
k := flux.Member("r", tr.Key)
|
|
|
|
v := flux.String(tr.Value)
|
2019-08-19 11:31:46 +00:00
|
|
|
|
2019-08-28 16:25:54 +00:00
|
|
|
switch tr.Operator {
|
2019-09-23 16:00:03 +00:00
|
|
|
case influxdb.Equal:
|
2019-08-19 11:31:46 +00:00
|
|
|
return flux.Equal(k, v)
|
|
|
|
// TODO(desa): have this work for all operator types
|
|
|
|
}
|
|
|
|
|
|
|
|
return flux.Equal(k, v)
|
|
|
|
}
|