Skip to content

Add possibility to show REST call result #17

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

Open
ftasso opened this issue Dec 22, 2022 · 13 comments
Open

Add possibility to show REST call result #17

ftasso opened this issue Dec 22, 2022 · 13 comments

Comments

@ftasso
Copy link

ftasso commented Dec 22, 2022

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

@speakyourcode
Copy link
Owner

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

@ftasso
Copy link
Author

ftasso commented Dec 27, 2022

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
Copy link

canob commented Apr 5, 2023

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
Copy link
Author

ftasso commented Apr 14, 2023 via email

@canob
Copy link

canob commented Apr 14, 2023

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
Copy link
Author

ftasso commented Apr 18, 2023

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
Copy link

canob commented Apr 18, 2023

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

Regards,
Alejandro

@canob
Copy link

canob commented Apr 19, 2023

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
Copy link
Author

ftasso commented Apr 20, 2023

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

Bye,
Fabrizio

@Akuzike8
Copy link

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.

@Akuzike8
Copy link

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 } }

@canob
Copy link

canob commented Jun 24, 2024

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?

@Akuzike8
Copy link

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.

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

4 participants