Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
)
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
def datadog_initialized():
return api._api_key and api._application_key
from datadog import initialize, api
options = {
'api_key': '9775a026f1ca7d1c6c5af9d94d9595a4',
'app_key': '87ce4a24b5553d2e482ea8a8500e71b8ad4554ff'
}
initialize(**options)
api.Tag.delete('hostname')
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:
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
)
from datadog import initialize, api
options = {
'api_key': '',
'app_key': ''
}
initialize(**options)
api.Event.delete(2603387619536318140)
},
{
"type": "integration_screenboard",
"id": 67
},
{
"type": "integration_timeboard",
"id": 5
},
{
"type": "host_timeboard",
"id": 123456789
}
]
api.DashboardList.add_items(list_id, dashboards=dashboards)
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)
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)