diff --git a/dashboards.go b/dashboards.go index 847d838..cfcf183 100644 --- a/dashboards.go +++ b/dashboards.go @@ -102,17 +102,19 @@ type Dashboard struct { // Widget information type Widget struct { - Type string `json:"type"` - Title string `json:"title"` - Layout Layout `json:"layout"` - Metric Metric `json:"metric,omitempty"` - Graph Graph `json:"graph,omitempty"` - Range Range `json:"range,omitempty"` - Markdown string `json:"markdown,omitempty"` + Type string `json:"type"` + Title string `json:"title"` + Layout Layout `json:"layout"` + Metric Metric `json:"metric,omitempty"` + Graph Graph `json:"graph,omitempty"` + Range Range `json:"range,omitempty"` + Markdown string `json:"markdown,omitempty"` + ReferenceLines []ReferenceLine `json:"referenceLines,omitempty"` // If this field is nil, it will be treated as a two-digit display after the decimal point. - FractionSize *int64 `json:"fractionSize,omitempty"` - Suffix string `json:"suffix,omitempty"` - RoleFullName string `json:"roleFullname,omitempty"` + FractionSize *int64 `json:"fractionSize,omitempty"` + Suffix string `json:"suffix,omitempty"` + FormatRules []FormatRule `json:"formatRules,omitempty"` + RoleFullName string `json:"roleFullname,omitempty"` } // Metric information @@ -133,6 +135,12 @@ func (m Metric) MarshalJSON() ([]byte, error) { return json.Marshal(Alias(m)) } +type FormatRule struct { + Name string `json:"name"` + Threshold float64 `json:"threshold"` + Operator string `json:"operator"` +} + // Graph information type Graph struct { Type string `json:"type"` @@ -190,6 +198,11 @@ func (r Range) MarshalJSON() ([]byte, error) { } } +type ReferenceLine struct { + Label string `json:"label"` + Value float64 `json:"value"` +} + // Layout information type Layout struct { X int64 `json:"x"` diff --git a/dashboards_test.go b/dashboards_test.go index 00ab82b..e5c2c42 100644 --- a/dashboards_test.go +++ b/dashboards_test.go @@ -108,12 +108,25 @@ func TestFindDashboard(t *testing.T) { "width": 8, "height": 10, }, + "referenceLines": []map[string]interface{}{ + { + "label": "critical", + "value": 1.23, + }, + }, }, { "type": "value", "title": "value_widget", "fractionSize": 2, "suffix": "total", + "formatRules": []map[string]interface{}{ + { + "name": "SLO", + "threshold": 2.34, + "operator": ">", + }, + }, "metric": map[string]interface{}{ "type": "expression", "expression": "alias(scale(\nsum(\n group(\n host(2u4PP3TJqbx,loadavg.*)\n )\n),\n1\n), 'test')", @@ -218,6 +231,14 @@ func TestFindDashboard(t *testing.T) { t.Error("request sends json including widgets.graph.name but:", dashboard) } + if dashboard.Widgets[1].ReferenceLines[0].Label != "critical" { + t.Error("request sends json including widgets.graph.referenceLines.label but:", dashboard) + } + + if dashboard.Widgets[1].ReferenceLines[0].Value != 1.23 { + t.Error("request sends json including widgets.graph.referenceLines.value but:", dashboard) + } + // Widget Test : Metric ( && Expression Type) if dashboard.Widgets[2].Metric.Type != "expression" { @@ -236,6 +257,18 @@ func TestFindDashboard(t *testing.T) { t.Error("request sends json including widgets.suffix but:", dashboard) } + if dashboard.Widgets[2].FormatRules[0].Name != "SLO" { + t.Error("request sends json including widgets.formatRules.name but:", dashboard) + } + + if dashboard.Widgets[2].FormatRules[0].Threshold != 2.34 { + t.Error("request sends json including widgets.formatRules.threshold but:", dashboard) + } + + if dashboard.Widgets[2].FormatRules[0].Operator != ">" { + t.Error("request sends json including widgets.formatRules.operator but:", dashboard) + } + // Widget Test : AlertStatus if dashboard.Widgets[3].RoleFullName != "test:dashboard" {