Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fvalidate to dogshell #827

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions datadog/dogshell/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def setup_parser(cls, subparsers):
validate_parser.add_argument("--options", help="json options for the monitor", default=None)
validate_parser.set_defaults(func=cls._validate)

file_validate_parser = verb_parsers.add_parser("fvalidate", help="Validate monitor from file")
file_validate_parser.add_argument("file", help="json file holding all details", type=argparse.FileType("r"))
file_validate_parser.set_defaults(func=cls._file_validate)

@classmethod
def _post(cls, args):
api._timeout = args.timeout
Expand Down Expand Up @@ -472,3 +476,33 @@ def _validate(cls, args):
print(pretty_json(res))
else:
print(json.dumps(res))

@classmethod
def _file_validate(cls, args):
api._timeout = args.timeout
format = args.format
monitor = json.load(args.file)
body = {
"type": monitor["type"],
"query": monitor["query"],
"name": monitor["name"],
"message": monitor["message"],
"options": monitor["options"]
}
restricted_roles = monitor.get("restricted_roles", None)
if restricted_roles:
body["restricted_roles"] = restricted_roles
tags = monitor.get("tags", None)
if tags:
body["tags"] = tags
priority = monitor.get("priority", None)
if priority:
body["priority"] = priority

res = api.Monitor.validate(**body)
# report_warnings(res)
# report_errors(res)
if format == "pretty":
print(pretty_json(res))
else:
print(json.dumps(res))