Skip to content

Commit

Permalink
[bugfix] monitors.get_all_monitors action to filter results based on …
Browse files Browse the repository at this point in the history
…action parameters (#17)

* Filter based on monitors.get_all_monitors input params
  • Loading branch information
abhishek-j16 authored Sep 27, 2024
1 parent f691b30 commit 8335a1e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.2

* Fix `monitors.get_all_monitors` action to filter results based on `group_states` and `monitor_tags` parameters

## 1.0.1

* Update metrics.query_ts_points action with the correct class: `DatadogQueryTSPoints`
Expand Down
7 changes: 4 additions & 3 deletions actions/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def run(self, **kwargs):
args = {k: v for k, v in kwargs.items()
if str(v).strip() and v is not None}
out = self._run(**args)
errors = out.get("errors")
if errors:
return (False, errors)
if isinstance(out, dict):
errors = out.get("errors", None)
if errors:
return (False, errors)
return (True, out)
8 changes: 6 additions & 2 deletions actions/lib/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ def _run(self, **kwargs):


class DatadogGetAllMonitors(DatadogBaseAction):
def _run(self):
return api.Monitor.get_all()
def _run(self, **kwargs):
monitor_tags_raw = kwargs.pop("tags","")
group_states_raw = kwargs.pop("group_states","")
monitor_tags = [tag.strip() for tag in monitor_tags_raw.split(",")] if monitor_tags_raw else None
group_states = [state.strip() for state in group_states_raw] if group_states_raw else None
return api.Monitor.get_all(monitor_tags=monitor_tags, group_states=group_states, **kwargs)


class DatadogGetMonitor(DatadogBaseAction):
Expand Down
2 changes: 1 addition & 1 deletion actions/monitors.get_all_monitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ parameters:
tags:
type: string
required: false
description: "A comma separated list indicating what tags, if any, should be used to filter the list of monitors by scope"
description: "A comma separated list indicating what tags, if any, should be used to filter the list of monitors by scope. Example: 'env:prod,service:abc'"
cls:
default: DatadogGetAllMonitors
immutable: true
Expand Down
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- monitoring
- alerting
- saas
version: 1.0.1
version: 1.0.2
author: Lisa Bekdache
email: [email protected]
python_versions:
Expand Down

0 comments on commit 8335a1e

Please sign in to comment.