package models import ( "context" "encoding/json" "errors" "fmt" "sort" "strconv" "time" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" alertingModels "github.com/grafana/alerting/models" "github.com/grafana/grafana/pkg/services/quota" "github.com/grafana/grafana/pkg/util/cmputil" ) var ( // ErrAlertRuleNotFound is an error for an unknown alert rule. ErrAlertRuleNotFound = fmt.Errorf("could not find alert rule") // ErrAlertRuleFailedGenerateUniqueUID is an error for failure to generate alert rule UID ErrAlertRuleFailedGenerateUniqueUID = errors.New("failed to generate alert rule UID") // ErrCannotEditNamespace is an error returned if the user does not have permissions to edit the namespace ErrCannotEditNamespace = errors.New("user does not have permissions to edit the namespace") ErrRuleGroupNamespaceNotFound = errors.New("rule group not found under this namespace") ErrAlertRuleFailedValidation = errors.New("invalid alert rule") ErrAlertRuleUniqueConstraintViolation = errors.New("a conflicting alert rule is found: rule title under the same organisation and folder should be unique") ErrQuotaReached = errors.New("quota has been exceeded") // ErrNoDashboard is returned when the alert rule does not have a Dashboard UID // in its annotations or the dashboard does not exist. ErrNoDashboard = errors.New("no dashboard") // ErrNoPanel is returned when the alert rule does not have a PanelID in its // annotations. ErrNoPanel = errors.New("no panel") ) // swagger:enum NoDataState type NoDataState string func (noDataState NoDataState) String() string { return string(noDataState) } func NoDataStateFromString(state string) (NoDataState, error) { switch state { case string(Alerting): return Alerting, nil case string(NoData): return NoData, nil case string(OK): return OK, nil default: return "", fmt.Errorf("unknown NoData state option %s", state) } } const ( Alerting NoDataState = "Alerting" NoData NoDataState = "NoData" OK NoDataState = "OK" ) // swagger:enum ExecutionErrorState type ExecutionErrorState string func (executionErrorState ExecutionErrorState) String() string { return string(executionErrorState) } func ErrStateFromString(opt string) (ExecutionErrorState, error) { switch opt { case string(Alerting): return AlertingErrState, nil case string(ErrorErrState): return ErrorErrState, nil case string(OkErrState): return OkErrState, nil default: return "", fmt.Errorf("unknown Error state option %s", opt) } } const ( AlertingErrState ExecutionErrorState = "Alerting" ErrorErrState ExecutionErrorState = "Error" OkErrState ExecutionErrorState = "OK" ) const ( // Annotations are actually a set of labels, so technically this is the label name of an annotation. DashboardUIDAnnotation = "__dashboardUid__" PanelIDAnnotation = "__panelId__" // GrafanaReservedLabelPrefix contains the prefix for Grafana reserved labels. These differ from "__