Hi!
Im running the new 1.2.0~beta7, and testing the new dashboard feature.
Would like a feature to export dashboards, so I can use them on another system.
Either through the GUI or CLI.
Export could be in form of a json or similar that I can import somewhere else.
Hi @hasselrot, thanks for writing in! What destination would you have in mind? Would the destination be another chronograf server?
HI! @goller
In my use case, we use ansible to provision many similar environments. And some dashboards I would want to re use across all environments.
So yes, it would be another chronograf server, ideally with some sort of import that can be run from ansible.
Or is this somehow possible to do with the API? I cant get it working from the documentation at https://github.com/influxdata/chronograf/blob/master/docs/dashboards.md
If I could just dump my dashboard in a json format, and import it via the API on another chronograf thats good enough for me :)
Hey @hasselrot, yup you could totally do this. Here is a little shell script to do it:
SRC=http://your-src-server:8888/chronograf/v1/dashboards
DST=http://your-dst-server:8888/chronograf/v1/dashboards
curl -Ss $SRC|jq -r '.dashboards[]|@json' |while IFS= read -r dashboard; do echo $dashboard > f; curl -X POST -H "Accept: application/json" -d @f $DST; done
As an aside, the server's REST API documentation is in swagger here: https://github.com/influxdata/chronograf/blob/master/server/swagger.json
Also, we place host the swagger.json file at your server's /docs endpoint (e.g. http://localhost:8888/docs) We render it using @RomanGotsiy excellent redoc package.
Let us know how it goes!
@goller Awesome thanks! I will let you know!
@goller Got it working, knowing where to find the documentation did all the difference :)
It was a bit tricky though, as the POST and PUT are exclusive. I mean if you do a PUT and it doesnt exist, it does not create it. And if you do a POST you get multiple dashboards with the same name.
So either way I needed to do a script that parses out id of existing dashboards and match with the name of my new dashboard.
In my case, it would have been best if there could be only one dashboard with a certain name. And if I try to POST/PUT another with that name it updates it.
I got it working but it could be something to think about :)
Hey @hasselrot I'm glad you got it working! In the chronograf API we follow REST conventions pretty strongly. APUT is always a replacement of an existing resource at a fully qualified URI. Meaning, if the dashboard's URI to replace was /chronograf/v1/dashboards/2 a PUT to that resource will overwrite 2 completely. The PUT 's response body will return the newly updated dashboard.
A POST creates an entirely new resource. To create a new dashboard you would POST to /chronograf/v1/dashboards. The POST 's response body will contain the information about the newly created dashboard including it's URI location at links.self.
If you GET at the /chronograf/v1/dashboards endpoint you will receive all dashboards.
So, I'm not sure if that helps make my mental model of the API more clear, but, I'd love to see your script so I can understand more deeply how it could be better!
@goller Sorry to keep writing in a closed issue. But I created a topic here:
https://community.influxdata.com/t/dashboard-id-in-url-problems/537
Maybe there is another way to solve this, but I just keep running in to problems.
Most helpful comment
Hey @hasselrot, yup you could totally do this. Here is a little shell script to do it:
As an aside, the server's REST API documentation is in swagger here: https://github.com/influxdata/chronograf/blob/master/server/swagger.json
Also, we place host the swagger.json file at your server's
/docsendpoint (e.g. http://localhost:8888/docs) We render it using @RomanGotsiy excellent redoc package.Let us know how it goes!