Datadog API: Difference between revisions
Jump to navigation
Jump to search
(28 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | =External= | ||
=Internal= | =Internal= | ||
* [[Datadog Concepts#API|Datadog Concepts]] | |||
=Overview= | |||
Datadog resources can be provisioned via an API. | |||
=HTTP= | =HTTP= | ||
* https://docs.datadoghq.com/api/latest/ | |||
==Organization== | |||
Organization information | |||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
curl -s -X GET "https://api.datadoghq.com/api/v1/org" \ | curl -s -X GET "https://api.datadoghq.com/api/v1/org" \ | ||
Line 14: | Line 20: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Playground= | =Python= | ||
{{External|https://github.com/ovidiuf/playground/tree/master/datadog/python-api}} | * https://github.com/DataDog/datadogpy | ||
* https://docs.datadoghq.com/api/latest/?code-lang=python | |||
* https://datadogpy.readthedocs.io/en/latest/ | |||
* https://docs.datadoghq.com/api/latest/using-the-api/ | |||
==Environment== | |||
The following environment variables must be present: <code>DD_API_KEY</code>, <code>DD_APP_KEY</code>. Apparently <code>DATADOG_API_KEY</code> and <code>DATADOG_APP_KEY</code> are ignored. | |||
<syntaxhighlight lang='bash'> | |||
DD_API_KEY='...' | |||
DD_APP_KEY='...' | |||
</syntaxhighlight> | |||
==<tt>requirements.txt</tt>== | |||
<font size=-1> | |||
datadog_api_client [== x.y.z] <font color=Teal># How do I find the latest version?</font> | |||
</font> | |||
==Dashboard== | |||
{{External|https://docs.datadoghq.com/api/latest/dashboards/}} | |||
===Get All Dashboards=== | |||
{{External|https://docs.datadoghq.com/api/latest/dashboards/#get-all-dashboards}} | |||
{{External|[https://github.com/ovidiuf/playground/blob/master/datadog/pyhton-api/dashboards/src/main/python/main.py Playground Example]}} | |||
<syntaxhighlight lang='py'> | |||
from datadog_api_client.v1 import ApiClient, Configuration | |||
from datadog_api_client.v1.api.dashboards_api import DashboardsApi | |||
configuration = Configuration() | |||
# | |||
# Get all dashboards | |||
# | |||
with ApiClient(configuration) as api_client: | |||
api_instance = DashboardsApi(api_client) | |||
dashboard_summaries = api_instance.list_dashboards(filter_shared=False) | |||
m = dashboard_summaries.to_dict() | |||
l = m.get('dashboards') | |||
for d in l: | |||
print(d['title'] + ' (ID ' + d['id'] + ')') | |||
</syntaxhighlight> | |||
===Get A Dashboards=== | |||
{{External|https://docs.datadoghq.com/api/latest/dashboards/#get-a-dashboard}} | |||
<syntaxhighlight lang='py'> | |||
from datadog_api_client.v1 import ApiClient, Configuration | |||
from datadog_api_client.v1.api.dashboards_api import DashboardsApi | |||
configuration = Configuration() | |||
d_id = ... | |||
configuration = Configuration() | |||
with ApiClient(configuration) as api_client: | |||
api_instance = DashboardsApi(api_client) | |||
dashboard = api_instance.get_dashboard(dashboard_id=d_id) | |||
m = dashboard.to_dict() | |||
print(m) | |||
</syntaxhighlight> | |||
==Generic== | |||
<font color=darkkhaki>TO PROCESS</font>: | |||
{{External|https://github.com/ovidiuf/playground/tree/master/datadog/python-api/generic}} |
Latest revision as of 01:00, 9 March 2022
External
Internal
Overview
Datadog resources can be provisioned via an API.
HTTP
Organization
Organization information
curl -s -X GET "https://api.datadoghq.com/api/v1/org" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}"
Python
- https://github.com/DataDog/datadogpy
- https://docs.datadoghq.com/api/latest/?code-lang=python
- https://datadogpy.readthedocs.io/en/latest/
- https://docs.datadoghq.com/api/latest/using-the-api/
Environment
The following environment variables must be present: DD_API_KEY
, DD_APP_KEY
. Apparently DATADOG_API_KEY
and DATADOG_APP_KEY
are ignored.
DD_API_KEY='...'
DD_APP_KEY='...'
requirements.txt
datadog_api_client [== x.y.z] # How do I find the latest version?
Dashboard
Get All Dashboards
from datadog_api_client.v1 import ApiClient, Configuration
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
configuration = Configuration()
#
# Get all dashboards
#
with ApiClient(configuration) as api_client:
api_instance = DashboardsApi(api_client)
dashboard_summaries = api_instance.list_dashboards(filter_shared=False)
m = dashboard_summaries.to_dict()
l = m.get('dashboards')
for d in l:
print(d['title'] + ' (ID ' + d['id'] + ')')
Get A Dashboards
from datadog_api_client.v1 import ApiClient, Configuration
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
configuration = Configuration()
d_id = ...
configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = DashboardsApi(api_client)
dashboard = api_instance.get_dashboard(dashboard_id=d_id)
m = dashboard.to_dict()
print(m)
Generic
TO PROCESS: