diff --git a/matrix_alertbot/alertmanager.py b/matrix_alertbot/alertmanager.py index e6c7efb..11b22c0 100644 --- a/matrix_alertbot/alertmanager.py +++ b/matrix_alertbot/alertmanager.py @@ -105,7 +105,7 @@ class AlertmanagerClient: async def delete_silence(self, silence_id: str) -> None: silence = await self.get_silence(silence_id) - silence_state = silence["state"] + silence_state = silence["status"]["state"] if silence_state == "expired": raise SilenceExpiredError( f"Cannot delete already expired silence with ID {silence_id}" diff --git a/tests/test_alertmanager.py b/tests/test_alertmanager.py index ecc41a4..90ca767 100644 --- a/tests/test_alertmanager.py +++ b/tests/test_alertmanager.py @@ -43,8 +43,8 @@ class AbstractFakeAlertmanagerServer: ] ) self.app["silences"] = [ - {"id": "silence1", "state": "active"}, - {"id": "silence2", "state": "expired"}, + {"id": "silence1", "status": {"state": "active"}}, + {"id": "silence2", "status": {"state": "expired"}}, ] self.runner = web.AppRunner(self.app) @@ -114,7 +114,7 @@ class FakeAlertmanagerServer(AbstractFakeAlertmanagerServer): silence = await request.json() if silence["id"] is None: silence["id"] = "silence1" - silence["state"] = "active" + silence["status"] = {"state": "active"} silences.append(silence) return web.Response( @@ -229,8 +229,8 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): self.assertEqual( [ - {"id": "silence1", "state": "active"}, - {"id": "silence2", "state": "expired"}, + {"id": "silence1", "status": {"state": "active"}}, + {"id": "silence2", "status": {"state": "expired"}}, ], silences, ) @@ -305,11 +305,11 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): silence2 = await alertmanager.get_silence("silence2") self.assertEqual( - {"id": "silence1", "state": "active"}, + {"id": "silence1", "status": {"state": "active"}}, silence1, ) self.assertEqual( - {"id": "silence2", "state": "expired"}, + {"id": "silence2", "status": {"state": "expired"}}, silence2, ) @@ -350,7 +350,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): self.assertEqual( { "id": "silence1", - "state": "active", + "status": {"state": "active"}, "matchers": [ { "name": "alertname", @@ -384,7 +384,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): self.assertEqual( { "id": "silence2", - "state": "active", + "status": {"state": "active"}, "matchers": [ { "name": "alertname", @@ -416,7 +416,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): self.assertEqual( { "id": "silence1", - "state": "active", + "status": {"state": "active"}, "matchers": [ { "name": "alertname", @@ -450,7 +450,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): self.assertEqual( { "id": "silence1", - "state": "active", + "status": {"state": "active"}, "matchers": [ { "name": "alertname", @@ -510,7 +510,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): await alertmanager.delete_silence("silence1") silences = await alertmanager.get_silences() - self.assertEqual([{"id": "silence2", "state": "expired"}], silences) + self.assertEqual([{"id": "silence2", "status": {"state": "expired"}}], silences) async def test_delete_silence_raise_silence_expired(self) -> None: async with FakeAlertmanagerServer() as fake_alertmanager_server: @@ -525,8 +525,8 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase): self.assertEqual( [ - {"id": "silence1", "state": "active"}, - {"id": "silence2", "state": "expired"}, + {"id": "silence1", "status": {"state": "active"}}, + {"id": "silence2", "status": {"state": "expired"}}, ], silences, )