Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grafana_notification_channel): deprecation #382

Merged
merged 10 commits into from
Jul 2, 2024
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
35 changes: 35 additions & 0 deletions plugins/modules/grafana_notification_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading