From ef51ce8b106bb19b2f03a65d817f15f498ff1c39 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:44:12 +0200 Subject: [PATCH 01/10] docs: meta runtime deprecation notification channel --- meta/runtime.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/meta/runtime.yml b/meta/runtime.yml index 529b9ea0..7f45047b 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -13,3 +13,9 @@ action_groups: - grafana_team - grafana_user - grafana_silence +plugin_routing: + modules: + grafana_notification_channel: + deprecation: + removal_version: 3.0.0 + warning_text: Legacy alerting is removed in Grafana version 11, use community.grafana.grafana_contact_point instead. From 787ee342154b8eb41d24b0f339a8f06e21e4c7e3 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:44:41 +0200 Subject: [PATCH 02/10] docs: plugin module deprecation notification_channel --- plugins/modules/grafana_notification_channel.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/modules/grafana_notification_channel.py b/plugins/modules/grafana_notification_channel.py index 30b5b112..42ea442d 100644 --- a/plugins/modules/grafana_notification_channel.py +++ b/plugins/modules/grafana_notification_channel.py @@ -33,6 +33,10 @@ short_description: Manage Grafana Notification Channels description: - Create/Update/Delete Grafana Notification Channels via API. +deprecated: + removed_in: "3.0.0" + why: Legacy alerting is removed in Grafana version 11. + alternative: Use M(community.grafana.grafana_contact_point) instead. options: org_id: description: From 9f94c10b780c728529e86368fa595800f64507cc Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:48:43 +0200 Subject: [PATCH 03/10] docs: changelog fragment --- changelogs/fragments/382-notification-channel-deprecation.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/382-notification-channel-deprecation.yml diff --git a/changelogs/fragments/382-notification-channel-deprecation.yml b/changelogs/fragments/382-notification-channel-deprecation.yml new file mode 100644 index 00000000..3410b084 --- /dev/null +++ b/changelogs/fragments/382-notification-channel-deprecation.yml @@ -0,0 +1,3 @@ +--- +deprecated_features: + - Deprecate `grafana_notification_channel` with removal in version 3.0.0 From 0c3138f6e67b5d913f21ba37a0d302b51d878d92 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:21:15 +0200 Subject: [PATCH 04/10] feat: notification channel get version with skip version check --- .../modules/grafana_notification_channel.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugins/modules/grafana_notification_channel.py b/plugins/modules/grafana_notification_channel.py index 42ea442d..324836ed 100644 --- a/plugins/modules/grafana_notification_channel.py +++ b/plugins/modules/grafana_notification_channel.py @@ -100,6 +100,11 @@ default: false description: - Disable the resolve message. + skip_version_check: + description: + - Skip Grafana version check and try to reach api endpoint anyway. + type: bool + default: false reminder_frequency: type: str description: @@ -627,6 +632,29 @@ def __init__(self, module): ) # }}} self.grafana_url = clean_url(module.params.get("url")) + if module.params.get("skip_version_check") is False: + try: + grafana_version = self.get_version() + except GrafanaAPIException as e: + self._module.fail_json(failed=True, msg=to_text(e)) + if grafana_version["major"] >= 11: + self._module.fail_json( + failed=True, + msg="Legacy Alerting API is available up to Grafana v11", + ) + + def get_version(self): + r, info = fetch_url( + self._module, + "%s/api/health" % self.grafana_url, + headers=self.headers, + method="GET", + ) + version = r.get("version") + if version is not None: + major, minor, rev = version.split(".") + return {"major": int(major), "minor": int(minor), "rev": int(rev)} + raise GrafanaAPIException("Failed to retrieve version: %s" % info) def grafana_switch_organisation(self, grafana_url, org_id): r, info = fetch_url( @@ -761,6 +789,7 @@ def main(): is_default=dict(type="bool", default=False), include_image=dict(type="bool", default=False), disable_resolve_message=dict(type="bool", default=False), + skip_version_check=dict(type="bool", default=False), reminder_frequency=dict(type="str"), dingding_url=dict(type="str"), dingding_message_type=dict( From 820c50e99d63795e6edc0240d4b6464b2542519a Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:28:23 +0200 Subject: [PATCH 05/10] chore: version ref --- plugins/modules/grafana_notification_channel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/grafana_notification_channel.py b/plugins/modules/grafana_notification_channel.py index 324836ed..c092e9cf 100644 --- a/plugins/modules/grafana_notification_channel.py +++ b/plugins/modules/grafana_notification_channel.py @@ -640,7 +640,7 @@ def __init__(self, module): if grafana_version["major"] >= 11: self._module.fail_json( failed=True, - msg="Legacy Alerting API is available up to Grafana v11", + msg="Legacy Alerting API is available up to Grafana v10", ) def get_version(self): From 13bec564e3c987944d1c0ad35e615d813dc53c8d Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:28:51 +0200 Subject: [PATCH 06/10] test: notification channel check for legacy api --- .../tasks/main.yml | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/tests/integration/targets/grafana_notification_channel/tasks/main.yml b/tests/integration/targets/grafana_notification_channel/tasks/main.yml index af0b2f86..4684926a 100644 --- a/tests/integration/targets/grafana_notification_channel/tasks/main.yml +++ b/tests/integration/targets/grafana_notification_channel/tasks/main.yml @@ -1,34 +1,29 @@ --- -- block: - - ansible.builtin.include_tasks: - file: dingding.yml - - ansible.builtin.include_tasks: - file: discord.yml - - ansible.builtin.include_tasks: - file: email.yml - - ansible.builtin.include_tasks: - file: googlechat.yml - - ansible.builtin.include_tasks: - file: hipchat.yml - - ansible.builtin.include_tasks: - file: kafka.yml - - ansible.builtin.include_tasks: - file: teams.yml - - ansible.builtin.include_tasks: - file: opsgenie.yml - - ansible.builtin.include_tasks: - file: pagerduty.yml - - ansible.builtin.include_tasks: - file: prometheus.yml - - ansible.builtin.include_tasks: - file: pushover.yml - - ansible.builtin.include_tasks: - file: sensu.yml - - ansible.builtin.include_tasks: - file: slack-and-beyond.yml - - ansible.builtin.include_tasks: - file: telegram.yml - - ansible.builtin.include_tasks: - file: victorops.yml - - ansible.builtin.include_tasks: - file: webhook.yml + +- name: Check for support of API endpoint + register: result + ignore_errors: true + community.grafana.grafana_notification_channel: + title: apitest + state: absent + +- name: Include notification channel task files + ansible.builtin.include_tasks: "{{ item }}.yml" + when: "result.msg | default('') != 'Legacy Alerting API is available up to Grafana v10'" + loop: + - dingding + - discord + - email + - googlechat + - hipchat + - kafka + - teams + - opsgenie + - pagerduty + - prometheus + - pushover + - sensu + - slack-and-beyond + - telegram + - victorops + - webhook From b7f7746da30b0edb61d9cc08bf61cee85715083e Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:33:19 +0200 Subject: [PATCH 07/10] test: grafana attributes --- .../targets/grafana_notification_channel/tasks/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/targets/grafana_notification_channel/tasks/main.yml b/tests/integration/targets/grafana_notification_channel/tasks/main.yml index 4684926a..7161088b 100644 --- a/tests/integration/targets/grafana_notification_channel/tasks/main.yml +++ b/tests/integration/targets/grafana_notification_channel/tasks/main.yml @@ -4,6 +4,9 @@ register: result ignore_errors: true community.grafana.grafana_notification_channel: + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" title: apitest state: absent From a7e584dbb46e30ab352ff8829348a30e7fdb67ac Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:19:55 +0200 Subject: [PATCH 08/10] fix: read output of health api if ok --- plugins/modules/grafana_notification_channel.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/modules/grafana_notification_channel.py b/plugins/modules/grafana_notification_channel.py index c092e9cf..24e4e3c0 100644 --- a/plugins/modules/grafana_notification_channel.py +++ b/plugins/modules/grafana_notification_channel.py @@ -650,11 +650,13 @@ def get_version(self): headers=self.headers, method="GET", ) - version = r.get("version") - if version is not None: - major, minor, rev = version.split(".") - return {"major": int(major), "minor": int(minor), "rev": int(rev)} - raise GrafanaAPIException("Failed to retrieve version: %s" % info) + if info["status"] == 200: + version = json.loads(to_text(r.read())).get("version") + if version is not None: + major, minor, rev = version.split(".") + return {"major": int(major), "minor": int(minor), "rev": int(rev)} + else: + raise GrafanaAPIException("Failed to retrieve version: %s" % info) def grafana_switch_organisation(self, grafana_url, org_id): r, info = fetch_url( From eaf5be9d5cae27c6c33bb26b035cdfb27f01a785 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:20:31 +0200 Subject: [PATCH 09/10] test: wrong arg --- .../targets/grafana_notification_channel/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/grafana_notification_channel/tasks/main.yml b/tests/integration/targets/grafana_notification_channel/tasks/main.yml index 7161088b..7d1dec69 100644 --- a/tests/integration/targets/grafana_notification_channel/tasks/main.yml +++ b/tests/integration/targets/grafana_notification_channel/tasks/main.yml @@ -7,7 +7,7 @@ grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" - title: apitest + name: apitest state: absent - name: Include notification channel task files From 45573052306c30b971a57a7b2afe8cfe4436ea54 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:23:37 +0200 Subject: [PATCH 10/10] docs: changelog fragment --- changelogs/fragments/382-notification-channel-deprecation.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelogs/fragments/382-notification-channel-deprecation.yml b/changelogs/fragments/382-notification-channel-deprecation.yml index 3410b084..9af1cf01 100644 --- a/changelogs/fragments/382-notification-channel-deprecation.yml +++ b/changelogs/fragments/382-notification-channel-deprecation.yml @@ -1,3 +1,5 @@ --- deprecated_features: - Deprecate `grafana_notification_channel` with removal in version 3.0.0 +trivial: + - Check Grafana version for `grafana_notification_channel` integration tests