From 9cc5b1adaf5e136013ff79a0efb2987255d25bd1 Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:11:25 +0530 Subject: [PATCH] Add POST /api/v1/alerts (#10) Signed-off-by: Ganesh Vernekar --- pkg/api/alertmanager.go | 14 ++++++++++++++ spec.json | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/pkg/api/alertmanager.go b/pkg/api/alertmanager.go index 74efb8d5854..f687da7cc7d 100644 --- a/pkg/api/alertmanager.go +++ b/pkg/api/alertmanager.go @@ -38,6 +38,14 @@ import ( // 200: GettableAlerts // 400: ValidationError +// swagger:route POST /api/v1/alerts alertmanager RoutePostAmAlerts +// +// create alertmanager alerts +// +// Responses: +// 200: Ack +// 400: ValidationError + // swagger:route GET /api/v1/alerts/groups alertmanager RouteGetAmAlertGroups // // get alertmanager alerts @@ -136,6 +144,12 @@ type AlertsParams struct { Receivers []string `json:"receivers"` } +// swagger:parameters RoutePostAmAlerts +type PostableAlerts struct { + // in:body + PostableAlerts []amv2.PostableAlert `yaml:"" json:""` +} + // swagger:parameters RoutePostAlertingConfig type BodyAlertingConfig struct { // in:body diff --git a/spec.json b/spec.json index d9a4b8ad34a..f01dc6d04ae 100644 --- a/spec.json +++ b/spec.json @@ -80,6 +80,39 @@ } } } + }, + "post": { + "description": "create alertmanager alerts", + "tags": [ + "alertmanager" + ], + "operationId": "RoutePostAmAlerts", + "parameters": [ + { + "name": "PostableAlerts", + "in": "body", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/postableAlert" + } + } + } + ], + "responses": { + "200": { + "description": "Ack", + "schema": { + "$ref": "#/definitions/Ack" + } + }, + "400": { + "description": "ValidationError", + "schema": { + "$ref": "#/definitions/ValidationError" + } + } + } } }, "/api/v1/alerts/groups": { @@ -2296,8 +2329,9 @@ "x-go-package": "github.com/prometheus/common/config" }, "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": "URL is a custom URL type that allows validation at configuration load time.", + "title": "A URL represents a parsed URL (technically, a URI reference).", "properties": { "ForceQuery": { "type": "boolean" @@ -2330,7 +2364,7 @@ "$ref": "#/definitions/Userinfo" } }, - "x-go-package": "github.com/prometheus/common/config" + "x-go-package": "net/url" }, "UpdateDashboardAclCommand": { "type": "object",