DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
609 stars 302 forks source link

dog monitor fpost ignores tags #734

Closed eric-the-bike-man closed 1 year ago

eric-the-bike-man commented 1 year ago

Describe the bug When running dog monitor fpost monitor.json, any tags included in the json file do not get applied to the monitor.

Label the issue properly.

To Reproduce create a JSON file named monitor.json with contents such as

{
    "name": "",
    "type": "query alert",
    "query": "avg(last_5m):avg:system.load.1{*} > 99",
    "message": "test alert",
    "tags": [
        "foobar"
    ],
    "options": {
        "thresholds": {
            "critical": 99
        },
        "notify_audit": false,
        "require_full_window": false,
        "notify_no_data": false,
        "renotify_interval": 0
    }
}

run dog monitor fpost monitor.json

{"restricted_roles": null, "tags": [], "deleted": null, "query": "avg(last_5m):avg:system.load.1{*} > 99", "message": "test alert", "id": 98921654, "multi": false, "name": "**system.load.1** over ***** was **> 99.0** on average during the **last 5m**.", "created": "2022-10-12T17:40:10.619078+00:00", "created_at": 1665596410000, "creator": {"id": xxx, "handle": "xxxxxx@example.com", "name": "Me", "email": "xxxxxxx@example.com"}, "org_id": 99999, "modified": "2022-10-12T17:40:10.619078+00:00", "priority": null, "overall_state_modified": null, "overall_state": "No Data", "type": "query alert", "options": {"notify_audit": false, "silenced": {}, "include_tags": true, "thresholds": {"critical": 99.0}, "require_full_window": false, "new_host_delay": 300, "notify_no_data": false, "renotify_interval": 0}}

Expected behavior A monitor should be created with the specified "foobar" tag. Instead no tags are created on the monitor.

Screenshots

Environment and Versions (please complete the following information): dog version 0.44.0

Additional context (https://github.com/DataDog/datadogpy/blob/master/datadog/dogshell/monitor.py#L175)

Adding tags=monitor["tags"], to the Monitor.create call produces the desired results.

    @classmethod
    def _file_post(cls, args):
        api._timeout = args.timeout
        format = args.format
        monitor = json.load(args.file)
        res = api.Monitor.create(
            type=monitor["type"],
            query=monitor["query"],
            name=monitor["name"],
            message=monitor["message"],
            options=monitor["options"],
            tags=monitor["tags"],
        )
        report_warnings(res)
        report_errors(res)
        if format == "pretty":
            print(pretty_json(res))
        else:
            print(json.dumps(res))
github-actions[bot] commented 1 year ago

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.