Skip to content

Commit

Permalink
Add API method get_alertrules_all
Browse files Browse the repository at this point in the history
Added REST API wrapper for v1/provisioning/alert-rules.
  • Loading branch information
harish422 authored and amotl committed Jul 30, 2023
1 parent 07bbe2a commit 8d01c16
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions grafana_client/elements/alertingprovisioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
6 changes: 6 additions & 0 deletions test/elements/test_alertingprovisioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8d01c16

Please sign in to comment.