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

Add Alert definitions, Axis.Label, Cloudwatch fields #28

Merged
merged 4 commits into from
Apr 23, 2019
Merged
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
70 changes: 70 additions & 0 deletions panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
TableType
TextType
PluginlistType
AlertlistType
SinglestatType
)

Expand All @@ -49,6 +50,7 @@ type (
*DashlistPanel
*PluginlistPanel
*RowPanel
*AlertlistPanel
*CustomPanel
}
panelType int8
Expand Down Expand Up @@ -82,6 +84,37 @@ type (
Title string `json:"title"` // general
Transparent bool `json:"transparent"`
Type string `json:"type"`
Alert *Alert `json:"alert,omitempty"`
}
AlertCondition struct {
Evaluator struct {
Params []float64 `json:"params,omitempty"`
Type string `json:"type,omitempty"`
} `json:"evaluator,omitempty"`
Operator struct {
Type string `json:"type,omitempty"`
} `json:"operator,omitempty"`
Query struct {
Params []string `json:"params,omitempty"`
} `json:"query,omitempty"`
Reducer struct {
Params []string `json:"params,omitempty"`
Type string `json:"type,omitempty"`
} `json:"reducer,omitempty"`
Type string `json:"type,omitempty"`
}
AlertNotification struct {
ID int `json:"id,omitempty"`
}
Alert struct {
Conditions []AlertCondition `json:"conditions,omitempty"`
ExecutionErrorState string `json:"executionErrorState,omitempty"`
Frequency string `json:"frequency,omitempty"`
Handler int `json:"handler,omitempty"`
Name string `json:"name,omitempty"`
NoDataState string `json:"noDataState,omitempty"`
Notifications []AlertNotification `json:"notifications,omitempty"`
Message string `json:"message,omitempty"`
}
GraphPanel struct {
AliasColors interface{} `json:"aliasColors"` // XXX
Expand Down Expand Up @@ -219,6 +252,13 @@ type (
PluginlistPanel struct {
Limit int `json:"limit,omitempty"`
}
AlertlistPanel struct {
OnlyAlertsOnDashboard bool `json:"onlyAlertsOnDashboard"`
Show string `json:"show"`
SortOrder int `json:"sortOrder"`
Limit int `json:"limit"`
StateFilter []string `json:"stateFilter"`
}
RowPanel struct {
Panels []Panel
}
Expand Down Expand Up @@ -254,6 +294,7 @@ type (
Max *FloatString `json:"max,omitempty"`
Min *FloatString `json:"min,omitempty"`
Show bool `json:"show"`
Label string `json:"label,omitempty"`
}
SeriesOverride struct {
Alias string `json:"alias"`
Expand Down Expand Up @@ -334,6 +375,14 @@ type Target struct {

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

// For CloudWatch
Namespace string `json:"namespace,omitempty"`
MetricName string `json:"metricName,omitempty"`
Statistics []string `json:"statistics,omitempty"`
Dimensions map[string]string `json:"dimensions,omitempty"`
Period string `json:"period,omitempty"`
Region string `json:"region,omitempty"`
}

type MapType struct {
Expand Down Expand Up @@ -449,6 +498,21 @@ func NewPluginlist(title string) *Panel {
PluginlistPanel: &PluginlistPanel{}}
}

func NewAlertlist(title string) *Panel {
if title == "" {
title = "Panel Title"
}
render := "flot"
return &Panel{
commonPanel: commonPanel{
OfType: AlertlistType,
Title: title,
Type: "alertlist",
Renderer: &render,
IsNew: true},
AlertlistPanel: &AlertlistPanel{}}
}

// NewCustom initializes panel with a singlestat panel.
func NewCustom(title string) *Panel {
if title == "" {
Expand Down Expand Up @@ -676,6 +740,12 @@ func (p *Panel) MarshalJSON() ([]byte, error) {
PluginlistPanel
}{p.commonPanel, *p.PluginlistPanel}
return json.Marshal(outPluginlist)
case AlertlistType:
var outAlertlist = struct {
commonPanel
AlertlistPanel
}{p.commonPanel, *p.AlertlistPanel}
return json.Marshal(outAlertlist)
case CustomType:
var outCustom = struct {
commonPanel
Expand Down