2016-11-10 17:27:42 +00:00
|
|
|
package kapacitor
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
const (
|
2017-03-06 16:11:52 +00:00
|
|
|
greaterThan = "greater than"
|
|
|
|
lessThan = "less than"
|
2016-11-10 17:27:42 +00:00
|
|
|
LessThanEqual = "equal to or less than"
|
2016-11-14 16:17:44 +00:00
|
|
|
GreaterThanEqual = "equal to or greater"
|
|
|
|
Equal = "equal to"
|
|
|
|
NotEqual = "not equal to"
|
2017-01-06 17:45:54 +00:00
|
|
|
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
|
|
|
|
case LessThanEqual:
|
|
|
|
return "<=", nil
|
|
|
|
case GreaterThanEqual:
|
|
|
|
return ">=", nil
|
|
|
|
case Equal:
|
|
|
|
return "==", nil
|
|
|
|
case NotEqual:
|
|
|
|
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 "<=":
|
|
|
|
return LessThanEqual, nil
|
|
|
|
case ">=":
|
|
|
|
return GreaterThanEqual, nil
|
|
|
|
case "==":
|
|
|
|
return Equal, nil
|
|
|
|
case "!=":
|
|
|
|
return NotEqual, nil
|
|
|
|
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 {
|
|
|
|
case InsideRange:
|
|
|
|
return []string{">=", "AND", "<="}, nil
|
|
|
|
case OutsideRange:
|
|
|
|
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] == "<=" {
|
|
|
|
return InsideRange, nil
|
|
|
|
} else if ops[0] == "<" && ops[1] == "OR" && ops[2] == ">" {
|
|
|
|
return OutsideRange, nil
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("Unknown operators")
|
|
|
|
}
|