Skip to content

Instantly share code, notes, and snippets.

@horttanainen
Created February 27, 2019 15:18
Show Gist options
  • Save horttanainen/2abd23a0c9ced13c6c660e5329928dcd to your computer and use it in GitHub Desktop.
Save horttanainen/2abd23a0c9ced13c6c660e5329928dcd to your computer and use it in GitHub Desktop.
Create a datadog screenboard from a timeboard
#!/usr/bin/env bash
#params
#dd_api_key=
#dd_app_key=
#dash_id=
curl -sX GET "https://app.datadoghq.com/api/v1/dash/${dash_id}?api_key=${dd_api_key}&application_key=${dd_app_key}" \
| jq '{
board_title: .dash.title,
description: .dash.description,
template_variables: .dash.template_variables,
widgets: [.dash.graphs[] | { type: .definition.viz, tile_def: .definition, title: true, title_text: .title, autoscale: true, x: 0, y: 0 }]
}' \
| curl -H "Content-type: application/json" -d @- \
"https://app.datadoghq.com/api/v1/screen?api_key=${dd_api_key}&application_key=${dd_app_key}"
@horttanainen
Copy link
Author

Here is how to do it to the opposite direction: https://gist.github.com/pmbauer/4de4871a38246ee9ee77

@horttanainen
Copy link
Author

The widgets are piled so you must rearrange them after running this script.

@shaunflagg
Copy link

Timeboard (dash) and screenboard (screen) are outdated.

https://docs.datadoghq.com/graphing/guide/screenboard-api-doc/?tab=bash
https://docs.datadoghq.com/graphing/guide/timeboard-api-doc/?tab=bash

Dashboard endpoint with layout_type free or ordered can be used instead.
https://docs.datadoghq.com/api/?lang=bash#dashboards

@jtafurth
Copy link

jtafurth commented Feb 2, 2021

Here is an updated script for the current API:

#!/usr/bin/env bash
#params
dd_api_key=<dd_api_key>
dd_app_key=<dd_app_key>
dash_id=<dash_id>
curl -sX GET "https://api.datadoghq.eu/api/v1/dashboard/${dash_id}?api_key=${dd_api_key}&application_key=${dd_app_key}" \
 | jq '{
         layout_type: "free",
         title: .title,
         description: .description,
         template_variables: .template_variables,
         widgets: [.widgets[] | { id: .id, definition: .definition, layout: { height: 10, width: 10, x: 0, y: 0 }}]
       }' \
 | curl -X POST -H "Content-type: application/json" -d @- \
    "https://api.datadoghq.eu/api/v1/dashboard?api_key=${dd_api_key}&application_key=${dd_app_key}"

It doesn't support groups as free form dashboard don't have groups, so either you'll have to remove them from the original dashboard or extend this to validate if .widget[i].type != groups.

@horttanainen
Copy link
Author

Thank you @jtafurth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment