Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce support for Alert Rules that utilize Cloudwatch as a datasource #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,30 @@ type Alert struct {
Interval string `json:"interval"`
Rules []AlertRule `json:"rules"`
}

type AlertRule struct {
For string `json:"for"`
GrafanaAlert *GrafanaAlert `json:"grafana_alert,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}

type GrafanaAlert struct {
Title string `json:"title"`
Condition string `json:"condition"`
NoDataState string `json:"no_data_state"`
ExecutionErrorState string `json:"exec_err_state,omitempty"`
Data []AlertQuery `json:"data"`
}

type AlertQuery struct {
RefID string `json:"refId"`
QueryType string `json:"queryType"`
RelativeTimeRange *AlertRelativeTimeRange `json:"relativeTimeRange,omitempty"`
DatasourceUID string `json:"datasourceUid"`
Model AlertModel `json:"model"`
}

type AlertRelativeTimeRange struct {
From int `json:"from"` // seconds
To int `json:"to"` // seconds
}

type AlertModel struct {
RefID string `json:"refId,omitempty"`
QueryType string `json:"queryType,omitempty"`
Expand All @@ -65,16 +60,29 @@ type AlertModel struct {
IntervalMs int `json:"intervalMs,omitempty"`
Hide *bool `json:"hide,omitempty"`
Conditions []AlertCondition `json:"conditions,omitempty"`

// For Graphite
Target string `json:"target,omitempty"`

// For Stackdriver
MetricQuery *StackdriverAlertQuery `json:"metricQuery,omitempty"`
// For Cloudwatch
Dimensions map[string]string `json:"dimensions,omitempty"`
Expression string `json:"expression,omitempty"`
Id string `json:"ids,omitempty"`
Label string `json:"label,omitempty"`
MatchExact *bool `json:"matchExact,omitempty"`
MaxDataPoints int `json:"maxDataPoints,omitempty"`
MetricEditorMode int `json:"metricEditorMode,omitempty"`
MetricName string `json:"metricName,omitempty"`
MetricQueryType int `json:"metricQueryType,omitempty"`
Namespace string `json:"namespace,omitempty"`
Period string `json:"period,omitempty"`
QueryMode string `json:"queryMode,omitempty"`
Region string `json:"region,omitempty"`
SqlExpression string `json:"sqlExpression,omitempty"`
Statistic string `json:"statistic,omitempty"`
}

type StackdriverAlertQuery struct {
ProjectName string `json:"projectName,omitempty"`
AlignOptions []StackdriverAlignOptions `json:"alignOptions,omitempty"`
AliasBy string `json:"aliasBy,omitempty"`
MetricType string `json:"metricType,omitempty"`
Expand All @@ -86,13 +94,12 @@ type StackdriverAlertQuery struct {
ValueType string `json:"valueType,omitempty"`
Preprocessor string `json:"preprocessor,omitempty"`
GroupBys []string `json:"groupBys,omitempty"`
ProjectName string `json:"projectName,omitempty"`
}

type AlertDatasourceRef struct {
UID string `json:"uid"`
Type string `json:"type"`
}

type AlertCondition struct {
Type string `json:"type,omitempty"`
Evaluator AlertEvaluator `json:"evaluator,omitempty"`
Expand All @@ -107,11 +114,9 @@ type AlertEvaluator struct {
Params []float64 `json:"params,omitempty"`
Type string `json:"type,omitempty"`
}

type AlertOperator struct {
Type string `json:"type,omitempty"`
}

type AlertReducer struct {
Params []string `json:"params,omitempty"`
Type string `json:"type,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion panel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,4 @@ func TestCustomPanelOutput_MarshalJSON(t *testing.T) {
t.Fatalf("wrong value of %s: got %s, expected %s", titleKey, val, titleValue)
}

}
}