mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 06:11:51 +08:00

* copy AlertQuery from ngmodels to the definition package * replaces usages of ngmodels.AlertQuery in API models * create a converter between models of AlertQuery --------- Co-authored-by: Alex Moreno <alexander.moreno@grafana.com>
36 lines
713 B
Go
36 lines
713 B
Go
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
|
|
}
|