From 355be158b7fb27b71ac37a3821916346536125c0 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 31 May 2021 11:18:29 +0300 Subject: [PATCH] [Alerting]: fix/cleanup API examples (#34588) --- ...m-alertmanager-recipient-unauthorized.http | 101 -------- .../test-data/am-alertmanager-recipient.http | 33 ++- .../am-grafana-recipient-unauthorized.http | 96 ------- .../api/test-data/post-user-config.json | 19 -- .../ruler-grafana-recipient-unauthorized.http | 236 ------------------ .../ruler-lotex-recipient-unauthorized.http | 148 ----------- 6 files changed, 16 insertions(+), 617 deletions(-) delete mode 100644 pkg/services/ngalert/api/test-data/am-alertmanager-recipient-unauthorized.http delete mode 100644 pkg/services/ngalert/api/test-data/am-grafana-recipient-unauthorized.http delete mode 100644 pkg/services/ngalert/api/test-data/ruler-grafana-recipient-unauthorized.http delete mode 100644 pkg/services/ngalert/api/test-data/ruler-lotex-recipient-unauthorized.http diff --git a/pkg/services/ngalert/api/test-data/am-alertmanager-recipient-unauthorized.http b/pkg/services/ngalert/api/test-data/am-alertmanager-recipient-unauthorized.http deleted file mode 100644 index 07ef355bd79..00000000000 --- a/pkg/services/ngalert/api/test-data/am-alertmanager-recipient-unauthorized.http +++ /dev/null @@ -1,101 +0,0 @@ -@alertManagerDatasourceID = 36 - -### -# create AM configuration -POST http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/config/api/v1/alerts -content-type: application/json - -{ - "template_files": {}, - "alertmanager_config": { - "global": { - "smtp_smarthost": "localhost:25", - "smtp_from": "youraddress@example.org", - }, - "receivers": [ - { - "name": "example-email", - "email_configs": { - "to": "youraddress@example.org" - } - } - ], - "route": { - "receiver": "example-email", - "routes": [], - "group_wait": "1s", - "group_interval": "1s", - "repeat_interval": "1s" - }, - "template": [] - } -} - -### -# get latest AM configuration -GET http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/config/api/v1/alerts -content-type: application/json - -### -# delete AM configuration -DELETE http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/config/api/v1/alerts - -### -# create AM alerts -POST http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/alerts -content-type: application/json - -### -# get silences - no silences -GET http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/silences?Filter=foo="bar"&Filter=bar="foo" - -### -# create silence -POST http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/silences -content-type: application/json - -{ - "comment": "string", - "createdBy": "string", - "endsAt": "2023-03-31T14:17:04.419Z", - "matchers": [ - { - "isRegex": true, - "name": "string", - "value": "string" - } - ], - "startsAt": "2021-03-31T13:17:04.419Z" -} - -### -# update silence - does not exist -POST http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/silences -content-type: application/json - -{ - "id": "something", - "comment": "string", - "createdBy": "string", - "endsAt": "2023-03-31T14:17:04.419Z", - "matchers": [ - { - "isRegex": true, - "name": "string", - "value": "string" - } - ], - "startsAt": "2021-03-31T13:17:04.419Z" -} - -### -# get silences -GET http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/silences - -### -# get silence -GET http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/silence/unknown - -### -# delete silence -DELETE http://localhost:3000/api/alertmanager/{{alertManagerDatasourceID}}/api/v2/silence/unknown \ No newline at end of file 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 fa0e46545d6..ecd0d91b688 100644 --- a/pkg/services/ngalert/api/test-data/am-alertmanager-recipient.http +++ b/pkg/services/ngalert/api/test-data/am-alertmanager-recipient.http @@ -11,19 +11,18 @@ content-type: application/json "global": { "resolve_timeout": "4m", "http_config": { - "BasicAuth": null, - "Authorization": null, - "BearerToken": "", - "BearerTokenFile": "", - "ProxyURL": {}, - "TLSConfig": { - "CAFile": "", - "CertFile": "", - "KeyFile": "", - "ServerName": "", - "InsecureSkipVerify": false + "basic_auth": null, + "authorization": null, + "bearer_token": "", + "bearer_token_file": "", + "tls_config": { + "ca_file": "", + "cert_file": "", + "key_file": "", + "server_name": "", + "insecure_skip_verify": false }, - "FollowRedirects": true + "follow_redirects": true }, "smtp_from": "youraddress@example.org", "smtp_hello": "localhost", @@ -48,11 +47,11 @@ content-type: application/json "smarthost": "", "html": "{{ template \"email.default.html\" . }}", "tls_config": { - "CAFile": "", - "CertFile": "", - "KeyFile": "", - "ServerName": "", - "InsecureSkipVerify": false + "ca_file": "", + "cert_file": "", + "key_file": "", + "server_name": "", + "insecure_skip_verify": false } } ] diff --git a/pkg/services/ngalert/api/test-data/am-grafana-recipient-unauthorized.http b/pkg/services/ngalert/api/test-data/am-grafana-recipient-unauthorized.http deleted file mode 100644 index d82a444b40b..00000000000 --- a/pkg/services/ngalert/api/test-data/am-grafana-recipient-unauthorized.http +++ /dev/null @@ -1,96 +0,0 @@ -@grafana = grafana - -### -# create AM configuration -POST http://localhost:3000/api/alertmanager/{{grafana}}/config/api/v1/alerts -content-type: application/json - -< ./post-user-config.json - -### -# get latest AM configuration -GET http://localhost:3000/api/alertmanager/{{grafana}}/config/api/v1/alerts -content-type: application/json - -### -# delete AM configuration -DELETE http://localhost:3000/api/alertmanager/{{grafana}}/config/api/v1/alerts - -### -# create AM alerts -POST http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/alerts -content-type: application/json - -### -# get silences - no silences -GET http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/silences?Filter=foo="bar"&Filter=bar="foo" - -### -# create silence -POST http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/silences -content-type: application/json - -{ - "comment": "string", - "createdBy": "string", - "endsAt": "2023-03-31T14:17:04.419Z", - "matchers": [ - { - "isRegex": true, - "name": "string", - "value": "string" - } - ], - "startsAt": "2021-03-31T13:17:04.419Z" -} - -### -# update silence - does not exist -POST http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/silences -content-type: application/json - -{ - "id": "something", - "comment": "string", - "createdBy": "string", - "endsAt": "2023-03-31T14:17:04.419Z", - "matchers": [ - { - "isRegex": true, - "name": "string", - "value": "string" - } - ], - "startsAt": "2021-03-31T13:17:04.419Z" -} - -### -# create silence - bad paylaad - start time must be before end time -POST http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/silences -content-type: application/json - -{ - "comment": "string", - "createdBy": "string", - "endsAt": "2019-03-31T14:17:04.419Z", - "matchers": [ - { - "isRegex": true, - "name": "string", - "value": "string" - } - ], - "startsAt": "2021-03-31T13:17:04.419Z" -} - -### -# get silences -GET http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/silences - -### -# get silence - unknown -GET http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/silence/unknown - -### -# delete silence - unknown -DELETE http://localhost:3000/api/alertmanager/{{grafana}}/api/v2/silence/unknown diff --git a/pkg/services/ngalert/api/test-data/post-user-config.json b/pkg/services/ngalert/api/test-data/post-user-config.json index 986ddbeb883..6c4259ce19e 100644 --- a/pkg/services/ngalert/api/test-data/post-user-config.json +++ b/pkg/services/ngalert/api/test-data/post-user-config.json @@ -17,7 +17,6 @@ "name": "grafana_managed", "grafana_managed_receiver_configs": [ { - "uid": "alertmanager UID", "name": "an alert manager receiver", "type": "prometheus-alertmanager", "isDefault": false, @@ -37,7 +36,6 @@ } }, { - "uid": "dingding UID", "name": "a dingding receiver", "type": "dingding", "isDefault": false, @@ -55,7 +53,6 @@ "secureSettings": {} }, { - "uid": "discord UID", "name": "a discord receiver", "type": "discord", "isDefault": false, @@ -73,7 +70,6 @@ "secureSettings": {} }, { - "uid": "email UID", "name": "an email receiver", "type": "email", "isDefault": false, @@ -91,7 +87,6 @@ "secureSettings": {} }, { - "uid": "googlechatReceiver UID", "name": "a googlechat receiver", "type": "googlechat", "isDefault": false, @@ -108,7 +103,6 @@ "secureSettings": {} }, { - "uid": "hipchat UID", "name": "a hipchat receiver", "type": "hipchat", "isDefault": false, @@ -127,7 +121,6 @@ "secureSettings": {} }, { - "uid": "kafka UID", "name": "a kafka receiver", "type": "kafka", "isDefault": false, @@ -145,7 +138,6 @@ "secureSettings": {} }, { - "uid": "line UID", "name": "a line receiver", "type": "line", "isDefault": false, @@ -158,7 +150,6 @@ } }, { - "uid": "opsgenie UID", "name": "a opsgenie receiver", "type": "opsgenie", "isDefault": false, @@ -171,7 +162,6 @@ } }, { - "uid": "pagerduty UID", "name": "a pagerduty receiver", "type": "pagerduty", "isDefault": false, @@ -189,7 +179,6 @@ } }, { - "uid": "pushover UID", "name": "a pushover receiver", "type": "pushover", "isDefault": false, @@ -217,7 +206,6 @@ } }, { - "uid": "sensu UID", "name": "a sensu receiver", "type": "sensu", "isDefault": false, @@ -237,7 +225,6 @@ "secureSettings": {} }, { - "uid": "sensugo UID", "name": "a sensugo receiver", "type": "sensugo", "isDefault": false, @@ -260,7 +247,6 @@ } }, { - "uid": "slack UID", "name": "a slack receiver", "type": "slack", "isDefault": false, @@ -285,7 +271,6 @@ } }, { - "uid": "teams UID", "name": "a teams receiver", "type": "teams", "isDefault": false, @@ -302,7 +287,6 @@ "secureSettings": {} }, { - "uid": "telegram UID", "name": "a telegram receiver", "type": "telegram", "isDefault": false, @@ -321,7 +305,6 @@ } }, { - "uid": "threema UID", "name": "a threema receiver", "type": "threema", "isDefault": false, @@ -341,7 +324,6 @@ } }, { - "uid": "victorops UID", "name": "a victorops receiver", "type": "victorops", "isDefault": false, @@ -358,7 +340,6 @@ "secureSettings": {} }, { - "uid": "webhook UID", "name": "a webhook receiver", "type": "webhook", "isDefault": false, diff --git a/pkg/services/ngalert/api/test-data/ruler-grafana-recipient-unauthorized.http b/pkg/services/ngalert/api/test-data/ruler-grafana-recipient-unauthorized.http deleted file mode 100644 index 7fca8a99be5..00000000000 --- a/pkg/services/ngalert/api/test-data/ruler-grafana-recipient-unauthorized.http +++ /dev/null @@ -1,236 +0,0 @@ -@grafanaRecipient = grafana - -// should point to an existing folder named alerting -@namespace1 = alerting - -// create group42 under unknown namespace - it should fail -POST http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/unknown -content-type: application/json - -< ./post-rulegroup-42.json - -### -// create group42 -POST http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} -content-type: application/json - -< ./post-rulegroup-42.json - -### -// create group101 -POST http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} -content-type: application/json - -< ./post-rulegroup-101.json - -### -// get group42 rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}}/group42 - -### -// get group101 rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}}/group101 - -### -// get namespace rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} - -### -// get org rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules - -### -// delete group42 rules -DELETE http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}}/group42 - -### -// get namespace rules - only group101 should be listed -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} - -### -// delete namespace rules -DELETE http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} - -### -// get namespace rules - no rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} - -### -// recreate group42 -POST http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} -content-type: application/json - -{ - "name": "group42", - "interval": "10s", - "rules": [ - { - "grafana_alert": { - "title": "prom query with SSE", - "condition": "condition", - "data": [ - { - "refId": "query", - "queryType": "", - "relativeTimeRange": { - "from": 18000, - "to": 10800 - }, - "datasourceUid": "000000002", - "model": { - "expr": "http_request_duration_microseconds_count", - "hide": false, - "interval": "", - "intervalMs": 1000, - "legendFormat": "", - "maxDataPoints": 100, - "refId": "query" - } - }, - { - "refId": "reduced", - "queryType": "", - "relativeTimeRange": { - "from": 18000, - "to": 10800 - }, - "datasourceUid": "-100", - "model": { - "expression": "query", - "hide": false, - "intervalMs": 1000, - "maxDataPoints": 100, - "reducer": "mean", - "refId": "reduced", - "type": "reduce" - } - }, - { - "refId": "condition", - "queryType": "", - "relativeTimeRange": { - "from": 18000, - "to": 10800 - }, - "datasourceUid": "-100", - "model": { - "expression": "$reduced > 10", - "hide": false, - "intervalMs": 1000, - "maxDataPoints": 100, - "refId": "condition", - "type": "math" - } - } - ], - "no_data_state": "NoData", - "exec_err_state": "Alerting" - } - } - ] -} - - -### -// get group42 rules -# @name getRule -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}}/group42 - -### -// update group42 interval and condition threshold -POST http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} -content-type: application/json - -{ - "name": "group42", - "interval": "20s", - "rules": [ - { - "grafana_alert": { - "title": "prom query with SSE", - "condition": "condition", - "uid": "UID", - "data": [ - { - "refId": "query", - "queryType": "", - "relativeTimeRange": { - "from": 18000, - "to": 10800 - }, - "datasourceUid": "000000002", - "model": { - "expr": "http_request_duration_microseconds_count", - "hide": false, - "interval": "", - "intervalMs": 1000, - "legendFormat": "", - "maxDataPoints": 100, - "refId": "query" - } - }, - { - "refId": "reduced", - "queryType": "", - "relativeTimeRange": { - "from": 18000, - "to": 10800 - }, - "datasourceUid": "-100", - "model": { - "expression": "query", - "hide": false, - "intervalMs": 1000, - "maxDataPoints": 100, - "reducer": "mean", - "refId": "reduced", - "type": "reduce" - } - }, - { - "refId": "condition", - "queryType": "", - "relativeTimeRange": { - "from": 18000, - "to": 10800 - }, - "datasourceUid": "-100", - "model": { - "expression": "$reduced > 42", - "hide": false, - "intervalMs": 1000, - "maxDataPoints": 100, - "refId": "condition", - "type": "math" - } - } - ], - "no_data_state": "NoData", - "exec_err_state": "Alerting" - } - } - ] -} - -### -// get group42 rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}}/group42 - -### -// update group42 - delete all rules -POST http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} -content-type: application/json - -{ - "name": "group42", - "interval": "20s", - "rules": [] -} - -### -// get group42 rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}}/group42 - -### -// get namespace rules -GET http://localhost:3000/api/ruler/{{grafanaRecipient}}/api/v1/rules/{{namespace1}} diff --git a/pkg/services/ngalert/api/test-data/ruler-lotex-recipient-unauthorized.http b/pkg/services/ngalert/api/test-data/ruler-lotex-recipient-unauthorized.http deleted file mode 100644 index e5e9812d831..00000000000 --- a/pkg/services/ngalert/api/test-data/ruler-lotex-recipient-unauthorized.http +++ /dev/null @@ -1,148 +0,0 @@ -@lokiDatasourceID = 32 -@prometheusDatasourceID = 35 - -// should point to an existing folder named alerting -@namespace1 = test - -// create/update test namespace group42 rulegroup -POST http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} -content-type: application/json - -{ - "name": "group42", - "rules": [ - { - "alert": "logs_exist", - "expr": "rate({cluster=\"us-central1\", job=\"loki-prod/loki-canary\"}[1m]) > 0", - "for": "1m" - } - ] -} - -### -// create group101 -POST http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} -content-type: application/json - -{ - "name": "group101", - "rules": [ - { - "alert": "logs_exist", - "expr": "rate({cluster=\"us-central1\", job=\"loki-prod/loki-canary\"}[1m]) > 0", - "for": "2m" - } - ] -} - -### -// get group42 rules -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group42 - -### -// get group101 rules -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group101 - -### -// get namespace rules -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// get org rules -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules - -### -// delete group42 rules -DELETE http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group42 - -### -// get namespace rules - only group101 should be listed -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// delete namespace rules -DELETE http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// get namespace rules - no rules -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// get group42 rules -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group42 - -### -// get namespace rules -GET http://localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// create/update test namespace group42 rulegroup -POST http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} -content-type: application/json - -{ - "name": "group42", - "rules": [ - { - "alert": "logs_exist", - "expr": "rate({cluster=\"us-central1\", job=\"loki-prod/loki-canary\"}[1m]) > 0", - "for": "1m" - } - ] -} - -### -// create group101 -POST http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} -content-type: application/json - -{ - "name": "group101", - "rules": [ - { - "alert": "logs_exist", - "expr": "rate({cluster=\"us-central1\", job=\"loki-prod/loki-canary\"}[1m]) > 0", - "for": "2m" - } - ] -} - -### -// get group42 rules -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group42 - -### -// get group101 rules -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group101 - -### -// get namespace rules -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// get org rules -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules - -### -// delete group42 rules -DELETE http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group42 - -### -// get namespace rules - only group101 should be listed -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// delete namespace rules -DELETE http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// get namespace rules - no rules -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} - -### -// get group42 rules -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group42 - -### -// get namespace rules -GET http://localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} \ No newline at end of file