Skip to content

Commit ba367cd

Browse files
harish422amotl
authored andcommitted
Add API method get_alertrules_all
Added REST API wrapper for v1/provisioning/alert-rules.
1 parent 07bbe2a commit ba367cd

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Add missing argument `dashboard_uid` to `get_annotation` method.
66
Thanks, @nikita-b.
7+
* Add API method `get_alertrules_all`. Thanks, @harish422.
78

89

910
## 3.5.0 (2022-12-07)

grafana_client/elements/alertingprovisioning.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ def __init__(self, client):
66
super(AlertingProvisioning, self).__init__(client)
77
self.client = client
88

9+
def get_alertrules_all(self):
10+
"""
11+
Gets all alert rules
12+
@return:
13+
"""
14+
get_alertrules_all_path = "/v1/provisioning/alert-rules"
15+
r = self.client.GET(get_alertrules_all_path)
16+
return r
17+
918
def get_alertrule(self, alertrule_uid):
1019
"""
1120

test/elements/test_alertingprovisioning.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class AlertingProvisioningTestCase(unittest.TestCase):
2525
def setUp(self):
2626
self.grafana = GrafanaApi(("admin", "admin"), host="localhost", url_path_prefix="", protocol="http")
2727

28+
@requests_mock.Mocker()
29+
def test_get_alertrules_all(self, m):
30+
m.get("http://localhost/api/v1/provisioning/alert-rules", json=[ALERTRULE])
31+
response = self.grafana.alertingprovisioning.get_alertrules_all()
32+
self.assertEqual(response[0]["uid"], "bUUGqLiVk")
33+
2834
@requests_mock.Mocker()
2935
def test_get_alertrule(self, m):
3036
m.get("http://localhost/api/v1/provisioning/alert-rules/bUUGqLiVk", json=ALERTRULE)

0 commit comments

Comments
 (0)