grafana-client icon indicating copy to clipboard operation
grafana-client copied to clipboard

Add converter for dashboard JSON in "export format" representation

Open amotl opened this issue 3 years ago • 7 comments

Hi there,

@jeremybz / @jeremybanzhaf asked at ^1:

My goal is to use the API to get the JSON representation of a dashboard, including __inputs and named datasources.

@jangaraj answered:

HTTP API for dashboard export for external use doesn’t exist. This export feature is implemented in the UI (frontend). I would say the only option is to use standard dashboard API and make that output transformed into “dashboard format for external use”. Unfortunately, that format is not documented, so you have to use reverse engineering.

Torkel Ödegaard said at ^2:

This is not possible, the data is captured by the frontend so you would have to replicate what all the panel & data sources do (issue metric queries etc).

In order to implement this transformation, I would be happy to provide a place within this package, if possible. Would that make any sense / be helpful in any way?

The implementation should adhere to the specifications defined by the corresponding TypeScript code.

With kind regards, Andreas.

/cc @jangaraj

amotl avatar Feb 07 '22 22:02 amotl

I agree. That DashboardExporter.ts needs a corresponding Python implementation.

jangaraj avatar Feb 08 '22 07:02 jangaraj

Hi again,

I made a start with model/dashboard.py ^1 within the collab/dashboard-export branch ^2. The main body of DashboardExporter.makeExportable will still have to be implemented, but the framework is there [^3].

With kind regards, Andreas.

[^3]: Supported by a preliminary but working command line invocation like python -m grafana_client.model.dashboard play.grafana.org 000000012 | jq.

amotl avatar Feb 16 '22 14:02 amotl

The main body [...] will still have to be implemented [...]

It might have happened that @peekjef72 implemented the corresponding nitty-gritty details with their grafana-snapshots-tool already?

amotl avatar Jun 21 '22 21:06 amotl

Hi, grafana-snapshot-tool as mentionned in its documentation, can import, export, and generate what is called in GRAFANA UI "snapshots": they are dashboards with corresponding datas incorporated. My opinion is that snapshots, can't be part of the API because they are composed of calls to others parts of the api:

  • exporting a dashboard
  • collection datasources names
  • parsing the datasources used by the dashboard
  • query datasources from grafana
  • incorporating results into the dashboard
  • then generating a file or importing it to a grafana server.

A snapshot is a picture of a dashboard too, as a consequence it has parameters:

  • a time range (timefrom, time to)
  • value for each variables used by the dashboard.

Grafana-snapshot-tool is my implementation of these functionnalities. It uses the python api (panadata/grafana-client), to perform all above actions. My contribution to this repository, concerns datasources, particullary the ability to query them, as required and done by Grafana UI (reverse engineering on API call with browser dev tool). Hope my opinion can help. Anyway feel free to use the code or to incorpore it into contribs, if you think it should help :)

peekjef72 avatar Jun 22 '22 05:06 peekjef72

Dear Jean-Francois,

apologies for the late reply. I am very happy that we finally got closer in touch at https://github.com/peekjef72/grafana-snapshots-tool/issues/2#issuecomment-1251008404 ff. If I can find some time to work on another iteration of grafana-client, I will also be happy to share further thoughts about our topics of shared interest.

In the meanwhile, I will be looking forward to all contributions and improvements coming from your pen which may be needed as we go. Thank you very much already for making a start with https://github.com/panodata/grafana-client/compare/main...peekjef72:grafana-client:main.

With kind regards, Andreas.

amotl avatar Sep 19 '22 16:09 amotl