Expressions/threshold: Fix incorrect thresholds args length (#66859)

This commit is contained in:
Gilles De Mey
2023-04-20 05:42:34 -04:00
committed by GitHub
parent 82ac2bae5f
commit 350de3f3bf
2 changed files with 77 additions and 3 deletions
+11
View File
@@ -30,6 +30,17 @@ var (
)
func NewThresholdCommand(refID, referenceVar, thresholdFunc string, conditions []float64) (*ThresholdCommand, error) {
switch thresholdFunc {
case ThresholdIsOutsideRange, ThresholdIsWithinRange:
if len(conditions) < 2 {
return nil, fmt.Errorf("incorrect number of arguments: got %d but need 2", len(conditions))
}
case ThresholdIsAbove, ThresholdIsBelow:
if len(conditions) < 1 {
return nil, fmt.Errorf("incorrect number of arguments: got %d but need 1", len(conditions))
}
}
return &ThresholdCommand{
RefID: refID,
ReferenceVar: referenceVar,