Page 1 of 1

Convert grafana panels to images for control page.

PostPosted: Wed Sep 12, 2018 11:06 am
by eriass
Hi,
Probably someone has already made this but I couldn’t find it anywhere. With help from a awesome friend I have made a script that saves a grafana-panel to a jpg image. And with help of that jpg image I can display it on my control page.

First of all I install the Grafana/Influx plugin and make all settings for that plugin, make panels etc.
After that I add a API Key to get a authorization key.

Copy link, all text AFTER Authorization:

Then I go back to the grafana dashboard to choose which panel I want to view.
In top of the panel I press the little arrow and choose ”Share”
In the dialog box that opens I press the ”Direct link rendered image” button in the bottom left.

Copy that link as well. delete the from & to in the link or else you will have a static image.

then make a Action Group that executes a apple script:

do shell script "curl -o \”/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/images/image.jpg>” -H \"Authorization: <INSERT LINK FROM API>\” \"http://<INSERT GRAFANA LINK TO DIRECT LINK RENDERED IMAGE>\””


Of course you can change the path to the web server if you want to do another folder.

Make a schedule that automatically executes the action

After this you can add a refreshing URL in your control page, in my case:

http://user:password@127.0.0.1:8176/images/image.jpg

Hope you like it!

//Eric

Re: Convert grafana panels to images for control page.

PostPosted: Wed Sep 12, 2018 4:41 pm
by vtmikel
This is great. I’ll check it out!


Sent from my iPhone using Tapatalk Pro

Re: Convert grafana panels to images for control page.

PostPosted: Fri Sep 14, 2018 5:31 pm
by mundmc
Wait, I’ve been toying with the idea of Grafana, but I didn’t know the standalone plugin didn’t work with Control Pages. I am confused.


Sent from my iPhone using Tapatalk

Re: Convert grafana panels to images for control page.

PostPosted: Sun Sep 16, 2018 12:41 pm
by vtmikel
Grafana provides a web server that is used to view your dashboard. It's mostly client-based, using JavaScript. There's no way to directly embed the web content from Grafana into Indigo's control pages. There have been a couple of available ways to render individual panels to images, then make those images available in a control page. @eriass has provided a set of instructions in this thread.

Re: Convert grafana panels to images for control page.

PostPosted: Mon Sep 17, 2018 11:12 am
by mundmc
vtmikel wrote:
Grafana provides a web server that is used to view your dashboard. It's mostly client-based, using JavaScript. There's no way to directly embed the web content from Grafana into Indigo's control pages. There have been a couple of available ways to render individual panels to images, then make those images available in a control page. @eriass has provided a set of instructions in this thread.

Thank you for clarifying! They’re so pretty


Sent from my iPhone using Tapatalk

Re: Convert grafana panels to images for control page.

PostPosted: Tue Dec 04, 2018 12:14 pm
by Sharek326
I think I followed this correctly but I am getting an error in my log file

script error: around characters 10 to 11
Error script error: Expected “"” but found unknown token. (-2741)


As an example this is how I set it up. Did I miss something? The script won't compile

"curl -o \”/Library/Application Support/Perceptive Automation/Indigo 7.2/IndigoWebServer/images/image.jpg>” -H \"Authorization: Bearer eyJrIjoibXhXbUNKMjg0aWRIbTF0ckcwbEZXVlZnMHQ1SGMwdVYiLCJuIjoiSW5kaWdvQVBJIiwiaWQiOjF9" http://192.168.2.12:3006/api/dashboards/home\” \"http://192.168.2.12:3006/render/d-solo/xF85NDZiz/example-indigo-dashboard?orgId=1&panelId=20&from=1543860434201&to=1543946824201&width=1000&height=500””

Re: Convert grafana panels to images for control page.

PostPosted: Wed Dec 05, 2018 7:05 am
by roussell
Not sure if it’s the copy/paste but I see an odd number of quotes. Perhaps one too many/few?

Terry


Sent from my iPhone using Tapatalk

Re: Convert grafana panels to images for control page.

PostPosted: Wed Dec 05, 2018 9:10 am
by Sharek326
Well I am making progress but still getting an error....According to the instructions about I Added the API Key ( this is for test purposes ill change the key later.

this is the link of everything after Authorization:

Bearer eyJrIjoiYXB4YkZHY0FRMERLMzdITDdocmNEelpzMXdId3BZemciLCJuIjoiSW5kaWdvIiwiaWQiOjF9" http://192.168.2.12:3006/api/dashboards/home

Then it says copy the.direct link and delete everything after &from so the original link is this:

http://192.168.2.12:3006/render/d-solo/ ... 2FNew_York

then reduced to

http://192.168.2.12:3006/render/d-solo/ ... panelId=20

then use the about script entering the links in where needed

and it looks like this

do shell script "curl -o \"/Library/Application Support/Perceptive Automation/Indigo 7.2/IndigoWebServer/images/image.jpg>” -H \"Authorization: Bearer eyJrIjoiYXB4YkZHY0FRMERLMzdITDdocmNEelpzMXdId3BZemciLCJuIjoiSW5kaWdvIiwiaWQiOjF9" http://192.168.2.12:3006/api/dashboards/home\"\"http://192.168.2.12:3006/render/d-solo/xF85NDZiz/example-indigo-dashboard?orgId=1&panelId=20\""

but its not putting the file in the directory and when I run it in script editor its flagging the quote right after the API key with A identifier can’t go after this “"”.

Re: Convert grafana panels to images for control page.

PostPosted: Thu Dec 06, 2018 10:58 am
by Sharek326
After reworking this code a million ways I am closer but now I am getting an error No Url Specified. Anyone have any ideas what I could be missing?

Code: Select all
do shell script "curl -o \"/Library/Application Support/Perceptive Automation/Indigo 7.2/IndigoWebServer/images/image.jpg\" -H \"Authorization: Bearer eyJrIjoiYXB4YkZHY0FRMERLMzdITDdocmNEelpzMXdId3BZemciLCJuIjoiSW5kaWdvIiwiaWQiOjF9 http://192.168.2.12:3006/api/dashboards/home\"\"http://192.168.2.12:3006/render/d-solo/xF85NDZiz/example-indigo-dashboard?orgId=1&panelId=20\""

Re: Convert grafana panels to images for control page.

PostPosted: Fri Dec 07, 2018 8:46 am
by vtmikel
I'm sorry that I haven't had time to look at this. Have you tried the other mention in this forum about the PhantomJS alternative? This is the official way that Grafana supports expoerting to images.

viewtopic.php?f=279&t=20920

I personally have not found the need for exporting so I don't do it myself.

Re: Convert grafana panels to images for control page.

PostPosted: Mon May 11, 2020 3:42 pm
by farberm
I am trying to get this to work after having some help getting the applescript convert to python.

It still does not create an image int he folder for me.

Any and all help appreciated
Code: Select all
import requests

# Set up the variable data by copying share link and deleting from and to portions. This link works when I paste into a web browser
url = "http://192.168.2.22:3006/render/d-solo/xF85NDZiz/indigo-home-dashboard?orgId=1&panelId=26&width=1000&height=500&tz=America%2FNew_York"
file_name = "{}/IndigoWebServer/images/image.jpg".format(indigo.server.getInstallFolderPath())
api_key = indigo.variables[123456789].value
auth_header = {"Authorization": api_key}

# Use the requests library to fetch the file
reply = requests.get(url, headers=auth_header)

# If it got a good reply
if reply.status_code == 200:
    # Open the output file
    with open(file_name, 'wb') as output_file:
        # Write out the image data to the file
        output_file.write(reply.content)