Skip to content

Commit

Permalink
Merge branch 'w/127.0/bugfix/use_alertmanager_api_v2_on_metalk8s_moni…
Browse files Browse the repository at this point in the history
…toring_salt_module' into tmp/octopus/q/127.0
  • Loading branch information
bert-e committed Mar 15, 2024
2 parents 0bef13a + 0a612a5 commit ea27320
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
14 changes: 8 additions & 6 deletions salt/_modules/metalk8s_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def add_silence(
}

response = _requests_alertmanager_api(
"api/v1/silences", "POST", json=body, **kwargs
"api/v2/silences", "POST", json=body, **kwargs
)

return response["silenceId"]
Expand All @@ -109,7 +109,7 @@ def delete_silence(silence_id, **kwargs):
64d84a9e-cc6e-41ce-83ff-e84771ff6872
"""
return _requests_alertmanager_api(
f"api/v1/silence/{silence_id}", "DELETE", **kwargs
f"api/v2/silence/{silence_id}", "DELETE", **kwargs
)


Expand All @@ -128,8 +128,9 @@ def get_silences(state=None, **kwargs):
salt-call metalk8s_monitoring.get_silences
salt-call metalk8s_monitoring.get_silences state=active
"""
response = _requests_alertmanager_api("api/v1/silences", "GET", **kwargs)

response = _requests_alertmanager_api("api/v2/silences", "GET", **kwargs)
if response is None or response == []:
return []
if state is not None:
silences = [
silence for silence in response if silence["status"]["state"] == state
Expand All @@ -155,8 +156,9 @@ def get_alerts(state=None, **kwargs):
salt-call metalk8s_monitoring.get_alerts
salt-call metalk8s_monitoring.get_alerts state=suppressed
"""
response = _requests_alertmanager_api("api/v1/alerts", "GET", **kwargs)

response = _requests_alertmanager_api("api/v2/alerts", "GET", **kwargs)
if response is None or response == []:
return []
if state is not None:
alerts = [alert for alert in response if alert["status"]["state"] == state]
else:
Expand Down
16 changes: 16 additions & 0 deletions salt/tests/unit/modules/files/test_metalk8s_monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ get_silences:
result:
- *active_silence

- _id: get_empty
response: []
result: []

- _id: get_none
response: null
result: []

get_alerts:
- _id: without-state
response: &alerts_list
Expand All @@ -203,3 +211,11 @@ get_alerts:
response: *alerts_list
result:
- *active_alert

- _id: get_empty
response: []
result: []

- _id: get_none
response: null
result: []
2 changes: 1 addition & 1 deletion salt/tests/unit/modules/test_metalk8s_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_delete_silence(self):
request_mock.assert_called_once()
self.assertEqual(
request_mock.call_args[0],
("api/v1/silence/d287796c-cf59-4d10-8e5b-d5cc3ff51b9c", "DELETE"),
("api/v2/silence/d287796c-cf59-4d10-8e5b-d5cc3ff51b9c", "DELETE"),
)

@parameterized.expand(
Expand Down

0 comments on commit ea27320

Please sign in to comment.