DockerでDatadogのアカウントをまたいでdashboardをcopyする


概要

Datadogでアカウントをまたいでdashboardをcopyする

こちらの記事の内容で使われているツールを Docker を使って実行できるようにしました。

How to

Dockerfile

FROM python:3-alpine

WORKDIR /app

RUN python3 -m pip install --user dashjson

CMD [ "python3", "-m", "dashjson", "-h" ]
$ docker build -t dashjson .

credential file

$ cat << EOS > ./.dashjson_from.json
{
    "api_key": "abcdefg12345678",
    "app_key": "abcdefg987654321"
}
EOS

see: https://github.com/ouyi/dashjson#how-to-use

アカウントごとに作成しておく。

Datadogからのexport

$ docker run -ti --rm -v $PWD:/app dashjson python3 -m dashjson -c .dashjson_from.json tojson -b ${dashboard_id} dashboard.json

${dashboard_id} は下記のダッシュボードURLの値を利用した。

Datadogからのimport

$ docker run -ti --rm -v $PWD:/app dashjson python3 -m dashjson -c .dashjson_to.json fromjson -n dashboard.json 

備考

Datadog のダッシュボードの種類によって付与するオプションを変える必要等もあるので、詳しくは dashjson のヘルプを参照してください。

$ docker run -ti --rm dashjson   
usage: dashjson.py [-h] [-c CREDENTIALS] [-t {t,s}] {tojson,fromjson} ...

A tool for exporting (or importing) Datadog dashboards to (or from) json files.

Examples:

- Export to json (the id can be found in the dashboard URL, normally numeric or alphanumeric)
# python dashjson.py tojson -b xyz-123-abc my_timeboard.json
# python dashjson.py -t s tojson -b 584086 my_screenboard.json

- Import from json
# python dashjson.py fromjson my_timeboard.json
# python dashjson.py -t s fromjson my_screenboard.json

- Import from json creating new dashboard
# python dashjson.py fromjson -n my_timeboard.json
# python dashjson.py -t s fromjson -n my_screenboard.json

- Example content of the credentials file (your keys can be found at https://app.datadoghq.com/account/settings#api)
# cat ~/.dashjson.json
{
    "api_key": "abcdefg12345678",
    "app_key": "abcdefg987654321"
}

optional arguments:
  -h, --help            show this help message and exit
  -c CREDENTIALS, --credentials CREDENTIALS
                        the json file containing api_key and app_key as dictionary entries, defaults to ~/.dashjson.json
  -t {t,s}, --board-type {t,s}
                        the type of the dashboard (t for timeboard and s for screenboard) to be imported or exported, default to t

subcommands:
  run `python dashjson.py <subcommand> -h` for usage on a subcommand

  {tojson,fromjson}     valid subcommands
    tojson              export a dashboard to a json file
    fromjson            import a dashboard from a json file