Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restricted Grafana environment shows 'dashboard does not exist' [solved] #2

Closed
fsa1803 opened this issue Mar 22, 2021 · 8 comments
Closed

Comments

@fsa1803
Copy link

fsa1803 commented Mar 22, 2021

I have installed the reporter on CentOS 7 and Grafana 7.4.3. Grafana has restricted access. The installation and testing with MyFirstReport went well.

I created the following template:

= First Grafana report template
: grafana_default_dashboard: hiaysXEGk
grafana_panel_image: 3 [dashboard = "hiaysXEGk"]

and created the link in the Grafana dashboard.

I always get the following error:
GrafanaError: The specified dashboard 'hiaysXEGk' does not exist. (Grafana :: DashboardDoesNotExistError)
/usr/lib64/ruby/gems/2.7.0/gems/ruby-grafana-reporter-0.3.0/lib/grafana/grafana.rb:71:in dashboard ' /usr/lib64/ruby/gems/2.7.0/gems/ruby-grafana-reporter-0.3.0/lib/grafana_reporter/asciidoctor/extensions/panel_image_inline_macro.rb:48:in process'
/usr/lib64/ruby/gems/2.7.0/gems/asciidoctor-2.0.12/lib/asciidoctor/substitutors.rb:333:in [] ' /usr/lib64/ruby/gems/2.7.0/gems/asciidoctor-2.0.12/lib/asciidoctor/substitutors.rb:333:in block (2 levels) in sub_macros'

Note that the dashboard exists.

I think the problem is due to the API key. I don't know where to configure it, I tried in the grafana_reporter.config file like:

grafana:
  default:
    host: http://api_key:<my key>@<my IP>:3000

Note that has admin rights

Thanks.

@divinity666
Copy link
Owner

First of all: thanks for using the ruby-grafana-reporter.

  1. You are using the panel image inline macro. Please try using the panel image block macro instead:
    grafana_panel_image::3[]
    I had some issues a while ago, and maybe they still do persist (I have to check another day)

  2. Your configuration seems weird:
    a) Try to create your configuration file with the configuration option -w, to ensure a proper file including connection tests to your grafana instance.
    b) Manual way: Try your configuration like this:

grafana:
  default:
    host:  http://<<your_host>>:3000
    api_key: <<your_api_key>>
  1. Hint: the specification of the dashboard [dashboard="hiaysXEGk"] is not necessary, when configured previously with :grafana_default_dashboard: hiaysXEGk

  2. Info: Unfortunately, the reporter demo does not yet properly test against your grafana instance, but rather the proper setup of asciidoctor... This is on the roadmap for a next release.

Let me know, if this helps.

@fsa1803
Copy link
Author

fsa1803 commented Mar 23, 2021

I made the changes you suggested, but the problem persists.
After some testing I found the problem.
The problem is due to the fact that Grafana is configured to not allow anonymous access. In this case ruby-grafana-reporter uses orgId = 0 to access the dashboard:
t=2021-03-23T08:02:50+0100 lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/api/dashboards/uid/hiaysXEGk status=401 remote_addr=x.x.x.x time_ms=10 size=26 referer=

If I enable anonymous access in Grafana everything works, in this case ruby-grafana-reporter uses orgId = 1

I don't want to enable anonymous access, is there any way to fix this?

Thanks.

@divinity666
Copy link
Owner

Thanks for your investigation.

The reporter never uses the orgIds, as they are not relevant for the api_key connectivity. Instead, please ensure that the api_key you created is created in the correct organization. api_keys are organization-specific.

This also would explain, why enabling anonymous access is working. In that case the reporter does not use the provided api_key, but rather the read access available as an anonymous person.

Please reevaluate again and kindly come back with your feedback.

PS: If you want to access several grafana instances or several organizations within one grafana instance, you may simply configure additional grafana hosts in the configuration file. Then it's possible to put a query to the individual grafana instance by specifying instance=<<your_configured_grafana_instance_name>> as a property for individual requests, or by setting :grafana_default_instance: <<your_configured_grafana_instance_name>> which then applies as a default to the whole ADOC template.

@divinity666
Copy link
Owner

Can you kindly report if the issue is solved? Otherwise I will close the issue within the next days without further feedback, because of lacking information.

@karan369
Copy link

Can you kindly report if the issue is solved? Otherwise I will close the issue within the next days without further feedback, because of lacking information.

Thanks for your support.

I will try and update soon.

@fsa1803
Copy link
Author

fsa1803 commented Mar 31, 2021

I haven't solved the problem.
With this grafana configuration:
img02

when I configure have:
img01

and reporter go wrong

img05

With this Grafana configuration:
img04

I have:
img03

and reporter go fine.

@divinity666
Copy link
Owner

divinity666 commented Apr 1, 2021

Looks like we're getting closer :-)

To use the reporter in a non-anonymous environment, you have to create an API key first in your grafana organization. Please follow these steps:

  1. Login to your grafana instance

  2. Go to the API key section and create a new key
    image

  3. Create a new API key for the reporter with Viewer permissions. Set the Time to live to an appropriate time.
    api key

  4. Copy the shown key - it will never be visible later again!
    created_api_key

  5. Add the API key to your reporter configuration file:

grafana:
  default:
    host: <<your grafana host ip>>
    api_key: <<paste the API key here>>

Afterwards test your configuration again.

Please keep me informed, if that solves your issue.

PS: I will add this to the documentation.
PPS: The next reporter version will contain an improved configuration wizard, which asks for the API key, if the connection to grafana is otherwise not working.

@fsa1803
Copy link
Author

fsa1803 commented Apr 4, 2021

Resolved. Thanks.

@fsa1803 fsa1803 closed this as completed Apr 4, 2021
@divinity666 divinity666 changed the title Error while creating report Restricted Grafana environment shows 'dashboard does not exist' [solved] Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants