From 9c7b52fd36e63da8b71a27791aa16990d448d3fc Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> Date: Tue, 30 Nov 2021 21:55:54 +0200 Subject: [PATCH] Alerting: Fix API specification (#42282) * Alerting: Fix API specification --- pkg/services/ngalert/api/api.go | 2 +- pkg/services/ngalert/api/api_alertmanager.go | 2 +- pkg/services/ngalert/api/forked_am.go | 2 +- .../api/generated_base_api_alertmanager.go | 4 +- pkg/services/ngalert/api/lotex_am.go | 2 +- .../api/tooling/definitions/alertmanager.go | 11 +- .../ngalert/api/tooling/definitions/api.go | 6 +- pkg/services/ngalert/api/tooling/post.json | 249 ++++++++++++++++-- pkg/services/ngalert/api/tooling/spec.json | 239 +++++++++++++++-- pkg/services/ngalert/notifier/receivers.go | 4 +- 10 files changed, 459 insertions(+), 62 deletions(-) diff --git a/pkg/services/ngalert/api/api.go b/pkg/services/ngalert/api/api.go index d24c079d19a..71e55096b9c 100644 --- a/pkg/services/ngalert/api/api.go +++ b/pkg/services/ngalert/api/api.go @@ -46,7 +46,7 @@ type Alertmanager interface { GetAlertGroups(active, silenced, inhibited bool, filter []string, receiver string) (apimodels.AlertGroups, error) // Testing - TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigParams) (*notifier.TestReceiversResult, error) + TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error) } // API handlers. diff --git a/pkg/services/ngalert/api/api_alertmanager.go b/pkg/services/ngalert/api/api_alertmanager.go index 0196aa1507f..fdc767e7f35 100644 --- a/pkg/services/ngalert/api/api_alertmanager.go +++ b/pkg/services/ngalert/api/api_alertmanager.go @@ -376,7 +376,7 @@ func (srv AlertmanagerSrv) RoutePostAMAlerts(_ *models.ReqContext, _ apimodels.P return NotImplementedResp } -func (srv AlertmanagerSrv) RoutePostTestReceivers(c *models.ReqContext, body apimodels.TestReceiversConfigParams) response.Response { +func (srv AlertmanagerSrv) RoutePostTestReceivers(c *models.ReqContext, body apimodels.TestReceiversConfigBodyParams) response.Response { if !c.HasUserRole(models.ROLE_EDITOR) { return accessForbiddenResp() } diff --git a/pkg/services/ngalert/api/forked_am.go b/pkg/services/ngalert/api/forked_am.go index 9936e1dcb63..3fffb6b5eb7 100644 --- a/pkg/services/ngalert/api/forked_am.go +++ b/pkg/services/ngalert/api/forked_am.go @@ -147,7 +147,7 @@ func (am *ForkedAMSvc) RoutePostAMAlerts(ctx *models.ReqContext, body apimodels. return s.RoutePostAMAlerts(ctx, body) } -func (am *ForkedAMSvc) RoutePostTestReceivers(ctx *models.ReqContext, body apimodels.TestReceiversConfigParams) response.Response { +func (am *ForkedAMSvc) RoutePostTestReceivers(ctx *models.ReqContext, body apimodels.TestReceiversConfigBodyParams) response.Response { s, err := am.getService(ctx) if err != nil { return ErrResp(400, err, "") diff --git a/pkg/services/ngalert/api/generated_base_api_alertmanager.go b/pkg/services/ngalert/api/generated_base_api_alertmanager.go index 52b20f8afa8..6c786dc3aa2 100644 --- a/pkg/services/ngalert/api/generated_base_api_alertmanager.go +++ b/pkg/services/ngalert/api/generated_base_api_alertmanager.go @@ -31,7 +31,7 @@ type AlertmanagerApiService interface { RouteGetSilences(*models.ReqContext) response.Response RoutePostAMAlerts(*models.ReqContext, apimodels.PostableAlerts) response.Response RoutePostAlertingConfig(*models.ReqContext, apimodels.PostableUserConfig) response.Response - RoutePostTestReceivers(*models.ReqContext, apimodels.TestReceiversConfigParams) response.Response + RoutePostTestReceivers(*models.ReqContext, apimodels.TestReceiversConfigBodyParams) response.Response } func (api *API) RegisterAlertmanagerApiEndpoints(srv AlertmanagerApiService, m *metrics.API) { @@ -140,7 +140,7 @@ func (api *API) RegisterAlertmanagerApiEndpoints(srv AlertmanagerApiService, m * ) group.Post( toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/receivers/test"), - binding.Bind(apimodels.TestReceiversConfigParams{}), + binding.Bind(apimodels.TestReceiversConfigBodyParams{}), metrics.Instrument( http.MethodPost, "/api/alertmanager/{Recipient}/config/api/v1/receivers/test", diff --git a/pkg/services/ngalert/api/lotex_am.go b/pkg/services/ngalert/api/lotex_am.go index 9eb3a1ec25f..345f2be0033 100644 --- a/pkg/services/ngalert/api/lotex_am.go +++ b/pkg/services/ngalert/api/lotex_am.go @@ -241,6 +241,6 @@ func (am *LotexAM) RoutePostAMAlerts(ctx *models.ReqContext, alerts apimodels.Po ) } -func (am *LotexAM) RoutePostTestReceivers(ctx *models.ReqContext, config apimodels.TestReceiversConfigParams) response.Response { +func (am *LotexAM) RoutePostTestReceivers(ctx *models.ReqContext, config apimodels.TestReceiversConfigBodyParams) response.Response { return NotImplementedResp } diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index b701f74a3bb..7a8088e1cd0 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -138,12 +138,15 @@ type MultiStatus struct{} // swagger:parameters RoutePostTestReceivers type TestReceiversConfigParams struct { // in:body - Alert *TestReceiversConfigAlertParams `yaml:"alert,omitempty" json:"alert,omitempty"` - // in:body - Receivers []*PostableApiReceiver `yaml:"receivers,omitempty" json:"receivers,omitempty"` + Body TestReceiversConfigBodyParams } -func (c *TestReceiversConfigParams) ProcessConfig(encrypt EncryptFn) error { +type TestReceiversConfigBodyParams struct { + Alert *TestReceiversConfigAlertParams `yaml:"alert,omitempty" json:"alert,omitempty"` + Receivers []*PostableApiReceiver `yaml:"receivers,omitempty" json:"receivers,omitempty"` +} + +func (c *TestReceiversConfigBodyParams) ProcessConfig(encrypt EncryptFn) error { return processReceiverConfigs(c.Receivers, encrypt) } diff --git a/pkg/services/ngalert/api/tooling/definitions/api.go b/pkg/services/ngalert/api/tooling/definitions/api.go index 579c19562d9..014d6fadb45 100644 --- a/pkg/services/ngalert/api/tooling/definitions/api.go +++ b/pkg/services/ngalert/api/tooling/definitions/api.go @@ -1,6 +1,8 @@ +// Grafana Alerting API. +// // Package definitions includes the types required for generating or consuming an OpenAPI -// spec for the Unified Alerting API. -// Documentation of the API. +// spec for the Grafana Alerting API. +// // // Schemes: http, https // BasePath: /api/v1 diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index 5c1f9159ecc..2cb8e720264 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -319,6 +319,13 @@ "type": "array", "x-go-name": "InhibitRules" }, + "mute_time_intervals": { + "items": { + "$ref": "#/definitions/MuteTimeInterval" + }, + "type": "array", + "x-go-name": "MuteTimeIntervals" + }, "route": { "$ref": "#/definitions/Route" }, @@ -340,6 +347,21 @@ "type": "string", "x-go-package": "github.com/go-openapi/strfmt" }, + "DayOfMonthRange": { + "properties": { + "Begin": { + "format": "int64", + "type": "integer" + }, + "End": { + "format": "int64", + "type": "integer" + } + }, + "title": "A DayOfMonthRange is an inclusive range that may have negative Beginning/End values that represent distance from the End of the month Beginning at -1.", + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "DiscoveryBase": { "properties": { "error": { @@ -536,6 +558,13 @@ "type": "array", "x-go-name": "InhibitRules" }, + "mute_time_intervals": { + "items": { + "$ref": "#/definitions/MuteTimeInterval" + }, + "type": "array", + "x-go-name": "MuteTimeIntervals" + }, "receivers": { "description": "Override with our superset receiver type", "items": { @@ -886,6 +915,10 @@ "opsgenie_api_key": { "$ref": "#/definitions/Secret" }, + "opsgenie_api_key_file": { + "type": "string", + "x-go-name": "OpsGenieAPIKeyFile" + }, "opsgenie_api_url": { "$ref": "#/definitions/URL" }, @@ -999,6 +1032,21 @@ "type": "object", "x-go-package": "github.com/prometheus/alertmanager/config" }, + "InclusiveRange": { + "properties": { + "Begin": { + "format": "int64", + "type": "integer" + }, + "End": { + "format": "int64", + "type": "integer" + } + }, + "title": "InclusiveRange is used to hold the Beginning and End values of many time interval components.", + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "InhibitRule": { "description": "InhibitRule defines an inhibition rule that mutes alerts that match the\ntarget labels if an alert matching the source labels exists.\nBoth alerts have to have a set of labels being equal.", "properties": { @@ -1123,10 +1171,43 @@ }, "type": "array" }, + "MonthRange": { + "properties": { + "Begin": { + "format": "int64", + "type": "integer" + }, + "End": { + "format": "int64", + "type": "integer" + } + }, + "title": "A MonthRange is an inclusive range between [1, 12] where 1 = January.", + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "MultiStatus": { "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "MuteTimeInterval": { + "properties": { + "name": { + "type": "string", + "x-go-name": "Name" + }, + "time_intervals": { + "items": { + "$ref": "#/definitions/TimeInterval" + }, + "type": "array", + "x-go-name": "TimeIntervals" + } + }, + "title": "MuteTimeInterval represents a named set of time intervals for which a route should be muted.", + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/config" + }, "NamespaceConfigResponse": { "additionalProperties": { "items": { @@ -1150,6 +1231,9 @@ }, "OAuth2": { "properties": { + "TLSConfig": { + "$ref": "#/definitions/TLSConfig" + }, "client_id": { "type": "string", "x-go-name": "ClientID" @@ -1190,9 +1274,17 @@ }, "OpsGenieConfig": { "properties": { + "actions": { + "type": "string", + "x-go-name": "Actions" + }, "api_key": { "$ref": "#/definitions/Secret" }, + "api_key_file": { + "type": "string", + "x-go-name": "APIKeyFile" + }, "api_url": { "$ref": "#/definitions/URL" }, @@ -1207,6 +1299,10 @@ "type": "object", "x-go-name": "Details" }, + "entity": { + "type": "string", + "x-go-name": "Entity" + }, "http_config": { "$ref": "#/definitions/HTTPClientConfig" }, @@ -1411,6 +1507,13 @@ "type": "array", "x-go-name": "InhibitRules" }, + "mute_time_intervals": { + "items": { + "$ref": "#/definitions/MuteTimeInterval" + }, + "type": "array", + "x-go-name": "MuteTimeIntervals" + }, "receivers": { "description": "Override with our superset receiver type", "items": { @@ -2428,6 +2531,22 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "TestReceiversConfigBodyParams": { + "properties": { + "alert": { + "$ref": "#/definitions/TestReceiversConfigAlertParams" + }, + "receivers": { + "items": { + "$ref": "#/definitions/PostableApiReceiver" + }, + "type": "array", + "x-go-name": "Receivers" + } + }, + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "TestReceiversResult": { "properties": { "alert": { @@ -2475,6 +2594,64 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "TimeInterval": { + "description": "TimeInterval describes intervals of time. ContainsTime will tell you if a golang time is contained\nwithin the interval.", + "properties": { + "days_of_month": { + "items": { + "$ref": "#/definitions/DayOfMonthRange" + }, + "type": "array", + "x-go-name": "DaysOfMonth" + }, + "months": { + "items": { + "$ref": "#/definitions/MonthRange" + }, + "type": "array", + "x-go-name": "Months" + }, + "times": { + "items": { + "$ref": "#/definitions/TimeRange" + }, + "type": "array", + "x-go-name": "Times" + }, + "weekdays": { + "items": { + "$ref": "#/definitions/WeekdayRange" + }, + "type": "array", + "x-go-name": "Weekdays" + }, + "years": { + "items": { + "$ref": "#/definitions/YearRange" + }, + "type": "array", + "x-go-name": "Years" + } + }, + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, + "TimeRange": { + "description": "For example, 4:00PM to End of the day would Begin at 1020 and End at 1440.", + "properties": { + "EndMinute": { + "format": "int64", + "type": "integer" + }, + "StartMinute": { + "format": "int64", + "type": "integer" + } + }, + "title": "TimeRange represents a range of minutes within a 1440 minute day, exclusive of the End minute. A day consists of 1440 minutes.", + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "URL": { "properties": { "ForceQuery": { @@ -2656,6 +2833,36 @@ "type": "object", "x-go-package": "github.com/prometheus/alertmanager/config" }, + "WeekdayRange": { + "properties": { + "Begin": { + "format": "int64", + "type": "integer" + }, + "End": { + "format": "int64", + "type": "integer" + } + }, + "title": "A WeekdayRange is an inclusive range between [0, 6] where 0 = Sunday.", + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, + "YearRange": { + "properties": { + "Begin": { + "format": "int64", + "type": "integer" + }, + "End": { + "format": "int64", + "type": "integer" + } + }, + "title": "A YearRange is a positive inclusive range.", + "type": "object", + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "alert": { "description": "Alert alert", "properties": { @@ -2677,7 +2884,6 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "alertGroup": { - "description": "AlertGroup alert group", "properties": { "alerts": { "description": "alerts", @@ -2699,15 +2905,16 @@ "labels", "receiver" ], - "type": "object" + "type": "object", + "x-go-name": "AlertGroup", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "alertGroups": { + "description": "AlertGroups alert groups", "items": { "$ref": "#/definitions/alertGroup" }, - "type": "array", - "x-go-name": "AlertGroups", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" + "type": "array" }, "alertStatus": { "description": "AlertStatus alert status", @@ -2952,12 +3159,11 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "gettableSilences": { + "description": "GettableSilences gettable silences", "items": { "$ref": "#/definitions/gettableSilence" }, - "type": "array", - "x-go-name": "GettableSilences", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" + "type": "array" }, "labelSet": { "additionalProperties": { @@ -3086,6 +3292,7 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "postableSilence": { + "description": "PostableSilence postable silence", "properties": { "comment": { "description": "comment", @@ -3125,9 +3332,7 @@ "matchers", "startsAt" ], - "type": "object", - "x-go-name": "PostableSilence", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" + "type": "object" }, "receiver": { "properties": { @@ -3251,8 +3456,8 @@ } }, "info": { - "description": "Package definitions includes the types required for generating or consuming an OpenAPI\nspec for the Unified Alerting API.\nDocumentation of the API.", - "title": "Unified Alerting API", + "description": "Package definitions includes the types required for generating or consuming an OpenAPI\nspec for the Grafana 8 Alerts API.", + "title": "Grafana 8 Alerts API.", "version": "1.1.0" }, "paths": { @@ -3731,22 +3936,10 @@ "parameters": [ { "in": "body", - "name": "alert", + "name": "Body", "schema": { - "$ref": "#/definitions/TestReceiversConfigAlertParams" - }, - "x-go-name": "Alert" - }, - { - "in": "body", - "name": "receivers", - "schema": { - "items": { - "$ref": "#/definitions/PostableApiReceiver" - }, - "type": "array" - }, - "x-go-name": "Receivers" + "$ref": "#/definitions/TestReceiversConfigBodyParams" + } }, { "description": "Recipient should be \"grafana\" for requests to be handled by grafana\nand the numeric datasource id for requests to be forwarded to a datasource", diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index 7914844df1d..5088e59149c 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -11,7 +11,8 @@ ], "swagger": "2.0", "info": { - "description": "Package definitions includes the types required for generating or consuming an OpenAPI\nspec for the Unified Alerting API.\nDocumentation of the API.", + "description": "Package definitions includes the types required for generating or consuming an OpenAPI\nspec for the Grafana Alerting API.", + "title": "Grafana Alerting API.", "version": "1.1.0" }, "basePath": "/api/v1", @@ -494,22 +495,10 @@ "operationId": "RoutePostTestReceivers", "parameters": [ { - "x-go-name": "Alert", - "name": "alert", + "name": "Body", "in": "body", "schema": { - "$ref": "#/definitions/TestReceiversConfigAlertParams" - } - }, - { - "x-go-name": "Receivers", - "name": "receivers", - "in": "body", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/PostableApiReceiver" - } + "$ref": "#/definitions/TestReceiversConfigBodyParams" } }, { @@ -1351,6 +1340,13 @@ }, "x-go-name": "InhibitRules" }, + "mute_time_intervals": { + "type": "array", + "items": { + "$ref": "#/definitions/MuteTimeInterval" + }, + "x-go-name": "MuteTimeIntervals" + }, "route": { "$ref": "#/definitions/Route" }, @@ -1370,6 +1366,21 @@ "format": "date-time", "x-go-package": "github.com/go-openapi/strfmt" }, + "DayOfMonthRange": { + "type": "object", + "title": "A DayOfMonthRange is an inclusive range that may have negative Beginning/End values that represent distance from the End of the month Beginning at -1.", + "properties": { + "Begin": { + "type": "integer", + "format": "int64" + }, + "End": { + "type": "integer", + "format": "int64" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "DiscoveryBase": { "type": "object", "required": [ @@ -1570,6 +1581,13 @@ }, "x-go-name": "InhibitRules" }, + "mute_time_intervals": { + "type": "array", + "items": { + "$ref": "#/definitions/MuteTimeInterval" + }, + "x-go-name": "MuteTimeIntervals" + }, "receivers": { "description": "Override with our superset receiver type", "type": "array", @@ -1774,6 +1792,7 @@ "enum": [ "Alerting" ], + "x-go-enum-desc": "Alerting AlertingErrState", "x-go-name": "ExecErrState" }, "id": { @@ -1802,6 +1821,7 @@ "NoData", "OK" ], + "x-go-enum-desc": "Alerting Alerting\nNoData NoData\nOK OK", "x-go-name": "NoDataState" }, "orgId": { @@ -1920,6 +1940,10 @@ "opsgenie_api_key": { "$ref": "#/definitions/Secret" }, + "opsgenie_api_key_file": { + "type": "string", + "x-go-name": "OpsGenieAPIKeyFile" + }, "opsgenie_api_url": { "$ref": "#/definitions/URL" }, @@ -2032,6 +2056,21 @@ }, "x-go-package": "github.com/prometheus/alertmanager/config" }, + "InclusiveRange": { + "type": "object", + "title": "InclusiveRange is used to hold the Beginning and End values of many time interval components.", + "properties": { + "Begin": { + "type": "integer", + "format": "int64" + }, + "End": { + "type": "integer", + "format": "int64" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "InhibitRule": { "description": "InhibitRule defines an inhibition rule that mutes alerts that match the\ntarget labels if an alert matching the source labels exists.\nBoth alerts have to have a set of labels being equal.", "type": "object", @@ -2157,10 +2196,43 @@ }, "$ref": "#/definitions/Matchers" }, + "MonthRange": { + "type": "object", + "title": "A MonthRange is an inclusive range between [1, 12] where 1 = January.", + "properties": { + "Begin": { + "type": "integer", + "format": "int64" + }, + "End": { + "type": "integer", + "format": "int64" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "MultiStatus": { "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "MuteTimeInterval": { + "type": "object", + "title": "MuteTimeInterval represents a named set of time intervals for which a route should be muted.", + "properties": { + "name": { + "type": "string", + "x-go-name": "Name" + }, + "time_intervals": { + "type": "array", + "items": { + "$ref": "#/definitions/TimeInterval" + }, + "x-go-name": "TimeIntervals" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/config" + }, "NamespaceConfigResponse": { "type": "object", "additionalProperties": { @@ -2186,6 +2258,9 @@ "type": "object", "title": "OAuth2 is the oauth2 client configuration.", "properties": { + "TLSConfig": { + "$ref": "#/definitions/TLSConfig" + }, "client_id": { "type": "string", "x-go-name": "ClientID" @@ -2226,9 +2301,17 @@ "type": "object", "title": "OpsGenieConfig configures notifications via OpsGenie.", "properties": { + "actions": { + "type": "string", + "x-go-name": "Actions" + }, "api_key": { "$ref": "#/definitions/Secret" }, + "api_key_file": { + "type": "string", + "x-go-name": "APIKeyFile" + }, "api_url": { "$ref": "#/definitions/URL" }, @@ -2243,6 +2326,10 @@ }, "x-go-name": "Details" }, + "entity": { + "type": "string", + "x-go-name": "Entity" + }, "http_config": { "$ref": "#/definitions/HTTPClientConfig" }, @@ -2446,6 +2533,13 @@ }, "x-go-name": "InhibitRules" }, + "mute_time_intervals": { + "type": "array", + "items": { + "$ref": "#/definitions/MuteTimeInterval" + }, + "x-go-name": "MuteTimeIntervals" + }, "receivers": { "description": "Override with our superset receiver type", "type": "array", @@ -2650,6 +2744,7 @@ "enum": [ "Alerting" ], + "x-go-enum-desc": "Alerting AlertingErrState", "x-go-name": "ExecErrState" }, "no_data_state": { @@ -2659,6 +2754,7 @@ "NoData", "OK" ], + "x-go-enum-desc": "Alerting Alerting\nNoData NoData\nOK OK", "x-go-name": "NoDataState" }, "title": { @@ -3462,6 +3558,22 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "TestReceiversConfigBodyParams": { + "type": "object", + "properties": { + "alert": { + "$ref": "#/definitions/TestReceiversConfigAlertParams" + }, + "receivers": { + "type": "array", + "items": { + "$ref": "#/definitions/PostableApiReceiver" + }, + "x-go-name": "Receivers" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "TestReceiversResult": { "type": "object", "properties": { @@ -3509,6 +3621,64 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "TimeInterval": { + "description": "TimeInterval describes intervals of time. ContainsTime will tell you if a golang time is contained\nwithin the interval.", + "type": "object", + "properties": { + "days_of_month": { + "type": "array", + "items": { + "$ref": "#/definitions/DayOfMonthRange" + }, + "x-go-name": "DaysOfMonth" + }, + "months": { + "type": "array", + "items": { + "$ref": "#/definitions/MonthRange" + }, + "x-go-name": "Months" + }, + "times": { + "type": "array", + "items": { + "$ref": "#/definitions/TimeRange" + }, + "x-go-name": "Times" + }, + "weekdays": { + "type": "array", + "items": { + "$ref": "#/definitions/WeekdayRange" + }, + "x-go-name": "Weekdays" + }, + "years": { + "type": "array", + "items": { + "$ref": "#/definitions/YearRange" + }, + "x-go-name": "Years" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, + "TimeRange": { + "description": "For example, 4:00PM to End of the day would Begin at 1020 and End at 1440.", + "type": "object", + "title": "TimeRange represents a range of minutes within a 1440 minute day, exclusive of the End minute. A day consists of 1440 minutes.", + "properties": { + "EndMinute": { + "type": "integer", + "format": "int64" + }, + "StartMinute": { + "type": "integer", + "format": "int64" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "URL": { "type": "object", "title": "URL is a custom URL type that allows validation at configuration load time.", @@ -3690,6 +3860,36 @@ }, "x-go-package": "github.com/prometheus/alertmanager/config" }, + "WeekdayRange": { + "type": "object", + "title": "A WeekdayRange is an inclusive range between [0, 6] where 0 = Sunday.", + "properties": { + "Begin": { + "type": "integer", + "format": "int64" + }, + "End": { + "type": "integer", + "format": "int64" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, + "YearRange": { + "type": "object", + "title": "A YearRange is a positive inclusive range.", + "properties": { + "Begin": { + "type": "integer", + "format": "int64" + }, + "End": { + "type": "integer", + "format": "int64" + } + }, + "x-go-package": "github.com/prometheus/alertmanager/timeinterval" + }, "alert": { "description": "Alert alert", "type": "object", @@ -3711,7 +3911,6 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "alertGroup": { - "description": "AlertGroup alert group", "type": "object", "required": [ "alerts", @@ -3734,6 +3933,8 @@ "$ref": "#/definitions/receiver" } }, + "x-go-name": "AlertGroup", + "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/alertGroup" }, "alertGroups": { @@ -4126,6 +4327,7 @@ "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" }, "postableSilence": { + "description": "PostableSilence postable silence", "type": "object", "required": [ "comment", @@ -4166,11 +4368,10 @@ "x-go-name": "StartsAt" } }, - "x-go-name": "PostableSilence", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/postableSilence" }, "receiver": { + "description": "Receiver receiver", "type": "object", "required": [ "name" @@ -4182,8 +4383,6 @@ "x-go-name": "Name" } }, - "x-go-name": "Receiver", - "x-go-package": "github.com/prometheus/alertmanager/api/v2/models", "$ref": "#/definitions/receiver" }, "silence": { diff --git a/pkg/services/ngalert/notifier/receivers.go b/pkg/services/ngalert/notifier/receivers.go index 8b48aae9c87..1b60a72793c 100644 --- a/pkg/services/ngalert/notifier/receivers.go +++ b/pkg/services/ngalert/notifier/receivers.go @@ -59,7 +59,7 @@ func (e ReceiverTimeoutError) Error() string { return fmt.Sprintf("the receiver timed out: %s", e.Err) } -func (am *Alertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigParams) (*TestReceiversResult, error) { +func (am *Alertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*TestReceiversResult, error) { // now represents the start time of the test now := time.Now() testAlert := newTestAlert(c, now, now) @@ -197,7 +197,7 @@ func (am *Alertmanager) TestReceivers(ctx context.Context, c apimodels.TestRecei return newTestReceiversResult(testAlert, append(invalid, results...), now), nil } -func newTestAlert(c apimodels.TestReceiversConfigParams, startsAt, updatedAt time.Time) types.Alert { +func newTestAlert(c apimodels.TestReceiversConfigBodyParams, startsAt, updatedAt time.Time) types.Alert { var ( defaultAnnotations = model.LabelSet{ "summary": "Notification test",