Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateAlertInstance(alertInstance *AlertInstance) error
- type AdminConfiguration
- type AlertConfiguration
- type AlertInstance
- type AlertQuery
- func (aq *AlertQuery) GetDatasource() (string, error)
- func (aq *AlertQuery) GetIntervalDuration() (time.Duration, error)
- func (aq *AlertQuery) GetMaxDatapoints() (int64, error)
- func (aq *AlertQuery) GetModel() ([]byte, error)
- func (aq *AlertQuery) IsExpression() (bool, error)
- func (aq *AlertQuery) PreSave() error
- type AlertRule
- type AlertRuleKey
- type AlertRuleVersion
- type Condition
- type Duration
- type EvalAlertConditionCommand
- type ExecutionErrorState
- type GetAlertInstanceQuery
- type GetAlertRuleByUIDQuery
- type GetLatestAlertmanagerConfigurationQuery
- type InstanceLabels
- type InstanceStateType
- type ListAlertInstancesQuery
- type ListAlertInstancesQueryResult
- type ListAlertRulesQuery
- type ListNamespaceAlertRulesQuery
- type ListOrgRuleGroupsQuery
- type ListRuleGroupAlertRulesQuery
- type NoDataState
- type RelativeTimeRange
- type SaveAlertInstanceCommand
- type SaveAlertmanagerConfigurationCmd
Constants ¶
const ( RuleUIDLabel = "__alert_rule_uid__" NamespaceUIDLabel = "__alert_rule_namespace_uid__" // Annotations are actually a set of labels, so technically this is the label name of an annotation. DashboardUIDAnnotation = "__dashboardUid__" PanelIDAnnotation = "__panelId__" )
const AlertConfigurationVersion = 1
Variables ¶
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 ErrRuleGroupNamespaceNotFound = errors.New("rule group not found under this namespace") // ErrAlertRuleFailedValidation ErrAlertRuleFailedValidation = errors.New("invalid alert rule") // ErrAlertRuleUniqueConstraintViolation ErrAlertRuleUniqueConstraintViolation = errors.New("a conflicting alert rule is found: rule title under the same organisation and folder should be unique") )
Functions ¶
func ValidateAlertInstance ¶
func ValidateAlertInstance(alertInstance *AlertInstance) error
ValidateAlertInstance validates that the alert instance contains an alert rule id, and state.
Types ¶
type AdminConfiguration ¶
type AdminConfiguration struct {
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
// List of Alertmanager(s) URL to push alerts to.
Alertmanagers []string
CreatedAt int64 `xorm:"created"`
UpdatedAt int64 `xorm:"updated"`
}
AdminConfiguration represents the ngalert administration configuration settings.
func (*AdminConfiguration) AsSHA256 ¶
func (ac *AdminConfiguration) AsSHA256() string
func (*AdminConfiguration) Validate ¶
func (ac *AdminConfiguration) Validate() error
type AlertConfiguration ¶
type AlertConfiguration struct {
ID int64 `xorm:"pk autoincr 'id'"`
AlertmanagerConfiguration string
ConfigurationVersion string
CreatedAt int64 `xorm:"created"`
Default bool
OrgID int64 `xorm:"org_id"`
}
AlertConfiguration represents a single version of the Alerting Engine Configuration.
type AlertInstance ¶
type AlertInstance struct {
RuleOrgID int64 `xorm:"rule_org_id"`
RuleUID string `xorm:"rule_uid"`
Labels InstanceLabels
LabelsHash string
CurrentState InstanceStateType
CurrentStateSince time.Time
CurrentStateEnd time.Time
LastEvalTime time.Time
}
AlertInstance represents a single alert instance.
type AlertQuery ¶
type AlertQuery struct {
// RefID is the unique identifier of the query, set by the frontend call.
RefID string `json:"refId"`
// QueryType is an optional identifier for the type of query.
// It can be used to distinguish different types of queries.
QueryType string `json:"queryType"`
// RelativeTimeRange is the relative Start and End of the query as sent by the frontend.
RelativeTimeRange RelativeTimeRange `json:"relativeTimeRange"`
// Grafana data source unique identifier; it should be '-100' for a Server Side Expression operation.
DatasourceUID string `json:"datasourceUid"`
// JSON is the raw JSON query and includes the above properties as well as custom properties.
Model json.RawMessage `json:"model"`
// contains filtered or unexported fields
}
AlertQuery represents a single query associated with an alert definition.
func (*AlertQuery) GetDatasource ¶
func (aq *AlertQuery) GetDatasource() (string, error)
GetDatasource returns the query datasource identifier.
func (*AlertQuery) GetIntervalDuration ¶
func (aq *AlertQuery) GetIntervalDuration() (time.Duration, error)
func (*AlertQuery) GetMaxDatapoints ¶
func (aq *AlertQuery) GetMaxDatapoints() (int64, error)
func (*AlertQuery) GetModel ¶
func (aq *AlertQuery) GetModel() ([]byte, error)
func (*AlertQuery) IsExpression ¶
func (aq *AlertQuery) IsExpression() (bool, error)
IsExpression returns true if the alert query is an expression.
func (*AlertQuery) PreSave ¶
func (aq *AlertQuery) PreSave() error
PreSave sets query's properties. It should be called before being saved.
type AlertRule ¶
type AlertRule struct {
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
Title string
Condition string
Data []AlertQuery
Updated time.Time
IntervalSeconds int64
Version int64
UID string `xorm:"uid"`
NamespaceUID string `xorm:"namespace_uid"`
DashboardUID *string `xorm:"dashboard_uid"`
PanelID *int64 `xorm:"panel_id"`
RuleGroup string
NoDataState NoDataState
ExecErrState ExecutionErrorState
// ideally this field should have been apimodels.ApiDuration
// but this is currently not possible because of circular dependencies
For time.Duration
Annotations map[string]string
Labels map[string]string
}
AlertRule is the model for alert rules in unified alerting.
func (*AlertRule) GetKey ¶
func (alertRule *AlertRule) GetKey() AlertRuleKey
GetKey returns the alert definitions identifier
type AlertRuleKey ¶
AlertRuleKey is the alert definition identifier
func (AlertRuleKey) String ¶
func (k AlertRuleKey) String() string
type AlertRuleVersion ¶
type AlertRuleVersion struct {
ID int64 `xorm:"pk autoincr 'id'"`
RuleOrgID int64 `xorm:"rule_org_id"`
RuleUID string `xorm:"rule_uid"`
RuleNamespaceUID string `xorm:"rule_namespace_uid"`
RuleGroup string
ParentVersion int64
RestoredFrom int64
Version int64
Created time.Time
Title string
Condition string
Data []AlertQuery
IntervalSeconds int64
NoDataState NoDataState
ExecErrState ExecutionErrorState
// ideally this field should have been apimodels.ApiDuration
// but this is currently not possible because of circular dependencies
For time.Duration
Annotations map[string]string
Labels map[string]string
}
AlertRuleVersion is the model for alert rule versions in unified alerting.
type Condition ¶
type Condition struct {
// Condition is the RefID of the query or expression from
// the Data property to get the results for.
Condition string `json:"condition"`
OrgID int64 `json:"-"`
// Data is an array of data source queries and/or server side expressions.
Data []AlertQuery `json:"data"`
}
Condition contains backend expressions and queries and the RefID of the query or expression that will be evaluated.
type Duration ¶
Duration is a type used for marshalling durations.
func (Duration) MarshalJSON ¶
func (*Duration) UnmarshalJSON ¶
type EvalAlertConditionCommand ¶
type EvalAlertConditionCommand struct {
Condition string `json:"condition"`
Data []AlertQuery `json:"data"`
Now time.Time `json:"now"`
}
EvalAlertConditionCommand is the command for evaluating a condition
func (*EvalAlertConditionCommand) UnmarshalJSON ¶
func (cmd *EvalAlertConditionCommand) UnmarshalJSON(b []byte) error
type ExecutionErrorState ¶
type ExecutionErrorState string
const (
AlertingErrState ExecutionErrorState = "Alerting"
)
func (ExecutionErrorState) String ¶
func (executionErrorState ExecutionErrorState) String() string
type GetAlertInstanceQuery ¶
type GetAlertInstanceQuery struct {
RuleOrgID int64
RuleUID string
Labels InstanceLabels
Result *AlertInstance
}
GetAlertInstanceQuery is the query for retrieving/deleting an alert definition by ID. nolint:unused
type GetAlertRuleByUIDQuery ¶
GetAlertRuleByUIDQuery is the query for retrieving/deleting an alert rule by UID and organisation ID.
type GetLatestAlertmanagerConfigurationQuery ¶
type GetLatestAlertmanagerConfigurationQuery struct {
OrgID int64
Result *AlertConfiguration
}
GetLatestAlertmanagerConfigurationQuery is the query to get the latest alertmanager configuration.
type InstanceLabels ¶
InstanceLabels is an extension to data.Labels with methods for database serialization.
func (*InstanceLabels) FromDB ¶
func (il *InstanceLabels) FromDB(b []byte) error
FromDB loads labels stored in the database as json tuples into InstanceLabels. FromDB is part of the xorm Conversion interface.
func (*InstanceLabels) StringAndHash ¶
func (il *InstanceLabels) StringAndHash() (string, string, error)
StringAndHash returns a the json representation of the labels as tuples sorted by key. It also returns the a hash of that representation.
func (*InstanceLabels) StringKey ¶
func (il *InstanceLabels) StringKey() (string, error)
func (*InstanceLabels) ToDB ¶
func (il *InstanceLabels) ToDB() ([]byte, error)
ToDB is not implemented as serialization is handled with manual SQL queries). ToDB is part of the xorm Conversion interface.
type InstanceStateType ¶
type InstanceStateType string
InstanceStateType is an enum for instance states.
const ( // InstanceStateFiring is for a firing alert. InstanceStateFiring InstanceStateType = "Alerting" // InstanceStateNormal is for a normal alert. InstanceStateNormal InstanceStateType = "Normal" // InstanceStatePending is for an alert that is firing but has not met the duration InstanceStatePending InstanceStateType = "Pending" // InstanceStateNoData is for an alert with no data. InstanceStateNoData InstanceStateType = "NoData" // InstanceStateError is for a erroring alert. InstanceStateError InstanceStateType = "Error" )
func (InstanceStateType) IsValid ¶
func (i InstanceStateType) IsValid() bool
IsValid checks that the value of InstanceStateType is a valid string.
type ListAlertInstancesQuery ¶
type ListAlertInstancesQuery struct {
RuleOrgID int64 `json:"-"`
RuleUID string
State InstanceStateType
Result []*ListAlertInstancesQueryResult
}
ListAlertInstancesQuery is the query list alert Instances.
type ListAlertInstancesQueryResult ¶
type ListAlertInstancesQueryResult struct {
RuleOrgID int64 `xorm:"rule_org_id" json:"ruleOrgId"`
RuleUID string `xorm:"rule_uid" json:"ruleUid"`
Labels InstanceLabels `json:"labels"`
LabelsHash string `json:"labeHash"`
CurrentState InstanceStateType `json:"currentState"`
CurrentStateSince time.Time `json:"currentStateSince"`
CurrentStateEnd time.Time `json:"currentStateEnd"`
LastEvalTime time.Time `json:"lastEvalTime"`
}
ListAlertInstancesQueryResult represents the result of listAlertInstancesQuery.
type ListAlertRulesQuery ¶
type ListAlertRulesQuery struct {
OrgID int64
NamespaceUIDs []string
ExcludeOrgs []int64
// DashboardUID and PanelID are optional and allow filtering rules
// to return just those for a dashboard and panel.
DashboardUID string
PanelID int64
Result []*AlertRule
}
ListAlertRulesQuery is the query for listing alert rules
type ListNamespaceAlertRulesQuery ¶
type ListNamespaceAlertRulesQuery struct {
OrgID int64
// Namespace is the folder slug
NamespaceUID string
Result []*AlertRule
}
ListNamespaceAlertRulesQuery is the query for listing namespace alert rules
type ListOrgRuleGroupsQuery ¶
type ListOrgRuleGroupsQuery struct {
OrgID int64
NamespaceUIDs []string
// DashboardUID and PanelID are optional and allow filtering rules
// to return just those for a dashboard and panel.
DashboardUID string
PanelID int64
Result [][]string
}
ListOrgRuleGroupsQuery is the query for listing unique rule groups
type ListRuleGroupAlertRulesQuery ¶
type ListRuleGroupAlertRulesQuery struct {
OrgID int64
// Namespace is the folder slug
NamespaceUID string
RuleGroup string
// DashboardUID and PanelID are optional and allow filtering rules
// to return just those for a dashboard and panel.
DashboardUID string
PanelID int64
Result []*AlertRule
}
ListRuleGroupAlertRulesQuery is the query for listing rule group alert rules
type NoDataState ¶
type NoDataState string
const ( Alerting NoDataState = "Alerting" NoData NoDataState = "NoData" OK NoDataState = "OK" )
func (NoDataState) String ¶
func (noDataState NoDataState) String() string
type RelativeTimeRange ¶
RelativeTimeRange is the per query start and end time for requests.
func (*RelativeTimeRange) ToTimeRange ¶
func (rtr *RelativeTimeRange) ToTimeRange(now time.Time) backend.TimeRange
type SaveAlertInstanceCommand ¶
type SaveAlertInstanceCommand struct {
RuleOrgID int64
RuleUID string
Labels InstanceLabels
State InstanceStateType
LastEvalTime time.Time
CurrentStateSince time.Time
CurrentStateEnd time.Time
}
SaveAlertInstanceCommand is the query for saving a new alert instance.