From d76f08f3668502ca95cded87c8bc60e621447df8 Mon Sep 17 00:00:00 2001 From: Josue Abreu Date: Wed, 21 Apr 2021 16:51:22 +0100 Subject: [PATCH 01/16] Alerting: Implement /status for the notification system Implements the necessary plumbing to have a /status endpoint on the notification system. --- pkg/services/ngalert/api/api.go | 1 + pkg/services/ngalert/api/api_alertmanager.go | 4 ++ pkg/services/ngalert/api/forked_am.go | 9 +++ .../api/generated_base_api_alertmanager.go | 2 + pkg/services/ngalert/api/lotex_am.go | 15 +++++ .../api/tooling/definitions/alertmanager.go | 53 ++++++++++++++- pkg/services/ngalert/api/tooling/post.json | 43 +++++++++--- pkg/services/ngalert/api/tooling/spec.json | 44 +++++++++--- pkg/services/ngalert/notifier/status.go | 22 ++++++ .../api/alerting/api_alertmanager_test.go | 67 ++++++++++++++++++- 10 files changed, 242 insertions(+), 18 deletions(-) create mode 100644 pkg/services/ngalert/notifier/status.go diff --git a/pkg/services/ngalert/api/api.go b/pkg/services/ngalert/api/api.go index 256f3f5f8d61..1b9e58893864 100644 --- a/pkg/services/ngalert/api/api.go +++ b/pkg/services/ngalert/api/api.go @@ -26,6 +26,7 @@ var timeNow = time.Now type Alertmanager interface { // Configuration SaveAndApplyConfig(config *apimodels.PostableUserConfig) error + GetStatus() apimodels.GettableStatus // Silences CreateSilence(ps *apimodels.PostableSilence) (string, error) diff --git a/pkg/services/ngalert/api/api_alertmanager.go b/pkg/services/ngalert/api/api_alertmanager.go index c51fdea4c01d..9e478df00ecb 100644 --- a/pkg/services/ngalert/api/api_alertmanager.go +++ b/pkg/services/ngalert/api/api_alertmanager.go @@ -20,6 +20,10 @@ type AlertmanagerSrv struct { log log.Logger } +func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Response { + return response.JSON(http.StatusOK, srv.am.GetStatus()) +} + func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSilence apimodels.PostableSilence) response.Response { silenceID, err := srv.am.CreateSilence(&postableSilence) if err != nil { diff --git a/pkg/services/ngalert/api/forked_am.go b/pkg/services/ngalert/api/forked_am.go index 0256e642a6a8..1c2aa4ddb9d1 100644 --- a/pkg/services/ngalert/api/forked_am.go +++ b/pkg/services/ngalert/api/forked_am.go @@ -39,6 +39,15 @@ func (am *ForkedAMSvc) getService(ctx *models.ReqContext) (AlertmanagerApiServic } } +func (am *ForkedAMSvc) RouteGetAMStatus(ctx *models.ReqContext) response.Response { + s, err := am.getService(ctx) + if err != nil { + return response.Error(400, err.Error(), nil) + } + + return s.RouteGetAMStatus(ctx) +} + func (am *ForkedAMSvc) RouteCreateSilence(ctx *models.ReqContext, body apimodels.PostableSilence) response.Response { s, err := am.getService(ctx) if err != nil { diff --git a/pkg/services/ngalert/api/generated_base_api_alertmanager.go b/pkg/services/ngalert/api/generated_base_api_alertmanager.go index 02d3c1ad83cf..e71c1ab8a7cf 100644 --- a/pkg/services/ngalert/api/generated_base_api_alertmanager.go +++ b/pkg/services/ngalert/api/generated_base_api_alertmanager.go @@ -23,6 +23,7 @@ type AlertmanagerApiService interface { RouteDeleteSilence(*models.ReqContext) response.Response RouteGetAMAlertGroups(*models.ReqContext) response.Response RouteGetAMAlerts(*models.ReqContext) response.Response + RouteGetAMStatus(*models.ReqContext) response.Response RouteGetAlertingConfig(*models.ReqContext) response.Response RouteGetSilence(*models.ReqContext) response.Response RouteGetSilences(*models.ReqContext) response.Response @@ -37,6 +38,7 @@ func (api *API) RegisterAlertmanagerApiEndpoints(srv AlertmanagerApiService) { group.Delete(toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), routing.Wrap(srv.RouteDeleteSilence)) group.Get(toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts/groups"), routing.Wrap(srv.RouteGetAMAlertGroups)) group.Get(toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts"), routing.Wrap(srv.RouteGetAMAlerts)) + group.Get(toMacaronPath("/api/alertmanager/{Recipient}/api/v2/status"), routing.Wrap(srv.RouteGetAMStatus)) group.Get(toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), routing.Wrap(srv.RouteGetAlertingConfig)) group.Get(toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), routing.Wrap(srv.RouteGetSilence)) group.Get(toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silences"), routing.Wrap(srv.RouteGetSilences)) diff --git a/pkg/services/ngalert/api/lotex_am.go b/pkg/services/ngalert/api/lotex_am.go index 136328c52d47..de92ee187b97 100644 --- a/pkg/services/ngalert/api/lotex_am.go +++ b/pkg/services/ngalert/api/lotex_am.go @@ -16,6 +16,7 @@ import ( const ( amSilencesPath = "/alertmanager/api/v2/silences" amSilencePath = "/alertmanager/api/v2/silence/%s" + amStatusPath = "/alertmanager/api/v2/status" amAlertGroupsPath = "/alertmanager/api/v2/alerts/groups" amAlertsPath = "/alertmanager/api/v2/alerts" amConfigPath = "/api/v1/alerts" @@ -33,6 +34,20 @@ func NewLotexAM(proxy *AlertingProxy, log log.Logger) *LotexAM { } } +func (am *LotexAM) RouteGetAMStatus(ctx *models.ReqContext) response.Response { + return am.withReq( + ctx, + http.MethodGet, + withPath( + *ctx.Req.URL, + amStatusPath, + ), + nil, + jsonExtractor(&apimodels.GettableStatus{}), + nil, + ) +} + func (am *LotexAM) RouteCreateSilence(ctx *models.ReqContext, silenceBody apimodels.PostableSilence) response.Response { blob, err := json.Marshal(silenceBody) if err != nil { diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index 02a68efc9ed5..e64cca11240a 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" + "github.com/go-openapi/strfmt" + "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/models" amv2 "github.com/prometheus/alertmanager/api/v2/models" @@ -35,6 +37,14 @@ import ( // 200: Ack // 400: ValidationError +// swagger:route GET /api/alertmanager/{Recipient}/api/v2/status alertmanager RouteGetAMStatus +// +// get alertmanager status and configuration +// +// Responses: +// 200: GettableStatus +// 400: ValidationError + // swagger:route GET /api/alertmanager/{Recipient}/api/v2/alerts alertmanager RouteGetAMAlerts // // get alertmanager alerts @@ -109,6 +119,47 @@ type GetSilencesParams struct { Filter []string `json:"filter"` } +// swagger:model +type GettableStatus struct { + // cluster + // Required: true + Cluster *amv2.ClusterStatus `json:"cluster"` + + // config + // Required: true + Config *PostableApiAlertingConfig `json:"config"` + + // uptime + // Required: true + // Format: date-time + Uptime *strfmt.DateTime `json:"uptime"` + + // version info + // Required: true + VersionInfo *amv2.VersionInfo `json:"versionInfo"` +} + +func NewGettableStatus(cfg *PostableApiAlertingConfig) *GettableStatus { + // In Grafana, the only field we support is Config. + cs := amv2.ClusterStatusStatusDisabled + na := "N/A" + return &GettableStatus{ + Cluster: &amv2.ClusterStatus{ + Status: &cs, + Peers: []*amv2.PeerStatus{}, + }, + VersionInfo: &amv2.VersionInfo{ + Branch: &na, + BuildDate: &na, + BuildUser: &na, + GoVersion: &na, + Revision: &na, + Version: &na, + }, + Config: cfg, + } +} + // swagger:model type PostableSilence = amv2.PostableSilence @@ -178,7 +229,7 @@ type BodyAlertingConfig struct { } // alertmanager routes -// swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig +// swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMStatus RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig // ruler routes // swagger:parameters RouteGetRulesConfig RoutePostNameRulesConfig RouteGetNamespaceRulesConfig RouteDeleteNamespaceRulesConfig RouteGetRulegGroupConfig RouteDeleteRuleGroupConfig // prom routes diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index e190f340130e..2755ae9bd696 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -828,7 +828,10 @@ "GettableSilence": { "$ref": "#/definitions/gettableSilence" }, - "GettableSilences": {}, + "GettableSilences": { + "$ref": "#/definitions/gettableSilences" + }, + "GettableStatus": {}, "GettableUserConfig": { "properties": { "alertmanager_config": { @@ -1589,7 +1592,6 @@ "x-go-package": "github.com/prometheus/alertmanager/config" }, "Receiver": { - "$ref": "#/definitions/receiver", "properties": { "email_configs": { "items": { @@ -2176,7 +2178,6 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "URL": { - "description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.", "properties": { "ForceQuery": { "type": "boolean" @@ -2209,9 +2210,9 @@ "$ref": "#/definitions/Userinfo" } }, - "title": "A URL represents a parsed URL (technically, a URI reference).", + "title": "URL is a custom URL type that allows validation at configuration load time.", "type": "object", - "x-go-package": "net/url" + "x-go-package": "github.com/prometheus/common/config" }, "Userinfo": { "description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.", @@ -2380,7 +2381,7 @@ "alerts": { "description": "alerts", "items": { - "$ref": "#/definitions/gettableAlert" + "$ref": "#/definitions/GettableAlert" }, "type": "array", "x-go-name": "Alerts" @@ -2404,7 +2405,7 @@ "alertGroups": { "description": "AlertGroups alert groups", "items": { - "$ref": "#/definitions/alertGroup" + "$ref": "#/definitions/AlertGroup" }, "type": "array", "x-go-name": "AlertGroups", @@ -3273,7 +3274,7 @@ "in": "body", "name": "Silence", "schema": { - "$ref": "#/definitions/postableSilence" + "$ref": "#/definitions/PostableSilence" } }, { @@ -3303,6 +3304,32 @@ ] } }, + "/api/alertmanager/{Recipient}/api/v2/status": { + "get": { + "description": "get alertmanager status and configuration", + "operationId": "RouteGetAMStatus", + "parameters": [ + { + "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", + "in": "path", + "name": "Recipient", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "GettableStatus", + "schema": { + "$ref": "#/definitions/GettableStatus" + } + } + }, + "tags": [ + "alertmanager" + ] + } + }, "/api/alertmanager/{Recipient}/config/api/v1/alerts": { "delete": { "description": "deletes the Alerting config for a tenant", diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index dc79ed526a7d..f567b2591cb5 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -327,7 +327,7 @@ "name": "Silence", "in": "body", "schema": { - "$ref": "#/definitions/postableSilence" + "$ref": "#/definitions/PostableSilence" } }, { @@ -354,6 +354,32 @@ } } }, + "/api/alertmanager/{Recipient}/api/v2/status": { + "get": { + "description": "get alertmanager status and configuration", + "tags": [ + "alertmanager" + ], + "operationId": "RouteGetAMStatus", + "parameters": [ + { + "type": "string", + "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", + "name": "Recipient", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "GettableStatus", + "schema": { + "$ref": "#/definitions/GettableStatus" + } + } + } + } + }, "/api/alertmanager/{Recipient}/config/api/v1/alerts": { "get": { "description": "gets an Alerting config", @@ -1641,7 +1667,10 @@ "$ref": "#/definitions/gettableSilence" }, "GettableSilences": { - "$ref": "#/definitions/GettableSilences" + "$ref": "#/definitions/gettableSilences" + }, + "GettableStatus": { + "$ref": "#/definitions/GettableStatus" }, "GettableUserConfig": { "type": "object", @@ -2471,7 +2500,7 @@ "x-go-name": "WechatConfigs" } }, - "$ref": "#/definitions/receiver" + "$ref": "#/definitions/Receiver" }, "Regexp": { "description": "A Regexp is safe for concurrent use by multiple goroutines,\nexcept for configuration methods, such as Longest.", @@ -2993,9 +3022,8 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "URL": { - "description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.", "type": "object", - "title": "A URL represents a parsed URL (technically, a URI reference).", + "title": "URL is a custom URL type that allows validation at configuration load time.", "properties": { "ForceQuery": { "type": "boolean" @@ -3028,7 +3056,7 @@ "$ref": "#/definitions/Userinfo" } }, - "x-go-package": "net/url" + "x-go-package": "github.com/prometheus/common/config" }, "Userinfo": { "description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.", @@ -3204,7 +3232,7 @@ "description": "alerts", "type": "array", "items": { - "$ref": "#/definitions/gettableAlert" + "$ref": "#/definitions/GettableAlert" }, "x-go-name": "Alerts" }, @@ -3222,7 +3250,7 @@ "description": "AlertGroups alert groups", "type": "array", "items": { - "$ref": "#/definitions/alertGroup" + "$ref": "#/definitions/AlertGroup" }, "x-go-name": "AlertGroups", "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" diff --git a/pkg/services/ngalert/notifier/status.go b/pkg/services/ngalert/notifier/status.go new file mode 100644 index 000000000000..8726166dcbe7 --- /dev/null +++ b/pkg/services/ngalert/notifier/status.go @@ -0,0 +1,22 @@ +package notifier + +import ( + "encoding/json" + + apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" +) + +func (am *Alertmanager) GetStatus() apimodels.GettableStatus { + am.reloadConfigMtx.RLock() + defer am.reloadConfigMtx.RUnlock() + + var amConfig apimodels.PostableApiAlertingConfig + if am.config != nil { + err := json.Unmarshal(am.config, &amConfig) + if err != nil { + // this should never error here, if the configuration is running it should be valid. + am.logger.Error("unable to marshal alertmanager configuration", "err", err) + } + } + return *apimodels.NewGettableStatus(&amConfig) +} diff --git a/pkg/tests/api/alerting/api_alertmanager_test.go b/pkg/tests/api/alerting/api_alertmanager_test.go index 184e5c3cb724..e01e4d401155 100644 --- a/pkg/tests/api/alerting/api_alertmanager_test.go +++ b/pkg/tests/api/alerting/api_alertmanager_test.go @@ -714,7 +714,7 @@ func TestAlertRuleCRUD(t *testing.T) { "annotations": { "annotation1": "val42", "foo": "bar" - }, + }, "expr":"", "for": "30s", "labels": { @@ -799,6 +799,71 @@ func TestAlertRuleCRUD(t *testing.T) { } } +func TestAlertmanagerStatus(t *testing.T) { + // Setup Grafana and its Database + dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{ + EnableFeatureToggles: []string{"ngalert"}, + }) + store := testinfra.SetUpDatabase(t, dir) + grafanaListedAddr := testinfra.StartGrafana(t, dir, path, store) + + // Get the Alertmanager current status. + { + alertsURL := fmt.Sprintf("http://%s/api/alertmanager/grafana/api/v2/status", grafanaListedAddr) + // nolint:gosec + resp, err := http.Get(alertsURL) + require.NoError(t, err) + t.Cleanup(func() { + err := resp.Body.Close() + require.NoError(t, err) + }) + b, err := ioutil.ReadAll(resp.Body) + require.NoError(t, err) + fmt.Println(string(b)) + require.Equal(t, 200, resp.StatusCode) + require.JSONEq(t, ` +{ + "cluster": { + "peers": [], + "status": "disabled" + }, + "config": { + "route": { + "receiver": "grafana-default-email" + }, + "templates": null, + "receivers": [{ + "name": "grafana-default-email", + "grafana_managed_receiver_configs": [{ + "uid": "", + "name": "email receiver", + "type": "email", + "sendReminder": false, + "disableResolveMessage": false, + "frequency": "", + "isDefault": true, + "settings": { + "addresses": "\u003cexample@email.com\u003e" + }, + "secureSettings": null, + "Result": null + }] + }] + }, + "uptime": null, + "versionInfo": { + "branch": "N/A", + "buildDate": "N/A", + "buildUser": "N/A", + "goVersion": "N/A", + "revision": "N/A", + "version": "N/A" + } +} +`, string(b)) + } +} + // createFolder creates a folder for storing our alerts under. Grafana uses folders as a replacement for alert namespaces to match its permission model. // We use the dashboard command using IsFolder = true to tell it's a folder, it takes the dashboard as the name of the folder. func createFolder(t *testing.T, store *sqlstore.SQLStore, folderID int64, folderName string) error { From 22ea8765d5fddf15bb1a284a94914e6559f39d23 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 31 May 2021 17:55:15 +0300 Subject: [PATCH 02/16] Add API examples --- .../ngalert/api/test-data/am-alertmanager-recipient.http | 4 ++++ .../ngalert/api/test-data/am-grafana-recipient.http | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/services/ngalert/api/test-data/am-alertmanager-recipient.http b/pkg/services/ngalert/api/test-data/am-alertmanager-recipient.http index ecd0d91b6889..6fc614fa31d6 100644 --- a/pkg/services/ngalert/api/test-data/am-alertmanager-recipient.http +++ b/pkg/services/ngalert/api/test-data/am-alertmanager-recipient.http @@ -96,6 +96,10 @@ content-type: application/json # get AM alerts GET http://admin:admin@localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/alerts +### +# get status +GET http://admin:admin@localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/status + ### # get AM alert groups GET http://admin:admin@localhost:3000/alertmanager/{{alertManagerDatasourceID}}/api/v2/alerts/groups diff --git a/pkg/services/ngalert/api/test-data/am-grafana-recipient.http b/pkg/services/ngalert/api/test-data/am-grafana-recipient.http index 3fff2ca569e9..00358e07660b 100644 --- a/pkg/services/ngalert/api/test-data/am-grafana-recipient.http +++ b/pkg/services/ngalert/api/test-data/am-grafana-recipient.http @@ -21,6 +21,14 @@ DELETE http://admin:admin@localhost:3000/api/alertmanager/{{grafana}}/config/api POST http://admin:admin@localhost:3000/api/alertmanager/{{grafana}}/api/v2/alerts content-type: application/json +### +# get AM alerts +GET http://admin:admin@localhost:3000/api/alertmanager/{{grafana}}/api/v2/alerts + +### +# get AM status +GET http://admin:admin@localhost:3000/api/alertmanager/{{grafana}}/api/v2/status + ### # get silences - no silences GET http://admin:admin@localhost:3000/api/alertmanager/{{grafana}}/api/v2/silences?Filter=foo="bar"&Filter=bar="foo" From dadd7d1e2761751af29f13e0a6ae039d2897d110 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 31 May 2021 18:42:38 +0300 Subject: [PATCH 03/16] Fix unmarshalling --- pkg/services/ngalert/api/api.go | 2 +- pkg/services/ngalert/api/api_alertmanager.go | 6 +++- .../api/tooling/definitions/alertmanager.go | 32 ++++++------------- pkg/services/ngalert/notifier/status.go | 4 +-- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/pkg/services/ngalert/api/api.go b/pkg/services/ngalert/api/api.go index fa614b82c1d1..9635bdee0440 100644 --- a/pkg/services/ngalert/api/api.go +++ b/pkg/services/ngalert/api/api.go @@ -25,7 +25,7 @@ var timeNow = time.Now type Alertmanager interface { // Configuration SaveAndApplyConfig(config *apimodels.PostableUserConfig) error - GetStatus() apimodels.GettableStatus + GetStatus() (*apimodels.GettableStatus, error) // Silences CreateSilence(ps *apimodels.PostableSilence) (string, error) diff --git a/pkg/services/ngalert/api/api_alertmanager.go b/pkg/services/ngalert/api/api_alertmanager.go index 53fb1ca8ac87..fb3dc7c35325 100644 --- a/pkg/services/ngalert/api/api_alertmanager.go +++ b/pkg/services/ngalert/api/api_alertmanager.go @@ -22,7 +22,11 @@ type AlertmanagerSrv struct { } func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Response { - return response.JSON(http.StatusOK, srv.am.GetStatus()) + st, err := srv.am.GetStatus() + if err != nil { + return ErrResp(http.StatusInternalServerError, err, "failed to get status") + } + return response.JSON(http.StatusOK, st) } func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSilence apimodels.PostableSilence) response.Response { diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index c34d6eaedeb6..df235b77715f 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -6,8 +6,6 @@ import ( "fmt" "reflect" - "github.com/go-openapi/strfmt" - "github.com/pkg/errors" amv2 "github.com/prometheus/alertmanager/api/v2/models" "github.com/prometheus/alertmanager/config" @@ -125,30 +123,19 @@ type GetSilencesParams struct { } // swagger:model -type GettableStatus struct { - // cluster - // Required: true - Cluster *amv2.ClusterStatus `json:"cluster"` - - // config - // Required: true - Config *PostableApiAlertingConfig `json:"config"` +type GettableStatus amv2.AlertmanagerStatus - // uptime - // Required: true - // Format: date-time - Uptime *strfmt.DateTime `json:"uptime"` - - // version info - // Required: true - VersionInfo *amv2.VersionInfo `json:"versionInfo"` -} +func NewGettableStatus(cfg *PostableApiAlertingConfig) (*GettableStatus, error) { + blob, err := json.Marshal(cfg) + if err != nil { + return nil, err + } + toString := string(blob) -func NewGettableStatus(cfg *PostableApiAlertingConfig) *GettableStatus { // In Grafana, the only field we support is Config. cs := amv2.ClusterStatusStatusDisabled na := "N/A" - return &GettableStatus{ + status := &GettableStatus{ Cluster: &amv2.ClusterStatus{ Status: &cs, Peers: []*amv2.PeerStatus{}, @@ -161,8 +148,9 @@ func NewGettableStatus(cfg *PostableApiAlertingConfig) *GettableStatus { Revision: &na, Version: &na, }, - Config: cfg, + Config: &amv2.AlertmanagerConfig{Original: &toString}, } + return status, nil } // swagger:model diff --git a/pkg/services/ngalert/notifier/status.go b/pkg/services/ngalert/notifier/status.go index 8726166dcbe7..724f0e4f2f5f 100644 --- a/pkg/services/ngalert/notifier/status.go +++ b/pkg/services/ngalert/notifier/status.go @@ -6,7 +6,7 @@ import ( apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" ) -func (am *Alertmanager) GetStatus() apimodels.GettableStatus { +func (am *Alertmanager) GetStatus() (*apimodels.GettableStatus, error) { am.reloadConfigMtx.RLock() defer am.reloadConfigMtx.RUnlock() @@ -18,5 +18,5 @@ func (am *Alertmanager) GetStatus() apimodels.GettableStatus { am.logger.Error("unable to marshal alertmanager configuration", "err", err) } } - return *apimodels.NewGettableStatus(&amConfig) + return apimodels.NewGettableStatus(&amConfig) } From f21f0149b7c0fd8932378877e67c974946264df0 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 31 May 2021 20:30:14 +0300 Subject: [PATCH 04/16] Update API specs --- pkg/services/ngalert/api/tooling/post.json | 323 +++++++++------------ pkg/services/ngalert/api/tooling/spec.json | 315 +++++++++----------- 2 files changed, 274 insertions(+), 364 deletions(-) diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index 43cb90e148cd..2abed258ee9e 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -60,7 +60,9 @@ "AlertGroup": { "$ref": "#/definitions/alertGroup" }, - "AlertGroups": {}, + "AlertGroups": { + "$ref": "#/definitions/alertGroups" + }, "AlertInstancesResponse": { "properties": { "instances": { @@ -79,65 +81,6 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "AlertNotification": { - "properties": { - "created": { - "format": "date-time", - "type": "string", - "x-go-name": "Created" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "$ref": "#/definitions/Duration", - "type": "string" - }, - "id": { - "format": "int64", - "type": "integer", - "x-go-name": "Id" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureFields": { - "additionalProperties": { - "type": "boolean" - }, - "type": "object", - "x-go-name": "SecureFields" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - }, - "updated": { - "format": "date-time", - "type": "string", - "x-go-name": "Updated" - } - }, - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/api/dtos" - }, "AlertQuery": { "properties": { "datasourceUid": { @@ -296,14 +239,16 @@ }, "Authorization": { "properties": { - "Credentials": { + "credentials": { "$ref": "#/definitions/Secret" }, - "CredentialsFile": { - "type": "string" + "credentials_file": { + "type": "string", + "x-go-name": "CredentialsFile" }, - "Type": { - "type": "string" + "type": { + "type": "string", + "x-go-name": "Type" } }, "title": "Authorization contains HTTP authorization credentials.", @@ -312,14 +257,16 @@ }, "BasicAuth": { "properties": { - "Password": { + "password": { "$ref": "#/definitions/Secret" }, - "PasswordFile": { - "type": "string" + "password_file": { + "type": "string", + "x-go-name": "PasswordFile" }, - "Username": { - "type": "string" + "username": { + "type": "string", + "x-go-name": "Username" } }, "title": "BasicAuth contains basic HTTP authentication credentials.", @@ -338,13 +285,6 @@ "type": "array", "x-go-name": "InhibitRules" }, - "receivers": { - "items": { - "$ref": "#/definitions/Receiver" - }, - "type": "array", - "x-go-name": "Receivers" - }, "route": { "$ref": "#/definitions/Route" }, @@ -360,53 +300,6 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "CreateAlertNotificationCommand": { - "properties": { - "Result": { - "$ref": "#/definitions/AlertNotification" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "type": "string", - "x-go-name": "Frequency" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureSettings": { - "additionalProperties": { - "type": "string" - }, - "type": "object", - "x-go-name": "SecureSettings" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - } - }, - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/models" - }, "DateTime": { "description": "DateTime is a time but it serializes to ISO8601 format with millis\nIt knows how to read 3 different variations of a RFC3339 date time.\nMost APIs we encounter want either millisecond or second precision times.\nThis just tries to make it worry-free.", "format": "date-time", @@ -585,7 +478,9 @@ "$ref": "#/definitions/ResponseDetails" }, "GettableAlert": {}, - "GettableAlerts": {}, + "GettableAlerts": { + "$ref": "#/definitions/gettableAlerts" + }, "GettableApiAlertingConfig": { "properties": { "global": { @@ -733,7 +628,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceiver": { - "$ref": "#/definitions/AlertNotification" + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureFields": { + "additionalProperties": { + "type": "boolean" + }, + "type": "object", + "x-go-name": "SecureFields" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceivers": { "properties": { @@ -763,8 +687,7 @@ }, "exec_err_state": { "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "type": "string", "x-go-name": "ExecErrState" @@ -792,7 +715,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "type": "string", @@ -855,7 +777,9 @@ "GettableSilences": { "$ref": "#/definitions/gettableSilences" }, - "GettableStatus": {}, + "GettableStatus": { + "$ref": "#/definitions/alertmanagerStatus" + }, "GettableUserConfig": { "properties": { "alertmanager_config": { @@ -948,30 +872,32 @@ }, "HTTPClientConfig": { "properties": { - "Authorization": { + "authorization": { "$ref": "#/definitions/Authorization" }, - "BasicAuth": { + "basic_auth": { "$ref": "#/definitions/BasicAuth" }, - "BearerToken": { + "bearer_token": { "$ref": "#/definitions/Secret" }, - "BearerTokenFile": { + "bearer_token_file": { "description": "The bearer token file for the targets. Deprecated in favour of\nAuthorization.CredentialsFile.", - "type": "string" + "type": "string", + "x-go-name": "BearerTokenFile" }, - "FollowRedirects": { + "follow_redirects": { "description": "FollowRedirects specifies whether the client should follow HTTP 3xx redirects.\nThe omitempty flag is not set, because it would be hidden from the\nmarshalled configuration when set to false.", - "type": "boolean" + "type": "boolean", + "x-go-name": "FollowRedirects" }, - "OAuth2": { + "oauth2": { "$ref": "#/definitions/OAuth2" }, - "ProxyURL": { + "proxy_url": { "$ref": "#/definitions/URL" }, - "TLSConfig": { + "tls_config": { "$ref": "#/definitions/TLSConfig" } }, @@ -1126,29 +1052,34 @@ }, "OAuth2": { "properties": { - "ClientID": { - "type": "string" + "client_id": { + "type": "string", + "x-go-name": "ClientID" }, - "ClientSecret": { + "client_secret": { "$ref": "#/definitions/Secret" }, - "ClientSecretFile": { - "type": "string" + "client_secret_file": { + "type": "string", + "x-go-name": "ClientSecretFile" }, - "EndpointParams": { + "endpoint_params": { "additionalProperties": { "type": "string" }, - "type": "object" + "type": "object", + "x-go-name": "EndpointParams" }, - "Scopes": { + "scopes": { "items": { "type": "string" }, - "type": "array" + "type": "array", + "x-go-name": "Scopes" }, - "TokenURL": { - "type": "string" + "token_url": { + "type": "string", + "x-go-name": "TokenURL" } }, "title": "OAuth2 is the oauth2 client configuration.", @@ -1505,7 +1436,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceiver": { - "$ref": "#/definitions/CreateAlertNotificationCommand" + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureSettings": { + "additionalProperties": { + "type": "string" + }, + "type": "object", + "x-go-name": "SecureSettings" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceivers": { "properties": { @@ -1535,8 +1495,7 @@ }, "exec_err_state": { "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "type": "string", "x-go-name": "ExecErrState" @@ -1545,7 +1504,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "type": "string", @@ -1583,7 +1541,9 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "PostableSilence": {}, + "PostableSilence": { + "$ref": "#/definitions/postableSilence" + }, "PostableUserConfig": { "properties": { "alertmanager_config": { @@ -1987,18 +1947,6 @@ "$ref": "#/definitions/URL", "title": "SecretURL is a URL that must not be revealed on marshaling." }, - "SecureJsonData": { - "additionalProperties": { - "items": { - "format": "uint8", - "type": "integer" - }, - "type": "array" - }, - "description": "SecureJsonData is used to store encrypted data (for example in data_source table). Only values are separately\nencrypted.", - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/components/securejsondata" - }, "SlackAction": { "description": "See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons\nfor more information.", "properties": { @@ -2192,25 +2140,30 @@ }, "TLSConfig": { "properties": { - "CAFile": { + "ca_file": { "description": "The CA cert to use for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CAFile" }, - "CertFile": { + "cert_file": { "description": "The client cert file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CertFile" }, - "InsecureSkipVerify": { + "insecure_skip_verify": { "description": "Disable target certificate validation.", - "type": "boolean" + "type": "boolean", + "x-go-name": "InsecureSkipVerify" }, - "KeyFile": { + "key_file": { "description": "The client key file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "KeyFile" }, - "ServerName": { + "server_name": { "description": "Used to verify the hostname for the targets.", - "type": "string" + "type": "string", + "x-go-name": "ServerName" } }, "title": "TLSConfig configures the options for TLS connections.", @@ -2450,7 +2403,7 @@ "alerts": { "description": "alerts", "items": { - "$ref": "#/definitions/GettableAlert" + "$ref": "#/definitions/gettableAlert" }, "type": "array", "x-go-name": "Alerts" @@ -2459,7 +2412,7 @@ "$ref": "#/definitions/labelSet" }, "receiver": { - "$ref": "#/definitions/receiver" + "$ref": "#/definitions/Receiver" } }, "required": [ @@ -2474,7 +2427,7 @@ "alertGroups": { "description": "AlertGroups alert groups", "items": { - "$ref": "#/definitions/AlertGroup" + "$ref": "#/definitions/alertGroup" }, "type": "array", "x-go-name": "AlertGroups", @@ -2626,7 +2579,7 @@ "receivers": { "description": "receivers", "items": { - "$ref": "#/definitions/Receiver" + "$ref": "#/definitions/receiver" }, "type": "array", "x-go-name": "Receivers" @@ -3392,6 +3345,12 @@ "schema": { "$ref": "#/definitions/GettableStatus" } + }, + "400": { + "description": "ValidationError", + "schema": { + "$ref": "#/definitions/ValidationError" + } } }, "tags": [ diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index c7bee668dd6b..9280bc8da2e8 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -376,6 +376,12 @@ "schema": { "$ref": "#/definitions/GettableStatus" } + }, + "400": { + "description": "ValidationError", + "schema": { + "$ref": "#/definitions/ValidationError" + } } } } @@ -924,7 +930,7 @@ "$ref": "#/definitions/alertGroup" }, "AlertGroups": { - "$ref": "#/definitions/AlertGroups" + "$ref": "#/definitions/alertGroups" }, "AlertInstancesResponse": { "type": "object", @@ -944,65 +950,6 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "AlertNotification": { - "type": "object", - "properties": { - "created": { - "type": "string", - "format": "date-time", - "x-go-name": "Created" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "type": "string", - "$ref": "#/definitions/Duration" - }, - "id": { - "type": "integer", - "format": "int64", - "x-go-name": "Id" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureFields": { - "type": "object", - "additionalProperties": { - "type": "boolean" - }, - "x-go-name": "SecureFields" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - }, - "updated": { - "type": "string", - "format": "date-time", - "x-go-name": "Updated" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/api/dtos" - }, "AlertQuery": { "type": "object", "title": "AlertQuery represents a single query associated with an alert definition.", @@ -1163,14 +1110,16 @@ "type": "object", "title": "Authorization contains HTTP authorization credentials.", "properties": { - "Credentials": { + "credentials": { "$ref": "#/definitions/Secret" }, - "CredentialsFile": { - "type": "string" + "credentials_file": { + "type": "string", + "x-go-name": "CredentialsFile" }, - "Type": { - "type": "string" + "type": { + "type": "string", + "x-go-name": "Type" } }, "x-go-package": "github.com/prometheus/common/config" @@ -1179,14 +1128,16 @@ "type": "object", "title": "BasicAuth contains basic HTTP authentication credentials.", "properties": { - "Password": { + "password": { "$ref": "#/definitions/Secret" }, - "PasswordFile": { - "type": "string" + "password_file": { + "type": "string", + "x-go-name": "PasswordFile" }, - "Username": { - "type": "string" + "username": { + "type": "string", + "x-go-name": "Username" } }, "x-go-package": "github.com/prometheus/common/config" @@ -1205,13 +1156,6 @@ }, "x-go-name": "InhibitRules" }, - "receivers": { - "type": "array", - "items": { - "$ref": "#/definitions/Receiver" - }, - "x-go-name": "Receivers" - }, "route": { "$ref": "#/definitions/Route" }, @@ -1225,53 +1169,6 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "CreateAlertNotificationCommand": { - "type": "object", - "properties": { - "Result": { - "$ref": "#/definitions/AlertNotification" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "type": "string", - "x-go-name": "Frequency" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureSettings": { - "type": "object", - "additionalProperties": { - "type": "string" - }, - "x-go-name": "SecureSettings" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/models" - }, "DateTime": { "description": "DateTime is a time but it serializes to ISO8601 format with millis\nIt knows how to read 3 different variations of a RFC3339 date time.\nMost APIs we encounter want either millisecond or second precision times.\nThis just tries to make it worry-free.", "type": "string", @@ -1456,7 +1353,7 @@ "$ref": "#/definitions/GettableAlert" }, "GettableAlerts": { - "$ref": "#/definitions/GettableAlerts" + "$ref": "#/definitions/gettableAlerts" }, "GettableApiAlertingConfig": { "type": "object", @@ -1605,7 +1502,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceiver": { - "$ref": "#/definitions/AlertNotification" + "type": "object", + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureFields": { + "type": "object", + "additionalProperties": { + "type": "boolean" + }, + "x-go-name": "SecureFields" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceivers": { "type": "object", @@ -1637,8 +1563,7 @@ "exec_err_state": { "type": "string", "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "x-go-name": "ExecErrState" }, @@ -1666,7 +1591,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "x-go-name": "NoDataState" @@ -1728,7 +1652,7 @@ "$ref": "#/definitions/gettableSilences" }, "GettableStatus": { - "$ref": "#/definitions/GettableStatus" + "$ref": "#/definitions/alertmanagerStatus" }, "GettableUserConfig": { "type": "object", @@ -1824,30 +1748,32 @@ "type": "object", "title": "HTTPClientConfig configures an HTTP client.", "properties": { - "Authorization": { + "authorization": { "$ref": "#/definitions/Authorization" }, - "BasicAuth": { + "basic_auth": { "$ref": "#/definitions/BasicAuth" }, - "BearerToken": { + "bearer_token": { "$ref": "#/definitions/Secret" }, - "BearerTokenFile": { + "bearer_token_file": { "description": "The bearer token file for the targets. Deprecated in favour of\nAuthorization.CredentialsFile.", - "type": "string" + "type": "string", + "x-go-name": "BearerTokenFile" }, - "FollowRedirects": { + "follow_redirects": { "description": "FollowRedirects specifies whether the client should follow HTTP 3xx redirects.\nThe omitempty flag is not set, because it would be hidden from the\nmarshalled configuration when set to false.", - "type": "boolean" + "type": "boolean", + "x-go-name": "FollowRedirects" }, - "OAuth2": { + "oauth2": { "$ref": "#/definitions/OAuth2" }, - "ProxyURL": { + "proxy_url": { "$ref": "#/definitions/URL" }, - "TLSConfig": { + "tls_config": { "$ref": "#/definitions/TLSConfig" } }, @@ -2003,29 +1929,34 @@ "type": "object", "title": "OAuth2 is the oauth2 client configuration.", "properties": { - "ClientID": { - "type": "string" + "client_id": { + "type": "string", + "x-go-name": "ClientID" }, - "ClientSecret": { + "client_secret": { "$ref": "#/definitions/Secret" }, - "ClientSecretFile": { - "type": "string" + "client_secret_file": { + "type": "string", + "x-go-name": "ClientSecretFile" }, - "EndpointParams": { + "endpoint_params": { "type": "object", "additionalProperties": { "type": "string" - } + }, + "x-go-name": "EndpointParams" }, - "Scopes": { + "scopes": { "type": "array", "items": { "type": "string" - } + }, + "x-go-name": "Scopes" }, - "TokenURL": { - "type": "string" + "token_url": { + "type": "string", + "x-go-name": "TokenURL" } }, "x-go-package": "github.com/prometheus/common/config" @@ -2380,7 +2311,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceiver": { - "$ref": "#/definitions/CreateAlertNotificationCommand" + "type": "object", + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureSettings": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "x-go-name": "SecureSettings" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceivers": { "type": "object", @@ -2412,8 +2372,7 @@ "exec_err_state": { "type": "string", "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "x-go-name": "ExecErrState" }, @@ -2422,7 +2381,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "x-go-name": "NoDataState" @@ -2459,7 +2417,7 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableSilence": { - "$ref": "#/definitions/PostableSilence" + "$ref": "#/definitions/postableSilence" }, "PostableUserConfig": { "type": "object", @@ -2865,18 +2823,6 @@ "title": "SecretURL is a URL that must not be revealed on marshaling.", "$ref": "#/definitions/URL" }, - "SecureJsonData": { - "description": "SecureJsonData is used to store encrypted data (for example in data_source table). Only values are separately\nencrypted.", - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/components/securejsondata" - }, "SlackAction": { "description": "See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons\nfor more information.", "type": "object", @@ -3072,25 +3018,30 @@ "type": "object", "title": "TLSConfig configures the options for TLS connections.", "properties": { - "CAFile": { + "ca_file": { "description": "The CA cert to use for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CAFile" }, - "CertFile": { + "cert_file": { "description": "The client cert file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CertFile" }, - "InsecureSkipVerify": { + "insecure_skip_verify": { "description": "Disable target certificate validation.", - "type": "boolean" + "type": "boolean", + "x-go-name": "InsecureSkipVerify" }, - "KeyFile": { + "key_file": { "description": "The client key file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "KeyFile" }, - "ServerName": { + "server_name": { "description": "Used to verify the hostname for the targets.", - "type": "string" + "type": "string", + "x-go-name": "ServerName" } }, "x-go-package": "github.com/prometheus/common/config" @@ -3335,7 +3286,7 @@ "description": "alerts", "type": "array", "items": { - "$ref": "#/definitions/GettableAlert" + "$ref": "#/definitions/gettableAlert" }, "x-go-name": "Alerts" }, @@ -3343,7 +3294,7 @@ "$ref": "#/definitions/labelSet" }, "receiver": { - "$ref": "#/definitions/receiver" + "$ref": "#/definitions/Receiver" } }, "x-go-name": "AlertGroup", @@ -3353,7 +3304,7 @@ "description": "AlertGroups alert groups", "type": "array", "items": { - "$ref": "#/definitions/AlertGroup" + "$ref": "#/definitions/alertGroup" }, "x-go-name": "AlertGroups", "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" @@ -3516,7 +3467,7 @@ "description": "receivers", "type": "array", "items": { - "$ref": "#/definitions/Receiver" + "$ref": "#/definitions/receiver" }, "x-go-name": "Receivers" }, From f9eeb6e93c730b2c3601a56e1998672069be065f Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 31 May 2021 20:41:40 +0300 Subject: [PATCH 05/16] Delete temp files accidentally commited --- .../api/generated_base_api_alertmanager.go-e | 151 ------------------ .../api/generated_base_api_prometheus.go-e | 49 ------ .../ngalert/api/generated_base_api_ruler.go-e | 94 ----------- .../api/generated_base_api_testing.go-e | 63 -------- 4 files changed, 357 deletions(-) delete mode 100644 pkg/services/ngalert/api/generated_base_api_alertmanager.go-e delete mode 100644 pkg/services/ngalert/api/generated_base_api_prometheus.go-e delete mode 100644 pkg/services/ngalert/api/generated_base_api_ruler.go-e delete mode 100644 pkg/services/ngalert/api/generated_base_api_testing.go-e diff --git a/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e b/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e deleted file mode 100644 index 46930dc91554..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e +++ /dev/null @@ -1,151 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type AlertmanagerApiService interface { - RouteCreateSilence(*models.ReqContext, apimodels.PostableSilence) response.Response - RouteDeleteAlertingConfig(*models.ReqContext) response.Response - RouteDeleteSilence(*models.ReqContext) response.Response - RouteGetAMAlertGroups(*models.ReqContext) response.Response - RouteGetAMAlerts(*models.ReqContext) response.Response - RouteGetAMStatus(*models.ReqContext) response.Response - RouteGetAlertingConfig(*models.ReqContext) response.Response - RouteGetSilence(*models.ReqContext) response.Response - RouteGetSilences(*models.ReqContext) response.Response - RoutePostAMAlerts(*models.ReqContext, apimodels.PostableAlerts) response.Response - RoutePostAlertingConfig(*models.ReqContext, apimodels.PostableUserConfig) response.Response -} - -func (api *API) RegisterAlertmanagerApiEndpoints(srv AlertmanagerApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Post( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silences"), - binding.Bind(apimodels.PostableSilence{}), - metrics.Instrument( - http.MethodPost, - "/api/alertmanager/{Recipient}/api/v2/silences", - srv.RouteCreateSilence, - m, - ), - ) - group.Delete( - toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), - metrics.Instrument( - http.MethodDelete, - "/api/alertmanager/{Recipient}/config/api/v1/alerts", - srv.RouteDeleteAlertingConfig, - m, - ), - ) - group.Delete( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), - metrics.Instrument( - http.MethodDelete, - "/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}", - srv.RouteDeleteSilence, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts/groups"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/alerts/groups", - srv.RouteGetAMAlertGroups, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/alerts", - srv.RouteGetAMAlerts, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/status"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/status", - srv.RouteGetAMStatus, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/config/api/v1/alerts", - srv.RouteGetAlertingConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}", - srv.RouteGetSilence, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silences"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/silences", - srv.RouteGetSilences, - m, - ), - ) - group.Post( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts"), - binding.Bind(apimodels.PostableAlerts{}), - metrics.Instrument( - http.MethodPost, - "/api/alertmanager/{Recipient}/api/v2/alerts", - srv.RoutePostAMAlerts, - m, - ), - ) - group.Post( - toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), - binding.Bind(apimodels.PostableUserConfig{}), - metrics.Instrument( - http.MethodPost, - "/api/alertmanager/{Recipient}/config/api/v1/alerts", - srv.RoutePostAlertingConfig, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - - - - - - - - - - diff --git a/pkg/services/ngalert/api/generated_base_api_prometheus.go-e b/pkg/services/ngalert/api/generated_base_api_prometheus.go-e deleted file mode 100644 index 85227a5efd79..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_prometheus.go-e +++ /dev/null @@ -1,49 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type PrometheusApiService interface { - RouteGetAlertStatuses(*models.ReqContext) response.Response - RouteGetRuleStatuses(*models.ReqContext) response.Response -} - -func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Get( - toMacaronPath("/api/prometheus/{Recipient}/api/v1/alerts"), - metrics.Instrument( - http.MethodGet, - "/api/prometheus/{Recipient}/api/v1/alerts", - srv.RouteGetAlertStatuses, - m, - ), - ) - group.Get( - toMacaronPath("/api/prometheus/{Recipient}/api/v1/rules"), - metrics.Instrument( - http.MethodGet, - "/api/prometheus/{Recipient}/api/v1/rules", - srv.RouteGetRuleStatuses, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - diff --git a/pkg/services/ngalert/api/generated_base_api_ruler.go-e b/pkg/services/ngalert/api/generated_base_api_ruler.go-e deleted file mode 100644 index aee3d8fa9ef5..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_ruler.go-e +++ /dev/null @@ -1,94 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type RulerApiService interface { - RouteDeleteNamespaceRulesConfig(*models.ReqContext) response.Response - RouteDeleteRuleGroupConfig(*models.ReqContext) response.Response - RouteGetNamespaceRulesConfig(*models.ReqContext) response.Response - RouteGetRulegGroupConfig(*models.ReqContext) response.Response - RouteGetRulesConfig(*models.ReqContext) response.Response - RoutePostNameRulesConfig(*models.ReqContext, apimodels.PostableRuleGroupConfig) response.Response -} - -func (api *API) RegisterRulerApiEndpoints(srv RulerApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Delete( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), - metrics.Instrument( - http.MethodDelete, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", - srv.RouteDeleteNamespaceRulesConfig, - m, - ), - ) - group.Delete( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}"), - metrics.Instrument( - http.MethodDelete, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}", - srv.RouteDeleteRuleGroupConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), - metrics.Instrument( - http.MethodGet, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", - srv.RouteGetNamespaceRulesConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}"), - metrics.Instrument( - http.MethodGet, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}", - srv.RouteGetRulegGroupConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules"), - metrics.Instrument( - http.MethodGet, - "/api/ruler/{Recipient}/api/v1/rules", - srv.RouteGetRulesConfig, - m, - ), - ) - group.Post( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), - binding.Bind(apimodels.PostableRuleGroupConfig{}), - metrics.Instrument( - http.MethodPost, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", - srv.RoutePostNameRulesConfig, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - - - - - diff --git a/pkg/services/ngalert/api/generated_base_api_testing.go-e b/pkg/services/ngalert/api/generated_base_api_testing.go-e deleted file mode 100644 index d07f83749bce..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_testing.go-e +++ /dev/null @@ -1,63 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type TestingApiService interface { - RouteEvalQueries(*models.ReqContext, apimodels.EvalQueriesPayload) response.Response - RouteTestReceiverConfig(*models.ReqContext, apimodels.ExtendedReceiver) response.Response - RouteTestRuleConfig(*models.ReqContext, apimodels.TestRulePayload) response.Response -} - -func (api *API) RegisterTestingApiEndpoints(srv TestingApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Post( - toMacaronPath("/api/v1/eval"), - binding.Bind(apimodels.EvalQueriesPayload{}), - metrics.Instrument( - http.MethodPost, - "/api/v1/eval", - srv.RouteEvalQueries, - m, - ), - ) - group.Post( - toMacaronPath("/api/v1/receiver/test/{Recipient}"), - binding.Bind(apimodels.ExtendedReceiver{}), - metrics.Instrument( - http.MethodPost, - "/api/v1/receiver/test/{Recipient}", - srv.RouteTestReceiverConfig, - m, - ), - ) - group.Post( - toMacaronPath("/api/v1/rule/test/{Recipient}"), - binding.Bind(apimodels.TestRulePayload{}), - metrics.Instrument( - http.MethodPost, - "/api/v1/rule/test/{Recipient}", - srv.RouteTestRuleConfig, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - - From ef93a672ca02fc7507c118d6a027afb822b90171 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 31 May 2021 20:45:30 +0300 Subject: [PATCH 06/16] Fix test --- .../api/alerting/api_alertmanager_test.go | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/pkg/tests/api/alerting/api_alertmanager_test.go b/pkg/tests/api/alerting/api_alertmanager_test.go index 23b355957b12..2d760d51e1cb 100644 --- a/pkg/tests/api/alerting/api_alertmanager_test.go +++ b/pkg/tests/api/alerting/api_alertmanager_test.go @@ -1462,23 +1462,7 @@ func TestAlertmanagerStatus(t *testing.T) { "status": "disabled" }, "config": { - "route": { - "receiver": "grafana-default-email" - }, - "templates": null, - "receivers": [{ - "name": "grafana-default-email", - "grafana_managed_receiver_configs": [{ - "uid": "", - "name": "email receiver", - "type": "email", - "disableResolveMessage": false, - "settings": { - "addresses": "\u003cexample@email.com\u003e" - }, - "secureSettings": null - }] - }] + "original": "{\"route\":{\"receiver\":\"grafana-default-email\"},\"templates\":null,\"receivers\":[{\"name\":\"grafana-default-email\",\"grafana_managed_receiver_configs\":[{\"uid\":\"\",\"name\":\"email receiver\",\"type\":\"email\",\"disableResolveMessage\":false,\"settings\":{\"addresses\":\"\\u003cexample@email.com\\u003e\"},\"secureSettings\":null}]}]}" }, "uptime": null, "versionInfo": { From 275dd0f05b021307158e6051305f3a5d8025042b Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Thu, 3 Jun 2021 13:05:45 +0300 Subject: [PATCH 07/16] Revert "Fix test" This reverts commit ef93a672ca02fc7507c118d6a027afb822b90171. --- .../api/alerting/api_alertmanager_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/tests/api/alerting/api_alertmanager_test.go b/pkg/tests/api/alerting/api_alertmanager_test.go index 2d760d51e1cb..23b355957b12 100644 --- a/pkg/tests/api/alerting/api_alertmanager_test.go +++ b/pkg/tests/api/alerting/api_alertmanager_test.go @@ -1462,7 +1462,23 @@ func TestAlertmanagerStatus(t *testing.T) { "status": "disabled" }, "config": { - "original": "{\"route\":{\"receiver\":\"grafana-default-email\"},\"templates\":null,\"receivers\":[{\"name\":\"grafana-default-email\",\"grafana_managed_receiver_configs\":[{\"uid\":\"\",\"name\":\"email receiver\",\"type\":\"email\",\"disableResolveMessage\":false,\"settings\":{\"addresses\":\"\\u003cexample@email.com\\u003e\"},\"secureSettings\":null}]}]}" + "route": { + "receiver": "grafana-default-email" + }, + "templates": null, + "receivers": [{ + "name": "grafana-default-email", + "grafana_managed_receiver_configs": [{ + "uid": "", + "name": "email receiver", + "type": "email", + "disableResolveMessage": false, + "settings": { + "addresses": "\u003cexample@email.com\u003e" + }, + "secureSettings": null + }] + }] }, "uptime": null, "versionInfo": { From 5da44ea40f57ef0a570aef0185ade2a636c0fcda Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Thu, 3 Jun 2021 13:05:57 +0300 Subject: [PATCH 08/16] Revert "Delete temp files accidentally commited" This reverts commit f9eeb6e93c730b2c3601a56e1998672069be065f. --- .../api/generated_base_api_alertmanager.go-e | 151 ++++++++++++++++++ .../api/generated_base_api_prometheus.go-e | 49 ++++++ .../ngalert/api/generated_base_api_ruler.go-e | 94 +++++++++++ .../api/generated_base_api_testing.go-e | 63 ++++++++ 4 files changed, 357 insertions(+) create mode 100644 pkg/services/ngalert/api/generated_base_api_alertmanager.go-e create mode 100644 pkg/services/ngalert/api/generated_base_api_prometheus.go-e create mode 100644 pkg/services/ngalert/api/generated_base_api_ruler.go-e create mode 100644 pkg/services/ngalert/api/generated_base_api_testing.go-e diff --git a/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e b/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e new file mode 100644 index 000000000000..46930dc91554 --- /dev/null +++ b/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e @@ -0,0 +1,151 @@ +/*Package api contains base API implementation of unified alerting + * + *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + * + *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. + */ + +package api + +import ( + "github.com/go-macaron/binding" + + "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/models" + apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "github.com/grafana/grafana/pkg/services/ngalert/metrics" + "github.com/grafana/grafana/pkg/middleware" +) + +type AlertmanagerApiService interface { + RouteCreateSilence(*models.ReqContext, apimodels.PostableSilence) response.Response + RouteDeleteAlertingConfig(*models.ReqContext) response.Response + RouteDeleteSilence(*models.ReqContext) response.Response + RouteGetAMAlertGroups(*models.ReqContext) response.Response + RouteGetAMAlerts(*models.ReqContext) response.Response + RouteGetAMStatus(*models.ReqContext) response.Response + RouteGetAlertingConfig(*models.ReqContext) response.Response + RouteGetSilence(*models.ReqContext) response.Response + RouteGetSilences(*models.ReqContext) response.Response + RoutePostAMAlerts(*models.ReqContext, apimodels.PostableAlerts) response.Response + RoutePostAlertingConfig(*models.ReqContext, apimodels.PostableUserConfig) response.Response +} + +func (api *API) RegisterAlertmanagerApiEndpoints(srv AlertmanagerApiService, m *metrics.Metrics) { + api.RouteRegister.Group("", func(group routing.RouteRegister){ + group.Post( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silences"), + binding.Bind(apimodels.PostableSilence{}), + metrics.Instrument( + http.MethodPost, + "/api/alertmanager/{Recipient}/api/v2/silences", + srv.RouteCreateSilence, + m, + ), + ) + group.Delete( + toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), + metrics.Instrument( + http.MethodDelete, + "/api/alertmanager/{Recipient}/config/api/v1/alerts", + srv.RouteDeleteAlertingConfig, + m, + ), + ) + group.Delete( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), + metrics.Instrument( + http.MethodDelete, + "/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}", + srv.RouteDeleteSilence, + m, + ), + ) + group.Get( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts/groups"), + metrics.Instrument( + http.MethodGet, + "/api/alertmanager/{Recipient}/api/v2/alerts/groups", + srv.RouteGetAMAlertGroups, + m, + ), + ) + group.Get( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts"), + metrics.Instrument( + http.MethodGet, + "/api/alertmanager/{Recipient}/api/v2/alerts", + srv.RouteGetAMAlerts, + m, + ), + ) + group.Get( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/status"), + metrics.Instrument( + http.MethodGet, + "/api/alertmanager/{Recipient}/api/v2/status", + srv.RouteGetAMStatus, + m, + ), + ) + group.Get( + toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), + metrics.Instrument( + http.MethodGet, + "/api/alertmanager/{Recipient}/config/api/v1/alerts", + srv.RouteGetAlertingConfig, + m, + ), + ) + group.Get( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), + metrics.Instrument( + http.MethodGet, + "/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}", + srv.RouteGetSilence, + m, + ), + ) + group.Get( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silences"), + metrics.Instrument( + http.MethodGet, + "/api/alertmanager/{Recipient}/api/v2/silences", + srv.RouteGetSilences, + m, + ), + ) + group.Post( + toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts"), + binding.Bind(apimodels.PostableAlerts{}), + metrics.Instrument( + http.MethodPost, + "/api/alertmanager/{Recipient}/api/v2/alerts", + srv.RoutePostAMAlerts, + m, + ), + ) + group.Post( + toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), + binding.Bind(apimodels.PostableUserConfig{}), + metrics.Instrument( + http.MethodPost, + "/api/alertmanager/{Recipient}/config/api/v1/alerts", + srv.RoutePostAlertingConfig, + m, + ), + ) + }, middleware.ReqSignedIn) +} + + + + + + + + + + + diff --git a/pkg/services/ngalert/api/generated_base_api_prometheus.go-e b/pkg/services/ngalert/api/generated_base_api_prometheus.go-e new file mode 100644 index 000000000000..85227a5efd79 --- /dev/null +++ b/pkg/services/ngalert/api/generated_base_api_prometheus.go-e @@ -0,0 +1,49 @@ +/*Package api contains base API implementation of unified alerting + * + *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + * + *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. + */ + +package api + +import ( + "github.com/go-macaron/binding" + + "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/models" + apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "github.com/grafana/grafana/pkg/services/ngalert/metrics" + "github.com/grafana/grafana/pkg/middleware" +) + +type PrometheusApiService interface { + RouteGetAlertStatuses(*models.ReqContext) response.Response + RouteGetRuleStatuses(*models.ReqContext) response.Response +} + +func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApiService, m *metrics.Metrics) { + api.RouteRegister.Group("", func(group routing.RouteRegister){ + group.Get( + toMacaronPath("/api/prometheus/{Recipient}/api/v1/alerts"), + metrics.Instrument( + http.MethodGet, + "/api/prometheus/{Recipient}/api/v1/alerts", + srv.RouteGetAlertStatuses, + m, + ), + ) + group.Get( + toMacaronPath("/api/prometheus/{Recipient}/api/v1/rules"), + metrics.Instrument( + http.MethodGet, + "/api/prometheus/{Recipient}/api/v1/rules", + srv.RouteGetRuleStatuses, + m, + ), + ) + }, middleware.ReqSignedIn) +} + + diff --git a/pkg/services/ngalert/api/generated_base_api_ruler.go-e b/pkg/services/ngalert/api/generated_base_api_ruler.go-e new file mode 100644 index 000000000000..aee3d8fa9ef5 --- /dev/null +++ b/pkg/services/ngalert/api/generated_base_api_ruler.go-e @@ -0,0 +1,94 @@ +/*Package api contains base API implementation of unified alerting + * + *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + * + *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. + */ + +package api + +import ( + "github.com/go-macaron/binding" + + "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/models" + apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "github.com/grafana/grafana/pkg/services/ngalert/metrics" + "github.com/grafana/grafana/pkg/middleware" +) + +type RulerApiService interface { + RouteDeleteNamespaceRulesConfig(*models.ReqContext) response.Response + RouteDeleteRuleGroupConfig(*models.ReqContext) response.Response + RouteGetNamespaceRulesConfig(*models.ReqContext) response.Response + RouteGetRulegGroupConfig(*models.ReqContext) response.Response + RouteGetRulesConfig(*models.ReqContext) response.Response + RoutePostNameRulesConfig(*models.ReqContext, apimodels.PostableRuleGroupConfig) response.Response +} + +func (api *API) RegisterRulerApiEndpoints(srv RulerApiService, m *metrics.Metrics) { + api.RouteRegister.Group("", func(group routing.RouteRegister){ + group.Delete( + toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), + metrics.Instrument( + http.MethodDelete, + "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", + srv.RouteDeleteNamespaceRulesConfig, + m, + ), + ) + group.Delete( + toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}"), + metrics.Instrument( + http.MethodDelete, + "/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}", + srv.RouteDeleteRuleGroupConfig, + m, + ), + ) + group.Get( + toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), + metrics.Instrument( + http.MethodGet, + "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", + srv.RouteGetNamespaceRulesConfig, + m, + ), + ) + group.Get( + toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}"), + metrics.Instrument( + http.MethodGet, + "/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}", + srv.RouteGetRulegGroupConfig, + m, + ), + ) + group.Get( + toMacaronPath("/api/ruler/{Recipient}/api/v1/rules"), + metrics.Instrument( + http.MethodGet, + "/api/ruler/{Recipient}/api/v1/rules", + srv.RouteGetRulesConfig, + m, + ), + ) + group.Post( + toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), + binding.Bind(apimodels.PostableRuleGroupConfig{}), + metrics.Instrument( + http.MethodPost, + "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", + srv.RoutePostNameRulesConfig, + m, + ), + ) + }, middleware.ReqSignedIn) +} + + + + + + diff --git a/pkg/services/ngalert/api/generated_base_api_testing.go-e b/pkg/services/ngalert/api/generated_base_api_testing.go-e new file mode 100644 index 000000000000..d07f83749bce --- /dev/null +++ b/pkg/services/ngalert/api/generated_base_api_testing.go-e @@ -0,0 +1,63 @@ +/*Package api contains base API implementation of unified alerting + * + *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + * + *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. + */ + +package api + +import ( + "github.com/go-macaron/binding" + + "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/models" + apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "github.com/grafana/grafana/pkg/services/ngalert/metrics" + "github.com/grafana/grafana/pkg/middleware" +) + +type TestingApiService interface { + RouteEvalQueries(*models.ReqContext, apimodels.EvalQueriesPayload) response.Response + RouteTestReceiverConfig(*models.ReqContext, apimodels.ExtendedReceiver) response.Response + RouteTestRuleConfig(*models.ReqContext, apimodels.TestRulePayload) response.Response +} + +func (api *API) RegisterTestingApiEndpoints(srv TestingApiService, m *metrics.Metrics) { + api.RouteRegister.Group("", func(group routing.RouteRegister){ + group.Post( + toMacaronPath("/api/v1/eval"), + binding.Bind(apimodels.EvalQueriesPayload{}), + metrics.Instrument( + http.MethodPost, + "/api/v1/eval", + srv.RouteEvalQueries, + m, + ), + ) + group.Post( + toMacaronPath("/api/v1/receiver/test/{Recipient}"), + binding.Bind(apimodels.ExtendedReceiver{}), + metrics.Instrument( + http.MethodPost, + "/api/v1/receiver/test/{Recipient}", + srv.RouteTestReceiverConfig, + m, + ), + ) + group.Post( + toMacaronPath("/api/v1/rule/test/{Recipient}"), + binding.Bind(apimodels.TestRulePayload{}), + metrics.Instrument( + http.MethodPost, + "/api/v1/rule/test/{Recipient}", + srv.RouteTestRuleConfig, + m, + ), + ) + }, middleware.ReqSignedIn) +} + + + From 275bd4766c4000b6886b92817380f20a8a668e1d Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Thu, 3 Jun 2021 13:06:05 +0300 Subject: [PATCH 09/16] Revert "Update API specs" This reverts commit f21f0149b7c0fd8932378877e67c974946264df0. --- pkg/services/ngalert/api/tooling/post.json | 323 ++++++++++++--------- pkg/services/ngalert/api/tooling/spec.json | 315 +++++++++++--------- 2 files changed, 364 insertions(+), 274 deletions(-) diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index 2abed258ee9e..43cb90e148cd 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -60,9 +60,7 @@ "AlertGroup": { "$ref": "#/definitions/alertGroup" }, - "AlertGroups": { - "$ref": "#/definitions/alertGroups" - }, + "AlertGroups": {}, "AlertInstancesResponse": { "properties": { "instances": { @@ -81,6 +79,65 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "AlertNotification": { + "properties": { + "created": { + "format": "date-time", + "type": "string", + "x-go-name": "Created" + }, + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "frequency": { + "$ref": "#/definitions/Duration", + "type": "string" + }, + "id": { + "format": "int64", + "type": "integer", + "x-go-name": "Id" + }, + "isDefault": { + "type": "boolean", + "x-go-name": "IsDefault" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureFields": { + "additionalProperties": { + "type": "boolean" + }, + "type": "object", + "x-go-name": "SecureFields" + }, + "sendReminder": { + "type": "boolean", + "x-go-name": "SendReminder" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "Uid" + }, + "updated": { + "format": "date-time", + "type": "string", + "x-go-name": "Updated" + } + }, + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/api/dtos" + }, "AlertQuery": { "properties": { "datasourceUid": { @@ -239,16 +296,14 @@ }, "Authorization": { "properties": { - "credentials": { + "Credentials": { "$ref": "#/definitions/Secret" }, - "credentials_file": { - "type": "string", - "x-go-name": "CredentialsFile" + "CredentialsFile": { + "type": "string" }, - "type": { - "type": "string", - "x-go-name": "Type" + "Type": { + "type": "string" } }, "title": "Authorization contains HTTP authorization credentials.", @@ -257,16 +312,14 @@ }, "BasicAuth": { "properties": { - "password": { + "Password": { "$ref": "#/definitions/Secret" }, - "password_file": { - "type": "string", - "x-go-name": "PasswordFile" + "PasswordFile": { + "type": "string" }, - "username": { - "type": "string", - "x-go-name": "Username" + "Username": { + "type": "string" } }, "title": "BasicAuth contains basic HTTP authentication credentials.", @@ -285,6 +338,13 @@ "type": "array", "x-go-name": "InhibitRules" }, + "receivers": { + "items": { + "$ref": "#/definitions/Receiver" + }, + "type": "array", + "x-go-name": "Receivers" + }, "route": { "$ref": "#/definitions/Route" }, @@ -300,6 +360,53 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "CreateAlertNotificationCommand": { + "properties": { + "Result": { + "$ref": "#/definitions/AlertNotification" + }, + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "frequency": { + "type": "string", + "x-go-name": "Frequency" + }, + "isDefault": { + "type": "boolean", + "x-go-name": "IsDefault" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureSettings": { + "additionalProperties": { + "type": "string" + }, + "type": "object", + "x-go-name": "SecureSettings" + }, + "sendReminder": { + "type": "boolean", + "x-go-name": "SendReminder" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "Uid" + } + }, + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/models" + }, "DateTime": { "description": "DateTime is a time but it serializes to ISO8601 format with millis\nIt knows how to read 3 different variations of a RFC3339 date time.\nMost APIs we encounter want either millisecond or second precision times.\nThis just tries to make it worry-free.", "format": "date-time", @@ -478,9 +585,7 @@ "$ref": "#/definitions/ResponseDetails" }, "GettableAlert": {}, - "GettableAlerts": { - "$ref": "#/definitions/gettableAlerts" - }, + "GettableAlerts": {}, "GettableApiAlertingConfig": { "properties": { "global": { @@ -628,36 +733,7 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceiver": { - "properties": { - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureFields": { - "additionalProperties": { - "type": "boolean" - }, - "type": "object", - "x-go-name": "SecureFields" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "UID" - } - }, - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "$ref": "#/definitions/AlertNotification" }, "GettableGrafanaReceivers": { "properties": { @@ -687,7 +763,8 @@ }, "exec_err_state": { "enum": [ - "Alerting" + "Alerting", + "KeepLastState" ], "type": "string", "x-go-name": "ExecErrState" @@ -715,6 +792,7 @@ "enum": [ "Alerting", "NoData", + "KeepLastState", "OK" ], "type": "string", @@ -777,9 +855,7 @@ "GettableSilences": { "$ref": "#/definitions/gettableSilences" }, - "GettableStatus": { - "$ref": "#/definitions/alertmanagerStatus" - }, + "GettableStatus": {}, "GettableUserConfig": { "properties": { "alertmanager_config": { @@ -872,32 +948,30 @@ }, "HTTPClientConfig": { "properties": { - "authorization": { + "Authorization": { "$ref": "#/definitions/Authorization" }, - "basic_auth": { + "BasicAuth": { "$ref": "#/definitions/BasicAuth" }, - "bearer_token": { + "BearerToken": { "$ref": "#/definitions/Secret" }, - "bearer_token_file": { + "BearerTokenFile": { "description": "The bearer token file for the targets. Deprecated in favour of\nAuthorization.CredentialsFile.", - "type": "string", - "x-go-name": "BearerTokenFile" + "type": "string" }, - "follow_redirects": { + "FollowRedirects": { "description": "FollowRedirects specifies whether the client should follow HTTP 3xx redirects.\nThe omitempty flag is not set, because it would be hidden from the\nmarshalled configuration when set to false.", - "type": "boolean", - "x-go-name": "FollowRedirects" + "type": "boolean" }, - "oauth2": { + "OAuth2": { "$ref": "#/definitions/OAuth2" }, - "proxy_url": { + "ProxyURL": { "$ref": "#/definitions/URL" }, - "tls_config": { + "TLSConfig": { "$ref": "#/definitions/TLSConfig" } }, @@ -1052,34 +1126,29 @@ }, "OAuth2": { "properties": { - "client_id": { - "type": "string", - "x-go-name": "ClientID" + "ClientID": { + "type": "string" }, - "client_secret": { + "ClientSecret": { "$ref": "#/definitions/Secret" }, - "client_secret_file": { - "type": "string", - "x-go-name": "ClientSecretFile" + "ClientSecretFile": { + "type": "string" }, - "endpoint_params": { + "EndpointParams": { "additionalProperties": { "type": "string" }, - "type": "object", - "x-go-name": "EndpointParams" + "type": "object" }, - "scopes": { + "Scopes": { "items": { "type": "string" }, - "type": "array", - "x-go-name": "Scopes" + "type": "array" }, - "token_url": { - "type": "string", - "x-go-name": "TokenURL" + "TokenURL": { + "type": "string" } }, "title": "OAuth2 is the oauth2 client configuration.", @@ -1436,36 +1505,7 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceiver": { - "properties": { - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureSettings": { - "additionalProperties": { - "type": "string" - }, - "type": "object", - "x-go-name": "SecureSettings" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "UID" - } - }, - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "$ref": "#/definitions/CreateAlertNotificationCommand" }, "PostableGrafanaReceivers": { "properties": { @@ -1495,7 +1535,8 @@ }, "exec_err_state": { "enum": [ - "Alerting" + "Alerting", + "KeepLastState" ], "type": "string", "x-go-name": "ExecErrState" @@ -1504,6 +1545,7 @@ "enum": [ "Alerting", "NoData", + "KeepLastState", "OK" ], "type": "string", @@ -1541,9 +1583,7 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "PostableSilence": { - "$ref": "#/definitions/postableSilence" - }, + "PostableSilence": {}, "PostableUserConfig": { "properties": { "alertmanager_config": { @@ -1947,6 +1987,18 @@ "$ref": "#/definitions/URL", "title": "SecretURL is a URL that must not be revealed on marshaling." }, + "SecureJsonData": { + "additionalProperties": { + "items": { + "format": "uint8", + "type": "integer" + }, + "type": "array" + }, + "description": "SecureJsonData is used to store encrypted data (for example in data_source table). Only values are separately\nencrypted.", + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/components/securejsondata" + }, "SlackAction": { "description": "See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons\nfor more information.", "properties": { @@ -2140,30 +2192,25 @@ }, "TLSConfig": { "properties": { - "ca_file": { + "CAFile": { "description": "The CA cert to use for the targets.", - "type": "string", - "x-go-name": "CAFile" + "type": "string" }, - "cert_file": { + "CertFile": { "description": "The client cert file for the targets.", - "type": "string", - "x-go-name": "CertFile" + "type": "string" }, - "insecure_skip_verify": { + "InsecureSkipVerify": { "description": "Disable target certificate validation.", - "type": "boolean", - "x-go-name": "InsecureSkipVerify" + "type": "boolean" }, - "key_file": { + "KeyFile": { "description": "The client key file for the targets.", - "type": "string", - "x-go-name": "KeyFile" + "type": "string" }, - "server_name": { + "ServerName": { "description": "Used to verify the hostname for the targets.", - "type": "string", - "x-go-name": "ServerName" + "type": "string" } }, "title": "TLSConfig configures the options for TLS connections.", @@ -2403,7 +2450,7 @@ "alerts": { "description": "alerts", "items": { - "$ref": "#/definitions/gettableAlert" + "$ref": "#/definitions/GettableAlert" }, "type": "array", "x-go-name": "Alerts" @@ -2412,7 +2459,7 @@ "$ref": "#/definitions/labelSet" }, "receiver": { - "$ref": "#/definitions/Receiver" + "$ref": "#/definitions/receiver" } }, "required": [ @@ -2427,7 +2474,7 @@ "alertGroups": { "description": "AlertGroups alert groups", "items": { - "$ref": "#/definitions/alertGroup" + "$ref": "#/definitions/AlertGroup" }, "type": "array", "x-go-name": "AlertGroups", @@ -2579,7 +2626,7 @@ "receivers": { "description": "receivers", "items": { - "$ref": "#/definitions/receiver" + "$ref": "#/definitions/Receiver" }, "type": "array", "x-go-name": "Receivers" @@ -3345,12 +3392,6 @@ "schema": { "$ref": "#/definitions/GettableStatus" } - }, - "400": { - "description": "ValidationError", - "schema": { - "$ref": "#/definitions/ValidationError" - } } }, "tags": [ diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index 9280bc8da2e8..c7bee668dd6b 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -376,12 +376,6 @@ "schema": { "$ref": "#/definitions/GettableStatus" } - }, - "400": { - "description": "ValidationError", - "schema": { - "$ref": "#/definitions/ValidationError" - } } } } @@ -930,7 +924,7 @@ "$ref": "#/definitions/alertGroup" }, "AlertGroups": { - "$ref": "#/definitions/alertGroups" + "$ref": "#/definitions/AlertGroups" }, "AlertInstancesResponse": { "type": "object", @@ -950,6 +944,65 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "AlertNotification": { + "type": "object", + "properties": { + "created": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "frequency": { + "type": "string", + "$ref": "#/definitions/Duration" + }, + "id": { + "type": "integer", + "format": "int64", + "x-go-name": "Id" + }, + "isDefault": { + "type": "boolean", + "x-go-name": "IsDefault" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureFields": { + "type": "object", + "additionalProperties": { + "type": "boolean" + }, + "x-go-name": "SecureFields" + }, + "sendReminder": { + "type": "boolean", + "x-go-name": "SendReminder" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "Uid" + }, + "updated": { + "type": "string", + "format": "date-time", + "x-go-name": "Updated" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/api/dtos" + }, "AlertQuery": { "type": "object", "title": "AlertQuery represents a single query associated with an alert definition.", @@ -1110,16 +1163,14 @@ "type": "object", "title": "Authorization contains HTTP authorization credentials.", "properties": { - "credentials": { + "Credentials": { "$ref": "#/definitions/Secret" }, - "credentials_file": { - "type": "string", - "x-go-name": "CredentialsFile" + "CredentialsFile": { + "type": "string" }, - "type": { - "type": "string", - "x-go-name": "Type" + "Type": { + "type": "string" } }, "x-go-package": "github.com/prometheus/common/config" @@ -1128,16 +1179,14 @@ "type": "object", "title": "BasicAuth contains basic HTTP authentication credentials.", "properties": { - "password": { + "Password": { "$ref": "#/definitions/Secret" }, - "password_file": { - "type": "string", - "x-go-name": "PasswordFile" + "PasswordFile": { + "type": "string" }, - "username": { - "type": "string", - "x-go-name": "Username" + "Username": { + "type": "string" } }, "x-go-package": "github.com/prometheus/common/config" @@ -1156,6 +1205,13 @@ }, "x-go-name": "InhibitRules" }, + "receivers": { + "type": "array", + "items": { + "$ref": "#/definitions/Receiver" + }, + "x-go-name": "Receivers" + }, "route": { "$ref": "#/definitions/Route" }, @@ -1169,6 +1225,53 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, + "CreateAlertNotificationCommand": { + "type": "object", + "properties": { + "Result": { + "$ref": "#/definitions/AlertNotification" + }, + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "frequency": { + "type": "string", + "x-go-name": "Frequency" + }, + "isDefault": { + "type": "boolean", + "x-go-name": "IsDefault" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureSettings": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "x-go-name": "SecureSettings" + }, + "sendReminder": { + "type": "boolean", + "x-go-name": "SendReminder" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "Uid" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/models" + }, "DateTime": { "description": "DateTime is a time but it serializes to ISO8601 format with millis\nIt knows how to read 3 different variations of a RFC3339 date time.\nMost APIs we encounter want either millisecond or second precision times.\nThis just tries to make it worry-free.", "type": "string", @@ -1353,7 +1456,7 @@ "$ref": "#/definitions/GettableAlert" }, "GettableAlerts": { - "$ref": "#/definitions/gettableAlerts" + "$ref": "#/definitions/GettableAlerts" }, "GettableApiAlertingConfig": { "type": "object", @@ -1502,36 +1605,7 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceiver": { - "type": "object", - "properties": { - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureFields": { - "type": "object", - "additionalProperties": { - "type": "boolean" - }, - "x-go-name": "SecureFields" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "UID" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "$ref": "#/definitions/AlertNotification" }, "GettableGrafanaReceivers": { "type": "object", @@ -1563,7 +1637,8 @@ "exec_err_state": { "type": "string", "enum": [ - "Alerting" + "Alerting", + "KeepLastState" ], "x-go-name": "ExecErrState" }, @@ -1591,6 +1666,7 @@ "enum": [ "Alerting", "NoData", + "KeepLastState", "OK" ], "x-go-name": "NoDataState" @@ -1652,7 +1728,7 @@ "$ref": "#/definitions/gettableSilences" }, "GettableStatus": { - "$ref": "#/definitions/alertmanagerStatus" + "$ref": "#/definitions/GettableStatus" }, "GettableUserConfig": { "type": "object", @@ -1748,32 +1824,30 @@ "type": "object", "title": "HTTPClientConfig configures an HTTP client.", "properties": { - "authorization": { + "Authorization": { "$ref": "#/definitions/Authorization" }, - "basic_auth": { + "BasicAuth": { "$ref": "#/definitions/BasicAuth" }, - "bearer_token": { + "BearerToken": { "$ref": "#/definitions/Secret" }, - "bearer_token_file": { + "BearerTokenFile": { "description": "The bearer token file for the targets. Deprecated in favour of\nAuthorization.CredentialsFile.", - "type": "string", - "x-go-name": "BearerTokenFile" + "type": "string" }, - "follow_redirects": { + "FollowRedirects": { "description": "FollowRedirects specifies whether the client should follow HTTP 3xx redirects.\nThe omitempty flag is not set, because it would be hidden from the\nmarshalled configuration when set to false.", - "type": "boolean", - "x-go-name": "FollowRedirects" + "type": "boolean" }, - "oauth2": { + "OAuth2": { "$ref": "#/definitions/OAuth2" }, - "proxy_url": { + "ProxyURL": { "$ref": "#/definitions/URL" }, - "tls_config": { + "TLSConfig": { "$ref": "#/definitions/TLSConfig" } }, @@ -1929,34 +2003,29 @@ "type": "object", "title": "OAuth2 is the oauth2 client configuration.", "properties": { - "client_id": { - "type": "string", - "x-go-name": "ClientID" + "ClientID": { + "type": "string" }, - "client_secret": { + "ClientSecret": { "$ref": "#/definitions/Secret" }, - "client_secret_file": { - "type": "string", - "x-go-name": "ClientSecretFile" + "ClientSecretFile": { + "type": "string" }, - "endpoint_params": { + "EndpointParams": { "type": "object", "additionalProperties": { "type": "string" - }, - "x-go-name": "EndpointParams" + } }, - "scopes": { + "Scopes": { "type": "array", "items": { "type": "string" - }, - "x-go-name": "Scopes" + } }, - "token_url": { - "type": "string", - "x-go-name": "TokenURL" + "TokenURL": { + "type": "string" } }, "x-go-package": "github.com/prometheus/common/config" @@ -2311,36 +2380,7 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceiver": { - "type": "object", - "properties": { - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureSettings": { - "type": "object", - "additionalProperties": { - "type": "string" - }, - "x-go-name": "SecureSettings" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "UID" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + "$ref": "#/definitions/CreateAlertNotificationCommand" }, "PostableGrafanaReceivers": { "type": "object", @@ -2372,7 +2412,8 @@ "exec_err_state": { "type": "string", "enum": [ - "Alerting" + "Alerting", + "KeepLastState" ], "x-go-name": "ExecErrState" }, @@ -2381,6 +2422,7 @@ "enum": [ "Alerting", "NoData", + "KeepLastState", "OK" ], "x-go-name": "NoDataState" @@ -2417,7 +2459,7 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableSilence": { - "$ref": "#/definitions/postableSilence" + "$ref": "#/definitions/PostableSilence" }, "PostableUserConfig": { "type": "object", @@ -2823,6 +2865,18 @@ "title": "SecretURL is a URL that must not be revealed on marshaling.", "$ref": "#/definitions/URL" }, + "SecureJsonData": { + "description": "SecureJsonData is used to store encrypted data (for example in data_source table). Only values are separately\nencrypted.", + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "integer", + "format": "uint8" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/components/securejsondata" + }, "SlackAction": { "description": "See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons\nfor more information.", "type": "object", @@ -3018,30 +3072,25 @@ "type": "object", "title": "TLSConfig configures the options for TLS connections.", "properties": { - "ca_file": { + "CAFile": { "description": "The CA cert to use for the targets.", - "type": "string", - "x-go-name": "CAFile" + "type": "string" }, - "cert_file": { + "CertFile": { "description": "The client cert file for the targets.", - "type": "string", - "x-go-name": "CertFile" + "type": "string" }, - "insecure_skip_verify": { + "InsecureSkipVerify": { "description": "Disable target certificate validation.", - "type": "boolean", - "x-go-name": "InsecureSkipVerify" + "type": "boolean" }, - "key_file": { + "KeyFile": { "description": "The client key file for the targets.", - "type": "string", - "x-go-name": "KeyFile" + "type": "string" }, - "server_name": { + "ServerName": { "description": "Used to verify the hostname for the targets.", - "type": "string", - "x-go-name": "ServerName" + "type": "string" } }, "x-go-package": "github.com/prometheus/common/config" @@ -3286,7 +3335,7 @@ "description": "alerts", "type": "array", "items": { - "$ref": "#/definitions/gettableAlert" + "$ref": "#/definitions/GettableAlert" }, "x-go-name": "Alerts" }, @@ -3294,7 +3343,7 @@ "$ref": "#/definitions/labelSet" }, "receiver": { - "$ref": "#/definitions/Receiver" + "$ref": "#/definitions/receiver" } }, "x-go-name": "AlertGroup", @@ -3304,7 +3353,7 @@ "description": "AlertGroups alert groups", "type": "array", "items": { - "$ref": "#/definitions/alertGroup" + "$ref": "#/definitions/AlertGroup" }, "x-go-name": "AlertGroups", "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" @@ -3467,7 +3516,7 @@ "description": "receivers", "type": "array", "items": { - "$ref": "#/definitions/receiver" + "$ref": "#/definitions/Receiver" }, "x-go-name": "Receivers" }, From 63ccf9062211717b74a4969be18e944dff4c5888 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Thu, 3 Jun 2021 13:06:19 +0300 Subject: [PATCH 10/16] Revert "Fix unmarshalling" This reverts commit dadd7d1e2761751af29f13e0a6ae039d2897d110. --- pkg/services/ngalert/api/api.go | 2 +- pkg/services/ngalert/api/api_alertmanager.go | 6 +--- .../api/tooling/definitions/alertmanager.go | 32 +++++++++++++------ pkg/services/ngalert/notifier/status.go | 4 +-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/pkg/services/ngalert/api/api.go b/pkg/services/ngalert/api/api.go index 9635bdee0440..fa614b82c1d1 100644 --- a/pkg/services/ngalert/api/api.go +++ b/pkg/services/ngalert/api/api.go @@ -25,7 +25,7 @@ var timeNow = time.Now type Alertmanager interface { // Configuration SaveAndApplyConfig(config *apimodels.PostableUserConfig) error - GetStatus() (*apimodels.GettableStatus, error) + GetStatus() apimodels.GettableStatus // Silences CreateSilence(ps *apimodels.PostableSilence) (string, error) diff --git a/pkg/services/ngalert/api/api_alertmanager.go b/pkg/services/ngalert/api/api_alertmanager.go index fb3dc7c35325..53fb1ca8ac87 100644 --- a/pkg/services/ngalert/api/api_alertmanager.go +++ b/pkg/services/ngalert/api/api_alertmanager.go @@ -22,11 +22,7 @@ type AlertmanagerSrv struct { } func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Response { - st, err := srv.am.GetStatus() - if err != nil { - return ErrResp(http.StatusInternalServerError, err, "failed to get status") - } - return response.JSON(http.StatusOK, st) + return response.JSON(http.StatusOK, srv.am.GetStatus()) } func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSilence apimodels.PostableSilence) response.Response { diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index df235b77715f..c34d6eaedeb6 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -6,6 +6,8 @@ import ( "fmt" "reflect" + "github.com/go-openapi/strfmt" + "github.com/pkg/errors" amv2 "github.com/prometheus/alertmanager/api/v2/models" "github.com/prometheus/alertmanager/config" @@ -123,19 +125,30 @@ type GetSilencesParams struct { } // swagger:model -type GettableStatus amv2.AlertmanagerStatus +type GettableStatus struct { + // cluster + // Required: true + Cluster *amv2.ClusterStatus `json:"cluster"` -func NewGettableStatus(cfg *PostableApiAlertingConfig) (*GettableStatus, error) { - blob, err := json.Marshal(cfg) - if err != nil { - return nil, err - } - toString := string(blob) + // config + // Required: true + Config *PostableApiAlertingConfig `json:"config"` + + // uptime + // Required: true + // Format: date-time + Uptime *strfmt.DateTime `json:"uptime"` + + // version info + // Required: true + VersionInfo *amv2.VersionInfo `json:"versionInfo"` +} +func NewGettableStatus(cfg *PostableApiAlertingConfig) *GettableStatus { // In Grafana, the only field we support is Config. cs := amv2.ClusterStatusStatusDisabled na := "N/A" - status := &GettableStatus{ + return &GettableStatus{ Cluster: &amv2.ClusterStatus{ Status: &cs, Peers: []*amv2.PeerStatus{}, @@ -148,9 +161,8 @@ func NewGettableStatus(cfg *PostableApiAlertingConfig) (*GettableStatus, error) Revision: &na, Version: &na, }, - Config: &amv2.AlertmanagerConfig{Original: &toString}, + Config: cfg, } - return status, nil } // swagger:model diff --git a/pkg/services/ngalert/notifier/status.go b/pkg/services/ngalert/notifier/status.go index 724f0e4f2f5f..8726166dcbe7 100644 --- a/pkg/services/ngalert/notifier/status.go +++ b/pkg/services/ngalert/notifier/status.go @@ -6,7 +6,7 @@ import ( apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" ) -func (am *Alertmanager) GetStatus() (*apimodels.GettableStatus, error) { +func (am *Alertmanager) GetStatus() apimodels.GettableStatus { am.reloadConfigMtx.RLock() defer am.reloadConfigMtx.RUnlock() @@ -18,5 +18,5 @@ func (am *Alertmanager) GetStatus() (*apimodels.GettableStatus, error) { am.logger.Error("unable to marshal alertmanager configuration", "err", err) } } - return apimodels.NewGettableStatus(&amConfig) + return *apimodels.NewGettableStatus(&amConfig) } From 8999f77b3815bd0acd2bae0c21729cbb36bcd34e Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Thu, 3 Jun 2021 15:30:19 +0300 Subject: [PATCH 11/16] Fix unmarshalling --- .../api/tooling/definitions/alertmanager.go | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index c34d6eaedeb6..8d3d7321d42a 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -144,6 +144,25 @@ type GettableStatus struct { VersionInfo *amv2.VersionInfo `json:"versionInfo"` } +func (s *GettableStatus) UnmarshalJSON(b []byte) error { + amStatus := amv2.AlertmanagerStatus{} + if err := json.Unmarshal(b, &amStatus); err != nil { + return err + } + + c := Config{} + if err := yaml.Unmarshal([]byte(*amStatus.Config.Original), &c); err != nil { + return err + } + + s.Cluster = amStatus.Cluster + s.Config = &PostableApiAlertingConfig{Config: c} + s.Uptime = amStatus.Uptime + s.VersionInfo = amStatus.VersionInfo + + return nil +} + func NewGettableStatus(cfg *PostableApiAlertingConfig) *GettableStatus { // In Grafana, the only field we support is Config. cs := amv2.ClusterStatusStatusDisabled @@ -518,10 +537,6 @@ type Config struct { Templates []string `yaml:"templates" json:"templates"` } -// Config is the entrypoint for the embedded Alertmanager config with the exception of receivers. -// Prometheus historically uses yaml files as the method of configuration and thus some -// post-validation is included in the UnmarshalYAML method. Here we simply run this with -// a noop unmarshaling function in order to benefit from said validation. func (c *Config) UnmarshalJSON(b []byte) error { type plain Config if err := json.Unmarshal(b, (*plain)(c)); err != nil { From ac9fa0f57bd0af29c2555f66a6a29ffb7d1c32b2 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Thu, 3 Jun 2021 15:41:41 +0300 Subject: [PATCH 12/16] Fixup godoc removed accidentally --- pkg/services/ngalert/api/tooling/definitions/alertmanager.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index 8d3d7321d42a..2e8fb2737c3e 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -537,6 +537,10 @@ type Config struct { Templates []string `yaml:"templates" json:"templates"` } +// Config is the entrypoint for the embedded Alertmanager config with the exception of receivers. +// Prometheus historically uses yaml files as the method of configuration and thus some +// post-validation is included in the UnmarshalYAML method. Here we simply run this with +// a noop unmarshaling function in order to benefit from said validation. func (c *Config) UnmarshalJSON(b []byte) error { type plain Config if err := json.Unmarshal(b, (*plain)(c)); err != nil { From 2e97b0dda0d3a62474f6a44bf9cf514f405c9495 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Fri, 4 Jun 2021 11:38:11 +0300 Subject: [PATCH 13/16] Update prometheus/common dependency --- go.mod | 6 +++--- go.sum | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index da803faad66a..fcda3007803f 100644 --- a/go.mod +++ b/go.mod @@ -77,7 +77,7 @@ require ( github.com/prometheus/alertmanager v0.21.1-0.20210511232218-7301451eb94d github.com/prometheus/client_golang v1.10.0 github.com/prometheus/client_model v0.2.0 - github.com/prometheus/common v0.24.0 + github.com/prometheus/common v0.27.0 github.com/prometheus/prometheus v1.8.2-0.20210430082741-2a4b8e12bbf2 github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 github.com/robfig/cron/v3 v3.0.1 @@ -96,8 +96,8 @@ require ( go.opentelemetry.io/collector v0.27.0 golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a golang.org/x/exp v0.0.0-20210220032938-85be41e4509f // indirect - golang.org/x/net v0.0.0-20210521195947-fe42d452be8f - golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 + golang.org/x/net v0.0.0-20210525063256-abc453219eb5 + golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 // indirect golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba diff --git a/go.sum b/go.sum index a95365292128..121a6d536e4c 100644 --- a/go.sum +++ b/go.sum @@ -551,6 +551,7 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo= github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= @@ -1546,8 +1547,9 @@ github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16 github.com/prometheus/common v0.20.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.21.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.23.0/go.mod h1:H6QK/N6XVT42whUeIdI3dp36w49c+/iMDk7UAI2qm7Q= -github.com/prometheus/common v0.24.0 h1:aIycr3wRFxPUq8XlLQlGQ9aNXV3dFi5y62pe/SB262k= github.com/prometheus/common v0.24.0/go.mod h1:H6QK/N6XVT42whUeIdI3dp36w49c+/iMDk7UAI2qm7Q= +github.com/prometheus/common v0.27.0 h1:kJb5BtkTmonXrV2nfyRRlChGpgqhPCdj2ooGivZ8txo= +github.com/prometheus/common v0.27.0/go.mod h1:LdLj/WiR+LL0ThCPrtSZbijrsxInIhizDTiPlJhPPq4= github.com/prometheus/exporter-toolkit v0.5.0/go.mod h1:OCkM4805mmisBhLmVFw858QYi3v0wKdY6/UxrT0pZVg= github.com/prometheus/exporter-toolkit v0.5.1/go.mod h1:OCkM4805mmisBhLmVFw858QYi3v0wKdY6/UxrT0pZVg= github.com/prometheus/node_exporter v1.0.0-rc.0.0.20200428091818-01054558c289 h1:dTUS1vaLWq+Y6XKOTnrFpoVsQKLCbCp1OLj24TDi7oM= @@ -2094,8 +2096,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210324051636-2c4c8ecb7826/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20210427231257-85d9c07bbe3a/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20210521195947-fe42d452be8f h1:Si4U+UcgJzya9kpiEUJKQvjr512OLli+gL4poHrz93U= -golang.org/x/net v0.0.0-20210521195947-fe42d452be8f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -2111,8 +2113,9 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 h1:rPRtHfUb0UKZeZ6GH4K4Nt4YRbE9V1u+QZX5upZXqJQ= golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= From 3b40f3a9277639c12cc4da7f12bc53dcb20feab8 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Fri, 4 Jun 2021 18:54:43 +0300 Subject: [PATCH 14/16] Update spec --- pkg/services/ngalert/api/tooling/post.json | 349 ++++++++++----------- pkg/services/ngalert/api/tooling/spec.json | 341 ++++++++++---------- 2 files changed, 323 insertions(+), 367 deletions(-) diff --git a/pkg/services/ngalert/api/tooling/post.json b/pkg/services/ngalert/api/tooling/post.json index 43cb90e148cd..91f147af0e69 100644 --- a/pkg/services/ngalert/api/tooling/post.json +++ b/pkg/services/ngalert/api/tooling/post.json @@ -57,10 +57,10 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "AlertGroup": { - "$ref": "#/definitions/alertGroup" + "AlertGroup": {}, + "AlertGroups": { + "$ref": "#/definitions/alertGroups" }, - "AlertGroups": {}, "AlertInstancesResponse": { "properties": { "instances": { @@ -79,65 +79,6 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "AlertNotification": { - "properties": { - "created": { - "format": "date-time", - "type": "string", - "x-go-name": "Created" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "$ref": "#/definitions/Duration", - "type": "string" - }, - "id": { - "format": "int64", - "type": "integer", - "x-go-name": "Id" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureFields": { - "additionalProperties": { - "type": "boolean" - }, - "type": "object", - "x-go-name": "SecureFields" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - }, - "updated": { - "format": "date-time", - "type": "string", - "x-go-name": "Updated" - } - }, - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/api/dtos" - }, "AlertQuery": { "properties": { "datasourceUid": { @@ -296,14 +237,16 @@ }, "Authorization": { "properties": { - "Credentials": { + "credentials": { "$ref": "#/definitions/Secret" }, - "CredentialsFile": { - "type": "string" + "credentials_file": { + "type": "string", + "x-go-name": "CredentialsFile" }, - "Type": { - "type": "string" + "type": { + "type": "string", + "x-go-name": "Type" } }, "title": "Authorization contains HTTP authorization credentials.", @@ -312,14 +255,16 @@ }, "BasicAuth": { "properties": { - "Password": { + "password": { "$ref": "#/definitions/Secret" }, - "PasswordFile": { - "type": "string" + "password_file": { + "type": "string", + "x-go-name": "PasswordFile" }, - "Username": { - "type": "string" + "username": { + "type": "string", + "x-go-name": "Username" } }, "title": "BasicAuth contains basic HTTP authentication credentials.", @@ -338,13 +283,6 @@ "type": "array", "x-go-name": "InhibitRules" }, - "receivers": { - "items": { - "$ref": "#/definitions/Receiver" - }, - "type": "array", - "x-go-name": "Receivers" - }, "route": { "$ref": "#/definitions/Route" }, @@ -360,53 +298,6 @@ "type": "object", "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "CreateAlertNotificationCommand": { - "properties": { - "Result": { - "$ref": "#/definitions/AlertNotification" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "type": "string", - "x-go-name": "Frequency" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureSettings": { - "additionalProperties": { - "type": "string" - }, - "type": "object", - "x-go-name": "SecureSettings" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - } - }, - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/models" - }, "DateTime": { "description": "DateTime is a time but it serializes to ISO8601 format with millis\nIt knows how to read 3 different variations of a RFC3339 date time.\nMost APIs we encounter want either millisecond or second precision times.\nThis just tries to make it worry-free.", "format": "date-time", @@ -584,8 +475,12 @@ "Failure": { "$ref": "#/definitions/ResponseDetails" }, - "GettableAlert": {}, - "GettableAlerts": {}, + "GettableAlert": { + "$ref": "#/definitions/gettableAlert" + }, + "GettableAlerts": { + "$ref": "#/definitions/gettableAlerts" + }, "GettableApiAlertingConfig": { "properties": { "global": { @@ -733,7 +628,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceiver": { - "$ref": "#/definitions/AlertNotification" + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureFields": { + "additionalProperties": { + "type": "boolean" + }, + "type": "object", + "x-go-name": "SecureFields" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceivers": { "properties": { @@ -763,8 +687,7 @@ }, "exec_err_state": { "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "type": "string", "x-go-name": "ExecErrState" @@ -792,7 +715,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "type": "string", @@ -855,7 +777,33 @@ "GettableSilences": { "$ref": "#/definitions/gettableSilences" }, - "GettableStatus": {}, + "GettableStatus": { + "properties": { + "cluster": { + "$ref": "#/definitions/clusterStatus" + }, + "config": { + "$ref": "#/definitions/PostableApiAlertingConfig" + }, + "uptime": { + "description": "uptime", + "format": "date-time", + "type": "string", + "x-go-name": "Uptime" + }, + "versionInfo": { + "$ref": "#/definitions/versionInfo" + } + }, + "required": [ + "cluster", + "config", + "uptime", + "versionInfo" + ], + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" + }, "GettableUserConfig": { "properties": { "alertmanager_config": { @@ -948,30 +896,32 @@ }, "HTTPClientConfig": { "properties": { - "Authorization": { + "authorization": { "$ref": "#/definitions/Authorization" }, - "BasicAuth": { + "basic_auth": { "$ref": "#/definitions/BasicAuth" }, - "BearerToken": { + "bearer_token": { "$ref": "#/definitions/Secret" }, - "BearerTokenFile": { + "bearer_token_file": { "description": "The bearer token file for the targets. Deprecated in favour of\nAuthorization.CredentialsFile.", - "type": "string" + "type": "string", + "x-go-name": "BearerTokenFile" }, - "FollowRedirects": { + "follow_redirects": { "description": "FollowRedirects specifies whether the client should follow HTTP 3xx redirects.\nThe omitempty flag is not set, because it would be hidden from the\nmarshalled configuration when set to false.", - "type": "boolean" + "type": "boolean", + "x-go-name": "FollowRedirects" }, - "OAuth2": { + "oauth2": { "$ref": "#/definitions/OAuth2" }, - "ProxyURL": { + "proxy_url": { "$ref": "#/definitions/URL" }, - "TLSConfig": { + "tls_config": { "$ref": "#/definitions/TLSConfig" } }, @@ -1126,29 +1076,34 @@ }, "OAuth2": { "properties": { - "ClientID": { - "type": "string" + "client_id": { + "type": "string", + "x-go-name": "ClientID" }, - "ClientSecret": { + "client_secret": { "$ref": "#/definitions/Secret" }, - "ClientSecretFile": { - "type": "string" + "client_secret_file": { + "type": "string", + "x-go-name": "ClientSecretFile" }, - "EndpointParams": { + "endpoint_params": { "additionalProperties": { "type": "string" }, - "type": "object" + "type": "object", + "x-go-name": "EndpointParams" }, - "Scopes": { + "scopes": { "items": { "type": "string" }, - "type": "array" + "type": "array", + "x-go-name": "Scopes" }, - "TokenURL": { - "type": "string" + "token_url": { + "type": "string", + "x-go-name": "TokenURL" } }, "title": "OAuth2 is the oauth2 client configuration.", @@ -1505,7 +1460,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceiver": { - "$ref": "#/definitions/CreateAlertNotificationCommand" + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureSettings": { + "additionalProperties": { + "type": "string" + }, + "type": "object", + "x-go-name": "SecureSettings" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "type": "object", + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceivers": { "properties": { @@ -1535,8 +1519,7 @@ }, "exec_err_state": { "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "type": "string", "x-go-name": "ExecErrState" @@ -1545,7 +1528,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "type": "string", @@ -1987,18 +1969,6 @@ "$ref": "#/definitions/URL", "title": "SecretURL is a URL that must not be revealed on marshaling." }, - "SecureJsonData": { - "additionalProperties": { - "items": { - "format": "uint8", - "type": "integer" - }, - "type": "array" - }, - "description": "SecureJsonData is used to store encrypted data (for example in data_source table). Only values are separately\nencrypted.", - "type": "object", - "x-go-package": "github.com/grafana/grafana/pkg/components/securejsondata" - }, "SlackAction": { "description": "See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons\nfor more information.", "properties": { @@ -2192,25 +2162,30 @@ }, "TLSConfig": { "properties": { - "CAFile": { + "ca_file": { "description": "The CA cert to use for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CAFile" }, - "CertFile": { + "cert_file": { "description": "The client cert file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CertFile" }, - "InsecureSkipVerify": { + "insecure_skip_verify": { "description": "Disable target certificate validation.", - "type": "boolean" + "type": "boolean", + "x-go-name": "InsecureSkipVerify" }, - "KeyFile": { + "key_file": { "description": "The client key file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "KeyFile" }, - "ServerName": { + "server_name": { "description": "Used to verify the hostname for the targets.", - "type": "string" + "type": "string", + "x-go-name": "ServerName" } }, "title": "TLSConfig configures the options for TLS connections.", @@ -2474,7 +2449,7 @@ "alertGroups": { "description": "AlertGroups alert groups", "items": { - "$ref": "#/definitions/AlertGroup" + "$ref": "#/definitions/alertGroup" }, "type": "array", "x-go-name": "AlertGroups", @@ -2626,7 +2601,7 @@ "receivers": { "description": "receivers", "items": { - "$ref": "#/definitions/Receiver" + "$ref": "#/definitions/receiver" }, "type": "array", "x-go-name": "Receivers" @@ -2664,7 +2639,7 @@ "gettableAlerts": { "description": "GettableAlerts gettable alerts", "items": { - "$ref": "#/definitions/gettableAlert" + "$ref": "#/definitions/GettableAlert" }, "type": "array", "x-go-name": "GettableAlerts", @@ -3343,7 +3318,7 @@ "in": "body", "name": "Silence", "schema": { - "$ref": "#/definitions/PostableSilence" + "$ref": "#/definitions/postableSilence" } }, { @@ -3392,6 +3367,12 @@ "schema": { "$ref": "#/definitions/GettableStatus" } + }, + "400": { + "description": "ValidationError", + "schema": { + "$ref": "#/definitions/ValidationError" + } } }, "tags": [ diff --git a/pkg/services/ngalert/api/tooling/spec.json b/pkg/services/ngalert/api/tooling/spec.json index c7bee668dd6b..e7ce3bba95bd 100644 --- a/pkg/services/ngalert/api/tooling/spec.json +++ b/pkg/services/ngalert/api/tooling/spec.json @@ -327,7 +327,7 @@ "name": "Silence", "in": "body", "schema": { - "$ref": "#/definitions/PostableSilence" + "$ref": "#/definitions/postableSilence" } }, { @@ -376,6 +376,12 @@ "schema": { "$ref": "#/definitions/GettableStatus" } + }, + "400": { + "description": "ValidationError", + "schema": { + "$ref": "#/definitions/ValidationError" + } } } } @@ -921,10 +927,10 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "AlertGroup": { - "$ref": "#/definitions/alertGroup" + "$ref": "#/definitions/AlertGroup" }, "AlertGroups": { - "$ref": "#/definitions/AlertGroups" + "$ref": "#/definitions/alertGroups" }, "AlertInstancesResponse": { "type": "object", @@ -944,65 +950,6 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "AlertNotification": { - "type": "object", - "properties": { - "created": { - "type": "string", - "format": "date-time", - "x-go-name": "Created" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "type": "string", - "$ref": "#/definitions/Duration" - }, - "id": { - "type": "integer", - "format": "int64", - "x-go-name": "Id" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureFields": { - "type": "object", - "additionalProperties": { - "type": "boolean" - }, - "x-go-name": "SecureFields" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - }, - "updated": { - "type": "string", - "format": "date-time", - "x-go-name": "Updated" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/api/dtos" - }, "AlertQuery": { "type": "object", "title": "AlertQuery represents a single query associated with an alert definition.", @@ -1163,14 +1110,16 @@ "type": "object", "title": "Authorization contains HTTP authorization credentials.", "properties": { - "Credentials": { + "credentials": { "$ref": "#/definitions/Secret" }, - "CredentialsFile": { - "type": "string" + "credentials_file": { + "type": "string", + "x-go-name": "CredentialsFile" }, - "Type": { - "type": "string" + "type": { + "type": "string", + "x-go-name": "Type" } }, "x-go-package": "github.com/prometheus/common/config" @@ -1179,14 +1128,16 @@ "type": "object", "title": "BasicAuth contains basic HTTP authentication credentials.", "properties": { - "Password": { + "password": { "$ref": "#/definitions/Secret" }, - "PasswordFile": { - "type": "string" + "password_file": { + "type": "string", + "x-go-name": "PasswordFile" }, - "Username": { - "type": "string" + "username": { + "type": "string", + "x-go-name": "Username" } }, "x-go-package": "github.com/prometheus/common/config" @@ -1205,13 +1156,6 @@ }, "x-go-name": "InhibitRules" }, - "receivers": { - "type": "array", - "items": { - "$ref": "#/definitions/Receiver" - }, - "x-go-name": "Receivers" - }, "route": { "$ref": "#/definitions/Route" }, @@ -1225,53 +1169,6 @@ }, "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, - "CreateAlertNotificationCommand": { - "type": "object", - "properties": { - "Result": { - "$ref": "#/definitions/AlertNotification" - }, - "disableResolveMessage": { - "type": "boolean", - "x-go-name": "DisableResolveMessage" - }, - "frequency": { - "type": "string", - "x-go-name": "Frequency" - }, - "isDefault": { - "type": "boolean", - "x-go-name": "IsDefault" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "secureSettings": { - "type": "object", - "additionalProperties": { - "type": "string" - }, - "x-go-name": "SecureSettings" - }, - "sendReminder": { - "type": "boolean", - "x-go-name": "SendReminder" - }, - "settings": { - "$ref": "#/definitions/Json" - }, - "type": { - "type": "string", - "x-go-name": "Type" - }, - "uid": { - "type": "string", - "x-go-name": "Uid" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/models" - }, "DateTime": { "description": "DateTime is a time but it serializes to ISO8601 format with millis\nIt knows how to read 3 different variations of a RFC3339 date time.\nMost APIs we encounter want either millisecond or second precision times.\nThis just tries to make it worry-free.", "type": "string", @@ -1453,10 +1350,10 @@ "$ref": "#/definitions/ResponseDetails" }, "GettableAlert": { - "$ref": "#/definitions/GettableAlert" + "$ref": "#/definitions/gettableAlert" }, "GettableAlerts": { - "$ref": "#/definitions/GettableAlerts" + "$ref": "#/definitions/gettableAlerts" }, "GettableApiAlertingConfig": { "type": "object", @@ -1605,7 +1502,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceiver": { - "$ref": "#/definitions/AlertNotification" + "type": "object", + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureFields": { + "type": "object", + "additionalProperties": { + "type": "boolean" + }, + "x-go-name": "SecureFields" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableGrafanaReceivers": { "type": "object", @@ -1637,8 +1563,7 @@ "exec_err_state": { "type": "string", "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "x-go-name": "ExecErrState" }, @@ -1666,7 +1591,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "x-go-name": "NoDataState" @@ -1728,7 +1652,31 @@ "$ref": "#/definitions/gettableSilences" }, "GettableStatus": { - "$ref": "#/definitions/GettableStatus" + "type": "object", + "required": [ + "cluster", + "config", + "uptime", + "versionInfo" + ], + "properties": { + "cluster": { + "$ref": "#/definitions/clusterStatus" + }, + "config": { + "$ref": "#/definitions/PostableApiAlertingConfig" + }, + "uptime": { + "description": "uptime", + "type": "string", + "format": "date-time", + "x-go-name": "Uptime" + }, + "versionInfo": { + "$ref": "#/definitions/versionInfo" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "GettableUserConfig": { "type": "object", @@ -1824,30 +1772,32 @@ "type": "object", "title": "HTTPClientConfig configures an HTTP client.", "properties": { - "Authorization": { + "authorization": { "$ref": "#/definitions/Authorization" }, - "BasicAuth": { + "basic_auth": { "$ref": "#/definitions/BasicAuth" }, - "BearerToken": { + "bearer_token": { "$ref": "#/definitions/Secret" }, - "BearerTokenFile": { + "bearer_token_file": { "description": "The bearer token file for the targets. Deprecated in favour of\nAuthorization.CredentialsFile.", - "type": "string" + "type": "string", + "x-go-name": "BearerTokenFile" }, - "FollowRedirects": { + "follow_redirects": { "description": "FollowRedirects specifies whether the client should follow HTTP 3xx redirects.\nThe omitempty flag is not set, because it would be hidden from the\nmarshalled configuration when set to false.", - "type": "boolean" + "type": "boolean", + "x-go-name": "FollowRedirects" }, - "OAuth2": { + "oauth2": { "$ref": "#/definitions/OAuth2" }, - "ProxyURL": { + "proxy_url": { "$ref": "#/definitions/URL" }, - "TLSConfig": { + "tls_config": { "$ref": "#/definitions/TLSConfig" } }, @@ -2003,29 +1953,34 @@ "type": "object", "title": "OAuth2 is the oauth2 client configuration.", "properties": { - "ClientID": { - "type": "string" + "client_id": { + "type": "string", + "x-go-name": "ClientID" }, - "ClientSecret": { + "client_secret": { "$ref": "#/definitions/Secret" }, - "ClientSecretFile": { - "type": "string" + "client_secret_file": { + "type": "string", + "x-go-name": "ClientSecretFile" }, - "EndpointParams": { + "endpoint_params": { "type": "object", "additionalProperties": { "type": "string" - } + }, + "x-go-name": "EndpointParams" }, - "Scopes": { + "scopes": { "type": "array", "items": { "type": "string" - } + }, + "x-go-name": "Scopes" }, - "TokenURL": { - "type": "string" + "token_url": { + "type": "string", + "x-go-name": "TokenURL" } }, "x-go-package": "github.com/prometheus/common/config" @@ -2380,7 +2335,36 @@ "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceiver": { - "$ref": "#/definitions/CreateAlertNotificationCommand" + "type": "object", + "properties": { + "disableResolveMessage": { + "type": "boolean", + "x-go-name": "DisableResolveMessage" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "secureSettings": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "x-go-name": "SecureSettings" + }, + "settings": { + "$ref": "#/definitions/Json" + }, + "type": { + "type": "string", + "x-go-name": "Type" + }, + "uid": { + "type": "string", + "x-go-name": "UID" + } + }, + "x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" }, "PostableGrafanaReceivers": { "type": "object", @@ -2412,8 +2396,7 @@ "exec_err_state": { "type": "string", "enum": [ - "Alerting", - "KeepLastState" + "Alerting" ], "x-go-name": "ExecErrState" }, @@ -2422,7 +2405,6 @@ "enum": [ "Alerting", "NoData", - "KeepLastState", "OK" ], "x-go-name": "NoDataState" @@ -2865,18 +2847,6 @@ "title": "SecretURL is a URL that must not be revealed on marshaling.", "$ref": "#/definitions/URL" }, - "SecureJsonData": { - "description": "SecureJsonData is used to store encrypted data (for example in data_source table). Only values are separately\nencrypted.", - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8" - } - }, - "x-go-package": "github.com/grafana/grafana/pkg/components/securejsondata" - }, "SlackAction": { "description": "See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons\nfor more information.", "type": "object", @@ -3072,25 +3042,30 @@ "type": "object", "title": "TLSConfig configures the options for TLS connections.", "properties": { - "CAFile": { + "ca_file": { "description": "The CA cert to use for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CAFile" }, - "CertFile": { + "cert_file": { "description": "The client cert file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "CertFile" }, - "InsecureSkipVerify": { + "insecure_skip_verify": { "description": "Disable target certificate validation.", - "type": "boolean" + "type": "boolean", + "x-go-name": "InsecureSkipVerify" }, - "KeyFile": { + "key_file": { "description": "The client key file for the targets.", - "type": "string" + "type": "string", + "x-go-name": "KeyFile" }, - "ServerName": { + "server_name": { "description": "Used to verify the hostname for the targets.", - "type": "string" + "type": "string", + "x-go-name": "ServerName" } }, "x-go-package": "github.com/prometheus/common/config" @@ -3353,7 +3328,7 @@ "description": "AlertGroups alert groups", "type": "array", "items": { - "$ref": "#/definitions/AlertGroup" + "$ref": "#/definitions/alertGroup" }, "x-go-name": "AlertGroups", "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" @@ -3516,7 +3491,7 @@ "description": "receivers", "type": "array", "items": { - "$ref": "#/definitions/Receiver" + "$ref": "#/definitions/receiver" }, "x-go-name": "Receivers" }, @@ -3543,7 +3518,7 @@ "description": "GettableAlerts gettable alerts", "type": "array", "items": { - "$ref": "#/definitions/gettableAlert" + "$ref": "#/definitions/GettableAlert" }, "x-go-name": "GettableAlerts", "x-go-package": "github.com/prometheus/alertmanager/api/v2/models" From eb7aa5b5a69a8ca01d7d73cfc36e4b9d735249d0 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Fri, 4 Jun 2021 18:58:15 +0300 Subject: [PATCH 15/16] Remove accidentally committed files --- .../api/generated_base_api_alertmanager.go-e | 151 ------------------ .../api/generated_base_api_prometheus.go-e | 49 ------ .../ngalert/api/generated_base_api_ruler.go-e | 94 ----------- .../api/generated_base_api_testing.go-e | 63 -------- 4 files changed, 357 deletions(-) delete mode 100644 pkg/services/ngalert/api/generated_base_api_alertmanager.go-e delete mode 100644 pkg/services/ngalert/api/generated_base_api_prometheus.go-e delete mode 100644 pkg/services/ngalert/api/generated_base_api_ruler.go-e delete mode 100644 pkg/services/ngalert/api/generated_base_api_testing.go-e diff --git a/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e b/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e deleted file mode 100644 index 46930dc91554..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_alertmanager.go-e +++ /dev/null @@ -1,151 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type AlertmanagerApiService interface { - RouteCreateSilence(*models.ReqContext, apimodels.PostableSilence) response.Response - RouteDeleteAlertingConfig(*models.ReqContext) response.Response - RouteDeleteSilence(*models.ReqContext) response.Response - RouteGetAMAlertGroups(*models.ReqContext) response.Response - RouteGetAMAlerts(*models.ReqContext) response.Response - RouteGetAMStatus(*models.ReqContext) response.Response - RouteGetAlertingConfig(*models.ReqContext) response.Response - RouteGetSilence(*models.ReqContext) response.Response - RouteGetSilences(*models.ReqContext) response.Response - RoutePostAMAlerts(*models.ReqContext, apimodels.PostableAlerts) response.Response - RoutePostAlertingConfig(*models.ReqContext, apimodels.PostableUserConfig) response.Response -} - -func (api *API) RegisterAlertmanagerApiEndpoints(srv AlertmanagerApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Post( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silences"), - binding.Bind(apimodels.PostableSilence{}), - metrics.Instrument( - http.MethodPost, - "/api/alertmanager/{Recipient}/api/v2/silences", - srv.RouteCreateSilence, - m, - ), - ) - group.Delete( - toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), - metrics.Instrument( - http.MethodDelete, - "/api/alertmanager/{Recipient}/config/api/v1/alerts", - srv.RouteDeleteAlertingConfig, - m, - ), - ) - group.Delete( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), - metrics.Instrument( - http.MethodDelete, - "/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}", - srv.RouteDeleteSilence, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts/groups"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/alerts/groups", - srv.RouteGetAMAlertGroups, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/alerts", - srv.RouteGetAMAlerts, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/status"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/status", - srv.RouteGetAMStatus, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/config/api/v1/alerts", - srv.RouteGetAlertingConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/silence/{SilenceId}", - srv.RouteGetSilence, - m, - ), - ) - group.Get( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/silences"), - metrics.Instrument( - http.MethodGet, - "/api/alertmanager/{Recipient}/api/v2/silences", - srv.RouteGetSilences, - m, - ), - ) - group.Post( - toMacaronPath("/api/alertmanager/{Recipient}/api/v2/alerts"), - binding.Bind(apimodels.PostableAlerts{}), - metrics.Instrument( - http.MethodPost, - "/api/alertmanager/{Recipient}/api/v2/alerts", - srv.RoutePostAMAlerts, - m, - ), - ) - group.Post( - toMacaronPath("/api/alertmanager/{Recipient}/config/api/v1/alerts"), - binding.Bind(apimodels.PostableUserConfig{}), - metrics.Instrument( - http.MethodPost, - "/api/alertmanager/{Recipient}/config/api/v1/alerts", - srv.RoutePostAlertingConfig, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - - - - - - - - - - diff --git a/pkg/services/ngalert/api/generated_base_api_prometheus.go-e b/pkg/services/ngalert/api/generated_base_api_prometheus.go-e deleted file mode 100644 index 85227a5efd79..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_prometheus.go-e +++ /dev/null @@ -1,49 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type PrometheusApiService interface { - RouteGetAlertStatuses(*models.ReqContext) response.Response - RouteGetRuleStatuses(*models.ReqContext) response.Response -} - -func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Get( - toMacaronPath("/api/prometheus/{Recipient}/api/v1/alerts"), - metrics.Instrument( - http.MethodGet, - "/api/prometheus/{Recipient}/api/v1/alerts", - srv.RouteGetAlertStatuses, - m, - ), - ) - group.Get( - toMacaronPath("/api/prometheus/{Recipient}/api/v1/rules"), - metrics.Instrument( - http.MethodGet, - "/api/prometheus/{Recipient}/api/v1/rules", - srv.RouteGetRuleStatuses, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - diff --git a/pkg/services/ngalert/api/generated_base_api_ruler.go-e b/pkg/services/ngalert/api/generated_base_api_ruler.go-e deleted file mode 100644 index aee3d8fa9ef5..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_ruler.go-e +++ /dev/null @@ -1,94 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type RulerApiService interface { - RouteDeleteNamespaceRulesConfig(*models.ReqContext) response.Response - RouteDeleteRuleGroupConfig(*models.ReqContext) response.Response - RouteGetNamespaceRulesConfig(*models.ReqContext) response.Response - RouteGetRulegGroupConfig(*models.ReqContext) response.Response - RouteGetRulesConfig(*models.ReqContext) response.Response - RoutePostNameRulesConfig(*models.ReqContext, apimodels.PostableRuleGroupConfig) response.Response -} - -func (api *API) RegisterRulerApiEndpoints(srv RulerApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Delete( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), - metrics.Instrument( - http.MethodDelete, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", - srv.RouteDeleteNamespaceRulesConfig, - m, - ), - ) - group.Delete( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}"), - metrics.Instrument( - http.MethodDelete, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}", - srv.RouteDeleteRuleGroupConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), - metrics.Instrument( - http.MethodGet, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", - srv.RouteGetNamespaceRulesConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}"), - metrics.Instrument( - http.MethodGet, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}/{Groupname}", - srv.RouteGetRulegGroupConfig, - m, - ), - ) - group.Get( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules"), - metrics.Instrument( - http.MethodGet, - "/api/ruler/{Recipient}/api/v1/rules", - srv.RouteGetRulesConfig, - m, - ), - ) - group.Post( - toMacaronPath("/api/ruler/{Recipient}/api/v1/rules/{Namespace}"), - binding.Bind(apimodels.PostableRuleGroupConfig{}), - metrics.Instrument( - http.MethodPost, - "/api/ruler/{Recipient}/api/v1/rules/{Namespace}", - srv.RoutePostNameRulesConfig, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - - - - - diff --git a/pkg/services/ngalert/api/generated_base_api_testing.go-e b/pkg/services/ngalert/api/generated_base_api_testing.go-e deleted file mode 100644 index d07f83749bce..000000000000 --- a/pkg/services/ngalert/api/generated_base_api_testing.go-e +++ /dev/null @@ -1,63 +0,0 @@ -/*Package api contains base API implementation of unified alerting - * - *Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) - * - *Do not manually edit these files, please find ngalert/api/swagger-codegen/ for commands on how to generate them. - */ - -package api - -import ( - "github.com/go-macaron/binding" - - "github.com/grafana/grafana/pkg/api/routing" - "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" - "github.com/grafana/grafana/pkg/services/ngalert/metrics" - "github.com/grafana/grafana/pkg/middleware" -) - -type TestingApiService interface { - RouteEvalQueries(*models.ReqContext, apimodels.EvalQueriesPayload) response.Response - RouteTestReceiverConfig(*models.ReqContext, apimodels.ExtendedReceiver) response.Response - RouteTestRuleConfig(*models.ReqContext, apimodels.TestRulePayload) response.Response -} - -func (api *API) RegisterTestingApiEndpoints(srv TestingApiService, m *metrics.Metrics) { - api.RouteRegister.Group("", func(group routing.RouteRegister){ - group.Post( - toMacaronPath("/api/v1/eval"), - binding.Bind(apimodels.EvalQueriesPayload{}), - metrics.Instrument( - http.MethodPost, - "/api/v1/eval", - srv.RouteEvalQueries, - m, - ), - ) - group.Post( - toMacaronPath("/api/v1/receiver/test/{Recipient}"), - binding.Bind(apimodels.ExtendedReceiver{}), - metrics.Instrument( - http.MethodPost, - "/api/v1/receiver/test/{Recipient}", - srv.RouteTestReceiverConfig, - m, - ), - ) - group.Post( - toMacaronPath("/api/v1/rule/test/{Recipient}"), - binding.Bind(apimodels.TestRulePayload{}), - metrics.Instrument( - http.MethodPost, - "/api/v1/rule/test/{Recipient}", - srv.RouteTestRuleConfig, - m, - ), - ) - }, middleware.ReqSignedIn) -} - - - From 0392e5271cc7cf1b49a459087f07115f3113c242 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Wed, 9 Jun 2021 13:29:03 +0300 Subject: [PATCH 16/16] Fix /status missing receivers --- .../api/tooling/definitions/alertmanager.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go index 2e8fb2737c3e..28b4913f38b1 100644 --- a/pkg/services/ngalert/api/tooling/definitions/alertmanager.go +++ b/pkg/services/ngalert/api/tooling/definitions/alertmanager.go @@ -7,7 +7,6 @@ import ( "reflect" "github.com/go-openapi/strfmt" - "github.com/pkg/errors" amv2 "github.com/prometheus/alertmanager/api/v2/models" "github.com/prometheus/alertmanager/config" @@ -150,16 +149,29 @@ func (s *GettableStatus) UnmarshalJSON(b []byte) error { return err } - c := Config{} + c := config.Config{} if err := yaml.Unmarshal([]byte(*amStatus.Config.Original), &c); err != nil { return err } s.Cluster = amStatus.Cluster - s.Config = &PostableApiAlertingConfig{Config: c} + s.Config = &PostableApiAlertingConfig{Config: Config{ + Global: c.Global, + Route: c.Route, + InhibitRules: c.InhibitRules, + Templates: c.Templates, + }} s.Uptime = amStatus.Uptime s.VersionInfo = amStatus.VersionInfo + type overrides struct { + Receivers *[]*PostableApiReceiver `yaml:"receivers,omitempty" json:"receivers,omitempty"` + } + + if err := yaml.Unmarshal([]byte(*amStatus.Config.Original), &overrides{Receivers: &s.Config.Receivers}); err != nil { + return err + } + return nil }