speakyourcode/grafana-button-panel

Add possibility to show REST call result

Opened this issue · 13 comments

Hello,
I'm trying to use your plugin with Infinity datasource.
It works fine but I have only a notify popup with the text "200 (OK)" as feedback.
Could you please add an optional text box to show results from datasource or (could be better) a javascript method to override?

Thank you for your plugin!

Fabrizio

I think the explorer from Grafana is better suited to debug queries than the toaster notification

Hello,
thank you for your reply.
Yes sure, the Grafana explorer is very nice for debug but I didn't spoke about the datasource debugging, I will try to explain better: I use the Infinity datasource to execute HTTP REST operations, for example start/stop linux services via Tomcat/HTTP servlet, and I would like to show the results of these HTTP request, in my case each HTTP request returns a JSON structure describing result/errors/details.

Bye,
Fabrizio

canob commented

Hi @ftasso . Can you give me an example on how you are using Infinity Datasource with this plugin?
For example, are you been able to pass a variable value to the http request?
I need to pass a host_id in the URL, and for example, in the same dashboard that I'm using Infinity Datasource to show information in a table, I'm using a variable to get the correct host_id.
Are you completing the "query" part of this plugin with any information?

Thanks for your help.

Regards!

ftasso commented
canob commented

Hi @ftasso , thanks for your response.

To understand your answer and "translate" to what I need, suppose that the URL that I want to access is https://api.edr.com/device?action=block, with POST method, and the JSON Body Content is:
{ "host": [ ${host_id:doublequote} ] }
Where $host_id is the variable in Grafana that contain the host to block.
How can I translate that to your example? Maybe like this?

{
    "source": "url",
    "type": "json",
    "url": "https://api.edr.com/device?action=block",
    "url_options": {
       "accept": "application/json",
       "body_content_type": "application/json",
       "body": "{ "host": [ ${host_id:doublequote} ] }",
       "method": "POST"
    }
}

Is not clear for me where I need to put the "accept:application/json" header and the JSON body content in your example.

The CURL that I'm using and is working is:
curl -X POST "https://api.edr.com/device?action=block" -H "accept: application/json" -H "authorization: Bearer bigandlargetoken" -H "Content-Type: application/json" -d "{ \"host\": [ \"somehost\" ]}"

Can you tell me if my example translated from your example is ok?

Thanks in advance.

Regards,
Alejandro

ftasso commented

Hello Alejandro,
try this
immagine

{
"source": "url",
"type": "json",
"url": "https://api.edr.com/device?action=block",
"url_options": {
"body_content_type": "text/plain",
"body_type": "x-www-form-urlencoded",
"params":[{"key":"host","value":"${host_id}"}],
"method": "POST"
}
}

Bye,
Fabrizio

canob commented

Thanks @ftasso , I'm going to try with your example and let you know.

Regards,
Alejandro

canob commented

Hi @ftasso,

Finally It worked, after review your example, and viewed in the plugin homepage that what you need to put on Query is the same that you see on "query" on Query Inspector on Grafana.

This is the JSON I finally used:

{
    "alias": "",
    "columns": [],
    "computed_columns": [],
    "csv_options": {
      "columns": "",
      "comment": "",
      "delimiter": "",
      "relax_column_count": false,
      "skip_empty_lines": false,
      "skip_lines_with_error": false
    },
    "data": "",
    "dataOverrides": null,
    "expression": "",
    "filterExpression": "",
    "filters": [],
    "format": "table",
    "global_query_id": "",
    "groq": "",
    "json_options": {
      "columnar": false,
      "root_is_not_array": false
    },
    "parser": "backend",
    "query_mode": "",
    "refId": "A",
    "root_selector": "",
    "seriesCount": 0,
    "source": "url",
    "sqlite_query": "",
    "summarizeBy": "",
    "summarizeExpression": "",
    "type": "json",
    "uql": "",
    "url": "https://api.edr.com/device?action=block",
    "url_options": {
      "body_content_type": "application/json",
      "body_form": null,
      "body_graphql_query": "",
      "body_type": "raw",
      "data": "{\r\n    \"host\": [\"${host_id}\"]\r\n}",
      "headers": [
       {
         "key": "accept",
         "value": "application/json"
       }
      ],
      "method": "POST",
      "params": null
    }
}

Really thanks for all your help.

Regards,
Alejandro

ftasso commented

I'm happy you solved the problem. Nice job Alejandro.

Bye,
Fabrizio

Hi @canob ,

I was following the conversation and tried implementing the same but I am having trouble getting it to work. I am getting a Bad request response instead. May you please assist me.

This is what i submitted.
{ "alias": "", "columns": [], "computed_columns": [], "csv_options": { "columns": "", "comment": "", "delimiter": "", "relax_column_count": false, "skip_empty_lines": false, "skip_lines_with_error": false }, "data": "", "dataOverrides": null, "expression": "", "filterExpression": "", "filters": [], "format": "table", "global_query_id": "", "groq": "", "json_options": { "columnar": false, "root_is_not_array": false }, "parser": "backend", "query_mode": "", "root_selector": "", "seriesCount": 0, "source": "url", "sqlite_query": "", "summarizeBy": "", "summarizeExpression": "", "type": "json", "uql": "", "url": "http://127.0.0.1:8882/", "url_options": { "body_content_type": "", "body_form": null, "body_graphql_query": "", "body_graphql_variables": "", "body_type": "", "data": "", "headers": null, "method": "GET", "params": null } }

Hi @Akuzike8,

It's not clear by your description what http://127.0.0.1:8882 is expecting (for example, no headers, no params?), but if it is a GET, the first question for you is if it is working (you are getting an answer) if you put http://127.0.0.1:8882/ in your web browser for example?

Hi @canob ,

I have made adjustments and have fixed the problem. I am now using a POST request instead with all the required set. Thanks for your help.