The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/ngalert/api/tooling/definitions/eval_condition.go

35 lines
713 B

package definitions
import (
"encoding/json"
"fmt"
"time"
)
// EvalAlertConditionCommand is the command for evaluating a condition
type EvalAlertConditionCommand struct {
Condition string `json:"condition"`
Data []AlertQuery `json:"data"`
Now time.Time `json:"now"`
}
func (cmd *EvalAlertConditionCommand) UnmarshalJSON(b []byte) error {
type plain EvalAlertConditionCommand
if err := json.Unmarshal(b, (*plain)(cmd)); err != nil {
return err
}
return cmd.validate()
}
func (cmd *EvalAlertConditionCommand) validate() error {
if cmd.Condition == "" {
return fmt.Errorf("missing condition")
}
if len(cmd.Data) == 0 {
return fmt.Errorf("missing data")
}
return nil
}