Skip to content

Commit

Permalink
add fragment and improve module code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
flkhndlr committed Jan 3, 2024
1 parent fb05b23 commit 5d8011b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/add grafana_silence module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
major_changes:
- grafana_silence ; adding new module to create and delete silences through the API
16 changes: 7 additions & 9 deletions plugins/modules/grafana_silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright: (c) 2023, Rémi REY (@rrey)
# Copyright: (c) 2023, flkhndlr (@flkhndlr)

from __future__ import absolute_import, division, print_function

DOCUMENTATION = '''
---
module: grafana_silence
author:
- Falk (@flkhndlr)
- flkhndlr (@flkhndlr)
version_added: "1.5.5"
short_description: Manage Grafana Silences
description:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -267,7 +266,6 @@ def delete_silence(self, silence_id):
return response



def setup_module_object():
module = AnsibleModule(
argument_spec=argument_spec,
Expand Down

0 comments on commit 5d8011b

Please sign in to comment.