diff --git a/changelogs/fragments/382-notification-channel-deprecation.yml b/changelogs/fragments/382-notification-channel-deprecation.yml new file mode 100644 index 00000000..9af1cf01 --- /dev/null +++ b/changelogs/fragments/382-notification-channel-deprecation.yml @@ -0,0 +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 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. diff --git a/plugins/modules/grafana_notification_channel.py b/plugins/modules/grafana_notification_channel.py index 30b5b112..24e4e3c0 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: @@ -96,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: @@ -623,6 +632,31 @@ 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 v10", + ) + + def get_version(self): + r, info = fetch_url( + self._module, + "%s/api/health" % self.grafana_url, + headers=self.headers, + method="GET", + ) + 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( @@ -757,6 +791,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( diff --git a/tests/integration/targets/grafana_notification_channel/tasks/main.yml b/tests/integration/targets/grafana_notification_channel/tasks/main.yml index af0b2f86..7d1dec69 100644 --- a/tests/integration/targets/grafana_notification_channel/tasks/main.yml +++ b/tests/integration/targets/grafana_notification_channel/tasks/main.yml @@ -1,34 +1,32 @@ --- -- 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: + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + name: 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