Copying base dashboard to all the organizations

api

#1

Hi,
can someone please explain,what i am trying to create a new organization and then create a user for that organization.With viewer only access and then trying to create a new datasource and then copy the base dashboard which i have created using my admin login.Then repeats when a new user signs up.Is there way to do this??


#2

Each of the actions you describe can be achieved using a respective API call, so yes, it can be done that way. Though since you’ve applied the “api” tag to your question I guess you’re already aware of that. The API docs (http://docs.grafana.org/http_api/) are pretty comprehensive. Happy to give you some pointers if you’re having specific issues. We also have a python script for doing something similar (again, via the API) that I can share if that would be useful.

The only part I’m not sure about is:

Then repeats when a new user signs up.

A new user will generally be auto-assigned to a pre-defined organization, or trigger the creation of a new organization (depending on the config http://docs.grafana.org/installation/configuration/#auto-assign-org). I’m not sure whether there’s an easy way to trigger a hook upon new user signup, which would pre-populate the new org with the dashboard, etc.


#3

Thank you,I have been able to do almost all the operations.But i m stuck at only one place.I have created a new organization and a new user for that organization everything through api.But i have base dashboard which is in the main organization.Which i need to keep in the organization which now i created the same dashboard with all the variables.


#4

Good to hear!

Regarding the last step, you should be able to: (1) pull down the JSON of the dashboard in the main org using a dashboard API GET call, (2) make some small modifications (see below) and (3) push that JSON to the new org via another API call. This should result in a 1:1 replication, including variables. You’ll of course also need to make sure that a datasource(s) of the same name exist in the new org.

Off the top of my head, the modifications you’ll need to make to the original JSON are as follows:

  • Remove (or set to null) the dashboard->id and dashboard->uid fields, as these should be free to be auto-assigned for the new dashboard
  • Set dashboard->version to 0 (this is probably optional)
  • Remove the meta key and the map under it (again probably optional)

Finally, you can use http://docs.grafana.org/http_api/preferences/#update-current-org-prefs to set the new dashboard as the home dashboard for your new org.


#5

Thanks,It is working.But now i got into serious issue.Where in grafana configuration i have kept my base organization for unathenticated access.How do i allow all the new organization which i create through apis to also be added there.


#6

I wanted to wait a few days to see if someone else can chip in, but I guess things have gone quiet.

I’m personally not too familiar with the nuances of anonymous access, but according to the docs at least it doesn’t sound like it’s pissible to enable anonymous access on multiple organizations.

So you may need to find a workaround, like “faking” anonymous access with authproxy