This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Add --delete option to push command #9
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,15 +211,15 @@ def _is_changed(local, remote): | |
return local['obj'] != remote['obj'] | ||
|
||
|
||
def command_init(): | ||
def command_init(args): | ||
remote_monitors = [m['obj'] for m in get_datadog_monitors().values()] | ||
monitors = {'alerts': remote_monitors} | ||
print '# team: TEAMNAME' | ||
print _pretty_yaml(monitors) | ||
|
||
|
||
def command_push(): | ||
def command_push(args): | ||
local_monitors = get_local_monitors() | ||
remote_monitors = get_datadog_monitors() | ||
|
||
|
@@ -233,12 +233,20 @@ def command_push(): | |
changed = [name for name in common_names | ||
if _is_changed(local_monitors[name], remote_monitors[name])] | ||
if changed: | ||
print "Updating %d modified alerts" % len(changed) | ||
print "Updating %d modified monitors." % len(changed) | ||
for name in changed: | ||
datadog.api.Monitor.update( | ||
remote_monitors[name]['id'], | ||
**_prepare_monitor(local_monitors[name])) | ||
|
||
if args.delete: | ||
remote_monitors = get_datadog_monitors() | ||
untracked = set(remote_monitors.keys()) - set(local_monitors.keys()) | ||
if untracked: | ||
print "Deleting %d untracked monitors." % len(untracked) | ||
for monitor in untracked: | ||
datadog.api.Monitor.delete(remote_monitors[monitor]['id']) | ||
|
||
|
||
def _should_mute(expr, tz, now): | ||
return eval(expr, {}, {'now': now.astimezone(tz)}) | ||
|
@@ -261,7 +269,7 @@ def _mute_until(expr, tz, now): | |
return now | ||
|
||
|
||
def command_mute(): | ||
def command_mute(args): | ||
local_monitors = get_local_monitors() | ||
remote_monitors = get_datadog_monitors() | ||
mute_tags = {} | ||
|
@@ -292,7 +300,7 @@ def command_mute(): | |
mute_until['datetime']) | ||
|
||
|
||
def command_diff(): | ||
def command_diff(args): | ||
local_monitors = get_local_monitors() | ||
remote_monitors = get_datadog_monitors() | ||
|
||
|
@@ -358,26 +366,28 @@ def command_diff(): | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
|
||
parser.add_argument('--config', '-c', | ||
parser.add_argument('-c', '--config', | ||
default=os.path.join('.', 'config.yaml'), | ||
help='configuration file to load') | ||
|
||
subparsers = parser.add_subparsers(help='sub-command help') | ||
|
||
|
||
parser_push = subparsers.add_parser( | ||
'init', help='init new alerts file') | ||
'init', help='Init new alerts file') | ||
parser_push.set_defaults(command=command_init) | ||
|
||
|
||
parser_push = subparsers.add_parser( | ||
'push', help='push monitors to datadog') | ||
'push', help='Push monitors to DataDog.') | ||
parser_push.add_argument('-d', '--delete', action='store_true', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete_untracked |
||
help='Delete untracked monitors.') | ||
parser_push.set_defaults(command=command_push) | ||
|
||
|
||
parser_diff = subparsers.add_parser( | ||
'diff', | ||
help='show diff between local monitors and datadog') | ||
help='Show diff between local monitors and DataDog') | ||
parser_diff.set_defaults(command=command_diff) | ||
|
||
|
||
|
@@ -394,7 +404,7 @@ def command_diff(): | |
|
||
def main(): | ||
datadog.initialize(**CONFIG['datadog']) | ||
args.command() | ||
args.command(args) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too