Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Add filter by mention #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ mute_tags:

rule_files:
- rds.yaml

dogpush:
yaml_width: 80
ignore_prefix: 'string'
filter_by_at_mention:
- '@victorops-eng'
- '@hipchat-Engineering'
20 changes: 20 additions & 0 deletions dogpush/dogpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def _load_config(config_file):
# Ensure the keys of the above two groups are disjoint.
assert(set(config['default_rule_options'].keys()) &
set(DATADOG_DEFAULT_OPTIONS.keys()) == set())
config['dogpush']['filter_by_at_mention'] = config['dogpush'].get(
'filter_by_at_mention', None)

return config

Expand Down Expand Up @@ -146,6 +148,15 @@ def get_datadog_monitors():
if not m['name'].startswith(CONFIG['dogpush']['ignore_prefix'])
]

if CONFIG['dogpush']['filter_by_at_mention']:
monitors = [
m for m in monitors
if any(
team in m['message']
for team in CONFIG['dogpush']['filter_by_at_mention']
)
]

if not _check_monitor_names_unique(monitors):
raise DogPushException(
'Duplicate names found in remote datadog monitors.')
Expand Down Expand Up @@ -199,6 +210,15 @@ def get_local_monitors():
monitors.append(monitor)
if not _check_monitor_names_unique(monitors):
raise DogPushException('Duplicate names found in local monitors.')

if CONFIG['dogpush']['filter_by_at_mention']:
monitors = [
m for m in monitors
if any(
team in m['obj']['message']
for team in CONFIG['dogpush']['filter_by_at_mention']
)
]
result = dict((m['name'], m) for m in monitors)
return result

Expand Down