2016-11-10 17:27:42 +00:00
|
|
|
package kapacitor
|
|
|
|
|
2017-11-07 21:59:41 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
2016-11-10 17:27:42 +00:00
|
|
|
|
|
|
|
const (
|
2017-03-06 16:11:52 +00:00
|
|
|
greaterThan = "greater than"
|
|
|
|
lessThan = "less than"
|
2017-11-30 17:40:36 +00:00
|
|
|
lessThanEqual = "equal to or less than"
|
|
|
|
greaterThanEqual = "equal to or greater"
|
|
|
|
equal = "equal to"
|
|
|
|
notEqual = "not equal to"
|
|
|
|
insideRange = "inside range"
|
|
|
|
outsideRange = "outside range"
|
2016-11-10 17:27:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// kapaOperator converts UI strings to kapacitor operators
|
|
|
|
func kapaOperator(operator string) (string, error) {
|
|
|
|
switch operator {
|
2017-03-06 16:11:52 +00:00
|
|
|
case greaterThan:
|
2016-11-10 17:27:42 +00:00
|
|
|
return ">", nil
|
2017-03-06 16:11:52 +00:00
|
|
|
case lessThan:
|
2016-11-10 17:27:42 +00:00
|
|
|
return "<", nil
|
2017-11-30 17:40:36 +00:00
|
|
|
case lessThanEqual:
|
2016-11-10 17:27:42 +00:00
|
|
|
return "<=", nil
|
2017-11-30 17:40:36 +00:00
|
|
|
case greaterThanEqual:
|
2016-11-10 17:27:42 +00:00
|
|
|
return ">=", nil
|
2017-11-30 17:40:36 +00:00
|
|
|
case equal:
|
2016-11-10 17:27:42 +00:00
|
|
|
return "==", nil
|
2017-11-30 17:40:36 +00:00
|
|
|
case notEqual:
|
2016-11-10 17:27:42 +00:00
|
|
|
return "!=", nil
|
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("invalid operator: %s is unknown", operator)
|
|
|
|
}
|
|
|
|
}
|
2017-01-05 04:20:12 +00:00
|
|
|
|
2017-03-27 19:21:57 +00:00
|
|
|
func chronoOperator(operator string) (string, error) {
|
|
|
|
switch operator {
|
|
|
|
case ">":
|
|
|
|
return greaterThan, nil
|
|
|
|
case "<":
|
|
|
|
return lessThan, nil
|
|
|
|
case "<=":
|
2017-11-30 17:40:36 +00:00
|
|
|
return lessThanEqual, nil
|
2017-03-27 19:21:57 +00:00
|
|
|
case ">=":
|
2017-11-30 17:40:36 +00:00
|
|
|
return greaterThanEqual, nil
|
2017-03-27 19:21:57 +00:00
|
|
|
case "==":
|
2017-11-30 17:40:36 +00:00
|
|
|
return equal, nil
|
2017-03-27 19:21:57 +00:00
|
|
|
case "!=":
|
2017-11-30 17:40:36 +00:00
|
|
|
return notEqual, nil
|
2017-03-27 19:21:57 +00:00
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("invalid operator: %s is unknown", operator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-05 04:20:12 +00:00
|
|
|
func rangeOperators(operator string) ([]string, error) {
|
|
|
|
switch operator {
|
2017-11-30 17:40:36 +00:00
|
|
|
case insideRange:
|
2017-01-05 04:20:12 +00:00
|
|
|
return []string{">=", "AND", "<="}, nil
|
2017-11-30 17:40:36 +00:00
|
|
|
case outsideRange:
|
2017-01-05 04:20:12 +00:00
|
|
|
return []string{"<", "OR", ">"}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("invalid operator: %s is unknown", operator)
|
|
|
|
}
|
|
|
|
}
|
2017-03-27 19:21:57 +00:00
|
|
|
|
|
|
|
func chronoRangeOperators(ops []string) (string, error) {
|
|
|
|
if len(ops) != 3 {
|
|
|
|
return "", fmt.Errorf("Unknown operators")
|
|
|
|
}
|
|
|
|
if ops[0] == ">=" && ops[1] == "AND" && ops[2] == "<=" {
|
2017-11-30 17:40:36 +00:00
|
|
|
return insideRange, nil
|
2017-03-27 19:21:57 +00:00
|
|
|
} else if ops[0] == "<" && ops[1] == "OR" && ops[2] == ">" {
|
2017-11-30 17:40:36 +00:00
|
|
|
return outsideRange, nil
|
2017-03-27 19:21:57 +00:00
|
|
|
}
|
|
|
|
return "", fmt.Errorf("Unknown operators")
|
|
|
|
}
|