How to use the datadog.api.Monitor.create function in datadog

To help you get started, we’ve selected a few datadog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DataDog / datadogpy / tests / integration / api / test_api.py View on Github external
def test_monitor_muting(self):
        query1 = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"
        query2 = "avg(last_1h):sum:system.net.bytes_rcvd{*} by {host} > 100"
        monitor1 = dog.Monitor.create(type="metric alert", query=query1)
        monitor2 = dog.Monitor.create(type="metric alert", query=query2)

        dt = dog.Monitor.mute_all()
        assert dt["active"] is True
        assert dt["scope"] == ["*"]

        assert dog.Monitor.unmute_all() is None  # No response expected

        monitor1 = dog.Monitor.mute(monitor1["id"])
        assert monitor1["options"]["silenced"] == {"*": None}

        monitor2 = dog.Monitor.mute(monitor2["id"], scope="host:foo")
        assert monitor2["options"]["silenced"] == {"host:foo": None}

        get_with_retry(
            "Monitor",
github DataDog / datadogpy / tests / integration / api / test_api.py View on Github external
def test_monitor_crud(self):
        # Metric alerts
        query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"

        options = {
            "silenced": {"*": int(time.time()) + 60 * 60},
            "notify_no_data": False,
        }
        monitor = dog.Monitor.create(type="metric alert", query=query, options=options)
        assert monitor["query"] == query
        assert monitor["options"]["notify_no_data"] == options["notify_no_data"]
        assert monitor["options"]["silenced"] == options["silenced"]

        monitor = get_with_retry("Monitor", monitor["id"])
        assert monitor["query"] == query
        assert monitor["options"]["notify_no_data"] == options["notify_no_data"]
        assert monitor["options"]["silenced"] == options["silenced"]

        query2 = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 200"
        monitor = dog.Monitor.update(monitor["id"], query=query2, options=options)
        assert monitor["query"] == query2
        assert monitor["options"]["notify_no_data"] == options["notify_no_data"]
        assert monitor["options"]["silenced"] == options["silenced"]

        name = "test_monitors"
github DataDog / datadogpy / datadog / dogshell / monitor.py View on Github external
def _post(cls, args):
        api._timeout = args.timeout
        format = args.format
        options = None
        if args.options is not None:
            options = json.loads(args.options)

        if args.tags:
            tags = sorted(set([t.strip() for t in args.tags.split(',') if t.strip()]))
        else:
            tags = None

        res = api.Monitor.create(type=args.type, query=args.query, name=args.name,
                                 message=args.message, tags=tags, options=options)
        report_warnings(res)
        report_errors(res)
        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
github DataDog / Miscellany / Dogmover / dogmover.py View on Github external
def push_monitors():
    count = 0
    monitors = _files_to_json("monitors")
    if not monitors:
        exit("No monitors are locally available. Consider pulling monitors first.")

    for monitor in monitors:
        with open(monitor) as f:
            data = json.load(f)
            count = count + 1
            print("Pushing: {}".format(data["name"].encode('utf8')))
            if not arguments["--dry-run"]:
                api.Monitor.create(type=data['type'],
                                    query=data['query'],
                                    name=data['name'],
                                    message=data['message'],
                                    tags=data['tags'],
                                    options=data['options'])
    print("Pushed '{}' monitors.".format(count))
    if not arguments["--dry-run"]:
        print("Note. All monitors have been automatically muted to supress false/positive alerts. Navigate to Monitors -> Manage downtime to unmute.")
        api.Monitor.mute_all()
github DataDog / Miscellany / migrate_monitors.py View on Github external
new_monitor[k] = v
        new_monitors.append(new_monitor)

#pprint.pprint(new_monitors)

# TO org

options = {
    'api_key': 'new_api', # to org api
    'app_key': 'new_app'  # to org app
}

initialize(**options)

for monitor_dict in new_monitors:
    res = api.Monitor.create(
        type=monitor_dict['type'],
        query=monitor_dict['query'],
        name=monitor_dict['name'],
        message=monitor_dict['message'],
        tags=monitor_dict['tags'],
        options=monitor_dict['options']
        )
    print(res)
github StackStorm / st2contrib / packs / datadog / actions / lib / monitors.py View on Github external
def _run(self, **kwargs):
        return api.Monitor.create(**kwargs)
github trueaccord / DogPush / dogpush / dogpush.py View on Github external
def command_push(args):
    local_monitors = get_local_monitors()
    remote_monitors = get_datadog_monitors()

    only_local = set(local_monitors.keys()) - set(remote_monitors.keys())
    if only_local:
        print "Pushing %d new monitors." % len(only_local)
        for name in only_local:
            datadog.api.Monitor.create(**_prepare_monitor(local_monitors[name]))

    common_names = set(local_monitors.keys()) & set(remote_monitors.keys())
    changed = [name for name in common_names
               if _is_changed(local_monitors[name], remote_monitors[name])]
    if 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_untracked:
        remote_monitors = get_datadog_monitors()
        untracked = set(remote_monitors.keys()) - set(local_monitors.keys())
        if untracked:
            print "Deleting %d untracked monitors." % len(untracked)
github DataDog / documentation / content / api / monitors / code_snippets / api-monitor-create.py View on Github external
from datadog import initialize, api

options = {
    'api_key': '',
    'app_key': ''
}

initialize(**options)

# Create a new monitor
options = {
    "notify_no_data": True,
    "no_data_timeframe": 20
}
tags = ["app:webserver", "frontend"]
api.Monitor.create(
    type="metric alert",
    query="avg(last_5m):sum:system.net.bytes_rcvd{host:host0} > 100",
    name="Bytes received on host0",
    message="We may need to add web hosts if this is consistently high.",
    tags=tags,
    options=options
)