How to use the datadog.api 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 kiwicom / crane / tests / integration / test_hooks_datadog.py View on Github external
def test_create_event(monkeypatch, mocker, repo, commits, event, text):
    old_version = repo.head.commit.hexsha
    for commit in commits:
        repo.index.commit(commit)

    tags = ["releaser:picky@kiwi.com", "project:foo/bar", "environment:a-b/c-d"]

    fake_create = mocker.patch.object(datadog.api.Event, "create")
    fake_deployment = Deployment(repo=repo, new_version="HEAD", old_version=old_version)

    monkeypatch.setattr(uut, "deployment", fake_deployment)

    dd_hook = uut.Hook()
    if event == "success":
        dd_hook.after_upgrade_success()
    elif event == "error":
        dd_hook.after_upgrade_failure()

    fake_create.assert_called_with(
        title="foo/bar deployment", text=text, tags=tags, alert_type=event
    )
github DataDog / datadogpy / tests / unit / api / helper.py View on Github external
def tearDown(self):
        super(DatadogAPINoInitialization, self).tearDown()
        # Restore default values
        api._api_key = None
        api._application_key = None
        api._api_host = None
        api._host_name = None
        api._proxies = None
github dimagi / commcare-hq / corehq / util / datadog / utils.py View on Github external
def datadog_initialized():
    return api._api_key and api._application_key
github DataDog / documentation / content / api / tags / code_snippets / api-tags-remove.py View on Github external
from datadog import initialize, api

options = {
    'api_key': '9775a026f1ca7d1c6c5af9d94d9595a4',
    'app_key': '87ce4a24b5553d2e482ea8a8500e71b8ad4554ff'
}

initialize(**options)


api.Tag.delete('hostname')
github DataDog / Miscellany / dash_to_json.py View on Github external
def create_dash(dash_dict, board_type):
    if board_type == "timeboard":
        title = dash_dict.get('title', 'New Timeboard')
        read_only = dash_dict.get('read_only', 'False')
        description = dash_dict.get('description', '')
        graphs = dash_dict.get('graphs', [])
        template_variables = dash_dict.get('template_variables', [])
        res = api.Timeboard.create(title=title, description=description, graphs=graphs,
                                   template_variables=template_variables, read_only=read_only)
        if res.get('errors', None):
            print res
        else:
            print "Successfully created timeboard"
    elif board_type == "screenboard":
        title = dash_dict.get('board_title', 'New Screenboard')
        description = dash_dict.get('description', '')
        widgets = dash_dict.get('widgets', [])
        width = dash_dict.get('width', 1024)
        template_variables = dash_dict.get('template_variables', [])
        res = api.Screenboard.create(board_title=title, description=description,
                                     widgets=widgets, template_variables=template_variables, width=width)
        if res.get('errors', None):
            print res
        else:
github DataDog / Miscellany / easy_dash.py View on Github external
def create_new_dashboard(api_key, app_key, dashboard_template):
    
    options = { 'api_key': api_key, 'app_key': app_key }
    initialize(**options)
    
    title = dashboard_template['title']
    widgets = dashboard_template['widgets']
    layout_type = dashboard_template['layout_type']
    description = dashboard_template['description']
    is_read_only = dashboard_template['is_read_only']
    notify_list = dashboard_template['notify_list']
    template_variables = dashboard_template['template_variables']

    api.Dashboard.create(
        title=title,
        widgets=widgets,
        layout_type=layout_type,
        description=description,
        is_read_only=is_read_only,
        notify_list=notify_list,
        template_variables=template_variables
        )
github DataDog / documentation / ja / code_snippets / api-events-delete.py View on Github external
from datadog import initialize, api

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

initialize(**options)

api.Event.delete(2603387619536318140)
github DataDog / documentation / content / en / api / dashboard_lists / code_snippets / api-dashboard-list-add-items.py View on Github external
},
    {
        "type": "integration_screenboard",
        "id": 67
    },
    {
        "type": "integration_timeboard",
        "id": 5
    },
    {
        "type": "host_timeboard",
        "id": 123456789
    }
]

api.DashboardList.add_items(list_id, dashboards=dashboards)
github dimagi / commcare-cloud / src / commcare_cloud / manage_commcare_cloud / datadog_monitors.py View on Github external
def _wrap(self, raw_mon):
        # This drove me crazy to figure out, but the get_all endpoint omits
        # options.synthetics_check_id for no reason I can think of.
        # If it's a synthetics alert, pull it again directly by id.
        if raw_mon['type'] == 'synthetics alert':
            raw_mon = api.Monitor.get(raw_mon['id'])
        if raw_mon.get('errors'):
            raise MonitorError('\n'.join(raw_mon['errors']))
        else:
            return clean_raw_monitor(raw_mon)
github newsdev / nyt-fec / cycle_2018 / utils / logging.py View on Github external
def log(title, text="", tags=[]):
    try:
        api.Event.create(title=title,
                    text=text,
                    tags=tags)
    except api.exceptions.ApiNotInitialized:
        pass
    #for now at least we're gonna write everything to stdout
    message = "{}: {}.".format(title, text)
    if tags:
        message += "\nTAGS: {}".format(', '.join(tags))
    message += "\n\n"
    sys.stdout.write(message)