diff --git a/changelogs/fragments/add grafana_silence module.yml b/changelogs/fragments/add grafana_silence module.yml new file mode 100644 index 00000000..b78be00d --- /dev/null +++ b/changelogs/fragments/add grafana_silence module.yml @@ -0,0 +1,2 @@ +major_changes: +- grafana_silence ; adding new module to create and delete silences through the API \ No newline at end of file diff --git a/plugins/modules/grafana_silence.py b/plugins/modules/grafana_silence.py index 6a22a0f6..e4a97e90 100644 --- a/plugins/modules/grafana_silence.py +++ b/plugins/modules/grafana_silence.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # -# Copyright: (c) 2023, RĂ©mi REY (@rrey) +# Copyright: (c) 2023, flkhndlr (@flkhndlr) from __future__ import absolute_import, division, print_function @@ -23,7 +23,7 @@ --- module: grafana_silence author: - - Falk (@flkhndlr) + - flkhndlr (@flkhndlr) version_added: "1.5.5" short_description: Manage Grafana Silences description: @@ -169,7 +169,6 @@ from ansible.module_utils.urls import fetch_url, basic_auth_header from ansible.module_utils._text import to_text from ansible_collections.community.grafana.plugins.module_utils import base -from ansible.module_utils.six.moves.urllib.parse import quote __metaclass__ = type @@ -231,20 +230,20 @@ def get_version(self): return {"major": int(major), "minor": int(minor), "rev": int(rev)} raise GrafanaError("Failed to retrieve version from '%s'" % url) - def create_silence(self, comment, createdBy, startsAt ,endsAt, matchers): + def create_silence(self, comment, created_by, starts_at, ends_at, matchers): url = "/api/alertmanager/grafana/api/v2/silences" - silence = dict(comment=comment, createdBy=createdBy, startsAt=startsAt, endsAt=endsAt, matchers=matchers) + silence = dict(comment=comment, createdBy=created_by, startsAt=starts_at, endsAt=ends_at, matchers=matchers) response = self._send_request(url, data=silence, headers=self.headers, method="POST") return response - def get_silence(self, comment, createdBy, startsAt ,endsAt, matchers): + def get_silence(self, comment, created_by, starts_at, ends_at, matchers): url = "/api/alertmanager/grafana/api/v2/silences" responses = self._send_request(url, headers=self.headers, method="GET") for response in responses: - if response["comment"] == comment and response["createdBy"] == createdBy and \ - response["startsAt"] == startsAt and response["endsAt"] == endsAt and \ + if response["comment"] == comment and response["createdBy"] == created_by and \ + response["startsAt"] == starts_at and response["endsAt"] == ends_at and \ response["matchers"] == matchers: return response else: @@ -267,7 +266,6 @@ def delete_silence(self, silence_id): return response - def setup_module_object(): module = AnsibleModule( argument_spec=argument_spec,