From 8d01c16f4bbd60398bd5815188e85b83896b0a04 Mon Sep 17 00:00:00 2001 From: harish422 Date: Fri, 28 Jul 2023 23:50:24 -0700 Subject: [PATCH] Add API method `get_alertrules_all` Added REST API wrapper for v1/provisioning/alert-rules. --- CHANGELOG.md | 1 + grafana_client/elements/alertingprovisioning.py | 9 +++++++++ test/elements/test_alertingprovisioning.py | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d87d3c1..f6ea7ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Add missing argument `dashboard_uid` to `get_annotation` method. Thanks, @nikita-b. +* Add API method `get_alertrules_all`. Thanks, @harish422. ## 3.5.0 (2022-12-07) diff --git a/grafana_client/elements/alertingprovisioning.py b/grafana_client/elements/alertingprovisioning.py index 0adaba0..e3c1c4f 100644 --- a/grafana_client/elements/alertingprovisioning.py +++ b/grafana_client/elements/alertingprovisioning.py @@ -6,6 +6,15 @@ def __init__(self, client): super(AlertingProvisioning, self).__init__(client) self.client = client + def get_alertrules_all(self): + """ + Gets all alert rules + @return: + """ + get_alertrules_all_path = "/v1/provisioning/alert-rules" + r = self.client.GET(get_alertrules_all_path) + return r + def get_alertrule(self, alertrule_uid): """ diff --git a/test/elements/test_alertingprovisioning.py b/test/elements/test_alertingprovisioning.py index 6249e2d..1b2b3d4 100644 --- a/test/elements/test_alertingprovisioning.py +++ b/test/elements/test_alertingprovisioning.py @@ -25,6 +25,12 @@ class AlertingProvisioningTestCase(unittest.TestCase): def setUp(self): self.grafana = GrafanaApi(("admin", "admin"), host="localhost", url_path_prefix="", protocol="http") + @requests_mock.Mocker() + def test_get_alertrules_all(self, m): + m.get("http://localhost/api/v1/provisioning/alert-rules", json=[ALERTRULE]) + response = self.grafana.alertingprovisioning.get_alertrules_all() + self.assertEqual(response[0]["uid"], "bUUGqLiVk") + @requests_mock.Mocker() def test_get_alertrule(self, m): m.get("http://localhost/api/v1/provisioning/alert-rules/bUUGqLiVk", json=ALERTRULE)