ruby-grafana-reporter icon indicating copy to clipboard operation
ruby-grafana-reporter copied to clipboard

Generate reports through API call

Open hoouinkyouma opened this issue 9 months ago • 4 comments
trafficstars

Hi divinity666, thanks a lot for building this tool. I've been trying to take reports by making api calls. I'm running the reporter in a docker container.

When I do an api call to generate report: curl -X POST "http://ip_address:8815/api/v1/render" -d "var-template=linux&var-from=$(date -d '1 hour ago' +%s000)&var-to=$(date +%s000)"

The var-template refers to the adoc file saved in the templates folder called linux.adoc.

I get a report_id back in response with it's id: ex: 2200

When I try to get the status of the report with: curl -X GET "http://ip_address:8815/api/v1/status?id=2200", I get a response saying: GrafanaReporterError: Could not render report because of internal error: report_status has been called without valid id. I'm trying to look for all the valid api calls and it's parameters that I could provide but I just can't find them online.

I have 10 servers under monitoring, I'm trying to automate the process of reports. I'd like to generate report for all of the servers for the last month. Is there a swagger page that I can look at all api calls?

Also, do I have to pass in any variables along with the api call? my dashboards are variablized. Please help. Thank you in advance!

hoouinkyouma avatar Feb 11 '25 03:02 hoouinkyouma

I guess the parameter is named report_id instead of id (refer here).

Hope this helps

divinity666 avatar Feb 17 '25 20:02 divinity666

Hi @divinity666, thanks for the response. I'm sorry to bug you, I'm a novice in the APIs so this might be a silly question for you.

When I call the reporter for generating the report /api/v1/render with var-template=linux. which I'm able to make sure that the file is present in the container.

When called the api, in the logs it says: I, [2025-03-07T06:25:14.034415 #17] INFO -- : Server listening on port 8817... D, [2025-03-07T06:27:45.534262 #17] DEBUG -- : Received request: POST /api/v1/render HTTP/1.1 D, [2025-03-07T06:27:45.534364 #17] DEBUG -- : query_parameters: {"POST /api/v1/render HTTP/1.1"=>[]} I, [2025-03-07T06:27:45.536612 #17] INFO -- : 1 report(s) in progress: 0% (running 0 secs) E, [2025-03-07T06:27:45.536939 #17] ERROR -- : GrafanaReporterError: Configuration error: Accessing report template file './templates/.adoc' is not possible. Check if file exists and is accessible

I can't figure out why it's not picking the file. By the way, I'm using postman to make these api calls.

Please help me out. Thanks in advance!

kyouma24 avatar Mar 07 '25 06:03 kyouma24

Looks like the handed over var-template variable is not properly recognized. Looking at my tests, I saw that you have to pass that variable similar to the GET parameters, see also test case here.

Not really nice, but that should do the trick. Can you confirm?

divinity666 avatar Mar 20 '25 20:03 divinity666

I was able to generate the report through api call successfully, instead of passing the var-template in the header, i passed it in the URL as this: (http://XX.X.X.X:8817/api/v1/render?var-template=indi).

How do i pass in the labels to filter out the instances that i want to take the report for and timestamps (from & to)? Thank you so much in advance!

hoouinkyouma avatar Apr 22 '25 06:04 hoouinkyouma