ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
827 stars 1.52k forks source link

absent state in sensu_silence fails if more then one silencing exists for subscription #5993

Open stefan-as opened 1 year ago

stefan-as commented 1 year ago

Summary

If there is more then one silencing for a given subscription and sensu_silence tries to figure out if a check is already silenced to remove the silencing later on, the code results in false positives. The API request to remove the check fails with 404 response code.

Root cause for the issue can be found within this code path: https://github.com/ansible-collections/community.general/blob/4c4ef80ca9518792bc4e0551864a7929254a27a0/plugins/modules/sensu_silence.py#L145-L150

Given there is a silencing for a specific subscription and a check called check="foo", but we want to remove a silencing for check=None, the mentioned code results in a false positive, even if there is no silencing for check=None. The original bug is to assume that there is only one silencing for a specific subscription and to use a generator to map all silencings into a dict with subscription as keys. https://github.com/ansible-collections/community.general/blob/4c4ef80ca9518792bc4e0551864a7929254a27a0/plugins/modules/sensu_silence.py#L145

Issue Type

Bug Report

Component Name

sensu_silence

Ansible Version

6.6.0

Community.general Version

5.8.0

Configuration

No response

OS / Environment

Arch Linux

Steps to Reproduce

tasks:
  - name: "unsilence monitoring"
    community.general.sensu_silence:
      subscription: "client:{{ inventory_hostname_short }}"
      reason: "running deployment"
      state: "absent"

Expected Results

TASK [unsilence monitoring] *******************************************
ok: [$HOSTNAME]

Actual Results

TASK [unsilence monitoring] *******************************************
failed: [$HOSTNAME] {"msg": "Failed to silence client:$HOSTNAME. Reason: {'url': 'http://127.0.01:4567/silenced/clear', 'status': 404, 'access-control-allow-credentials': 'true', 'access-control-allow-headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization', 'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS', 'access-control-allow-origin': '*', 'connection': 'close', 'content-length': '0', 'x-request-id': '$REQ_ID', 'msg': 'HTTP Error 404: Not Found', 'body': b''}"}

Code of Conduct

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 year ago

cc @dmsimard @smbambling click here for bot help