community.general icon indicating copy to clipboard operation
community.general copied to clipboard

datadog_monitor module unable to mute monitor based on a scope and time

Open RommelLayco opened this issue 4 years ago • 5 comments

SUMMARY

The datadog_monitor allows you to mute a monitor based on a scope and timestamp using the silenced parameter. This parameter does not work, as it is ignored by the datadog sdk and just mutes every host managed by the monitor forever.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

datadog_monitor

ANSIBLE VERSION
2.9.15
CONFIGURATION

OS / ENVIRONMENT

mac os

STEPS TO REPRODUCE
- hosts: all
  tasks:
  
      - datadog_monitor:
          api_key: axxxxxxxxxxxxxxx5
          app_key: cxxxxxxxxxxxa
          name: "My Monitor"
          state: mute
          silenced:
            scope: "host:my-host"
            end: 1608685755

EXPECTED RESULTS

only the host my-host to be muted till 1608685755

ACTUAL RESULTS

all hosts managed by the monitor are muted.


RommelLayco avatar Dec 23 '20 01:12 RommelLayco

The issue is that the datadog sdk ignores any parameters that are not defined for the method. In this case the we are making the following api call https://github.com/ansible-collections/community.general/blob/main/plugins/modules/monitoring/datadog/datadog_monitor.py#L384

api.Monitor.mute(id=monitor['id'], silenced=module.params['silenced'])

Silenced is not defined parameter for the mute method. This is just ignored. Instead it takes the following parameters to mute based on a scope and timestamp

api.Monitor.mute(id=monitor['id'],  scope="host:my-host", end=1608685755)

See https://docs.datadoghq.com/api/v1/monitors/#mute-a-monitor

RommelLayco avatar Dec 23 '20 02:12 RommelLayco

cc @skornehl click here for bot help

ansibullbot avatar Dec 23 '20 02:12 ansibullbot

CC @zippolyte

felixfontein avatar Dec 23 '20 08:12 felixfontein

Hey

Looks to me like this was present and broken since the beginning of this module, and not really much used. Honestly these two mute and unmute states don't really make much sense to me. I'd instead see the usage being having a monitor in state present in your playbook, and modifying the silenced attribute there.

Moreover, for managing downtimes, I'd recommend using the datadog_downtime module instead, as the silenced attribute and the mute and unmute endpoints are being deprecated.

IMO, the real fix here would be to remove the mute and unmute states, as they are broken anyway, and the functionality they are using is being deprecated on the Datadog side. Or at least make them stop accepting scope and timestamp and document them as muting the monitor for all scopes forever until unmuted, to keep the current behavior.

Feel free to push a PR for this, not sure how the original writer of this community module wants to proceed.

Hope this helps !

zippolyte avatar Jan 05 '21 14:01 zippolyte

It probably makes sense to deprecate the states then, so they can be removed in a future version and current users get a deprecation message (which informs them that these states don't work at all, and will be removed in the future, and they should use the other module instead).

felixfontein avatar Jan 05 '21 20:01 felixfontein