Saving and Restoring Dashboards with scripts

Sysdig Monitor offers, as part our python client library examples, the ability to save all your current dashboards to a locally controlled file, and later optionally create new dashboards identical to the ones previously saved.

In brief:

To back up existing dashboards:
 python examples/download_dashboards <API_TOKEN> saved_dashboard_configurations.zip

To create all new dashboards matching the saved configuration:
 python examples/restore_dashboards <API_TOKEN> saved_dashboard_configurations.zip


 

The save script will store all current dashboard for your account into a zip archive, while the restore script will add all dashboards from a zip archive in addition to your pre-existing set of dashboards.  There is no requirement that the restore target the same account as the save.

Thus if you are using this in a strictly backup/restore capacity, you will need to manually delete dashboards from your account before or after the restore action.

1. Pre-requisites:

  • Python 2.x (2.7.x)
  • recommended: virtualenv https://virtualenv.pypa.io/en/stable/installation/

2. Getting the scripts & library

The library and example scripts live in the github repository https://github.com/draios/python-sdc-client

You can get the current version using the git source tool, or simply downloading a zip from the page.

Downloading the zip should be obvious.  (Click clone or download -> Download Zip).  Unpack it in a convenient directory.

Git:

cd to a directory where it will be convenient to check out the code and use the command:

 git clone https://github.com/draios/python-sdc-client.git

3. Set up the environment

if you're familiar with python, you can of course arrange to have the sdcclient directory importable as a module via the means you choose.

If not I recommend setting up via pip & virtualenv

$ mkdir ~/workingdir/venv # declare where you want all python tools installed
$ virtualenv ~/workingdir/venv  # prepare the workspace -- this may download several things
$ source ~/workingdir/venv/bin/activate  # cause all python tools to use this workspace from now on
(venv) $  # at this point the prompt reminds us we're in the virtual environment
(venv) $  cd python-sdc-client
(venv) $  pip install .    # install the sdcclient library into the venv

4. Use the scripts

At this point, the sdcclient module should be available to python by the above steps, or by some other means.

We can use them to backup:

(venv) $ python examples/download_dashboards.py <API_TOKEN> saved_dashboards.zip
Dashboard name: JVM, # Charts: 5
Finished writing dashboard data in zip format to dashboards.zip

This saves all dashboards for the account linked to the api_token to the zip dir.  If you list the contents, you should see one json file per dashboard.

We can use them to re-create what was backed up:

(venv) $ python examples/restore_dashboards.py <API_TOKEN> dashboards.zip
Dashboards pushed.
(venv) $

Note that this will not overwrite existing dashboards, but just create additional ones.

 

Have more questions? Submit a request