ruby-grafana-reporter 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +337 -203
  3. data/lib/VERSION.rb +2 -2
  4. data/lib/grafana/abstract_datasource.rb +6 -3
  5. data/lib/grafana/errors.rb +2 -2
  6. data/lib/grafana/grafana_property_datasource.rb +8 -1
  7. data/lib/grafana/panel.rb +1 -1
  8. data/lib/grafana/sql_datasource.rb +1 -9
  9. data/lib/grafana/variable.rb +26 -20
  10. data/lib/grafana_reporter/abstract_query.rb +37 -19
  11. data/lib/grafana_reporter/abstract_report.rb +17 -4
  12. data/lib/grafana_reporter/abstract_table_format_strategy.rb +34 -0
  13. data/lib/grafana_reporter/alerts_table_query.rb +5 -1
  14. data/lib/grafana_reporter/annotations_table_query.rb +5 -1
  15. data/lib/grafana_reporter/application/application.rb +7 -2
  16. data/lib/grafana_reporter/application/webservice.rb +34 -29
  17. data/lib/grafana_reporter/asciidoctor/adoc_plain_table_format_strategy.rb +25 -0
  18. data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +2 -1
  19. data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +2 -1
  20. data/lib/grafana_reporter/asciidoctor/help.rb +458 -0
  21. data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +5 -1
  22. data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +5 -1
  23. data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +5 -1
  24. data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +5 -1
  25. data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +3 -0
  26. data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +3 -2
  27. data/lib/grafana_reporter/asciidoctor/report.rb +15 -13
  28. data/lib/grafana_reporter/asciidoctor/show_help_include_processor.rb +1 -1
  29. data/lib/grafana_reporter/asciidoctor/sql_table_include_processor.rb +5 -1
  30. data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +5 -1
  31. data/lib/grafana_reporter/console_configuration_wizard.rb +2 -2
  32. data/lib/grafana_reporter/csv_table_format_strategy.rb +23 -0
  33. data/lib/grafana_reporter/demo_report_wizard.rb +0 -1
  34. data/lib/grafana_reporter/erb/demo_report_builder.rb +46 -0
  35. data/lib/grafana_reporter/erb/report.rb +13 -7
  36. data/lib/grafana_reporter/errors.rb +9 -7
  37. data/lib/grafana_reporter/query_value_query.rb +1 -1
  38. data/lib/grafana_reporter/report_webhook.rb +12 -8
  39. metadata +7 -3
  40. data/lib/grafana_reporter/help.rb +0 -443
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24eeae0371069c8375a2d1eaa9533630f57d63939ba8426041b8c6ccc3a3ddd9
4
- data.tar.gz: 0deba99c14aead036fe70fc0bd07a4cac5332f436282e5fffdaba5884c3a5c47
3
+ metadata.gz: 7553ba3b91efd75d9e435a4c4d8148670b3337e953e2b39f13ae63ebf2f5fbb2
4
+ data.tar.gz: 696ea8b584bf017553f0b1fc9849870e78495f7257e7ea40671107c10254f66d
5
5
  SHA512:
6
- metadata.gz: 1bfd492430be9661470ab7ee9ceb25bdbfb91e845adbdd8d493c3fd121a4e09c68b52c2bb74793422ab4940507cd27fb8542e4a1aa6dde8da9ce6ceb2339a751
7
- data.tar.gz: fe2aced545c186bb803dfdbfe0988d4af135e39d45c6243cbf69c6e4012e96c15be1d4fdd5c76004593b4b4b4ed849240471304b9147c46ea42c415ef7ac47e1
6
+ metadata.gz: d10fd4f00099b92b843dc02a418487bae5de21363253212b2a5cc52794c6c11e361e300decef92524b5513e963c19eb11a9aaf82977aff4664be5a9da61ebc51
7
+ data.tar.gz: 85bb38c275136bc1f0318e9af15beacd98a1d7d3819c5e43db97b8df01abf8dc75b556618bb012eba4ead25c0b4bdef1baf80e5067cdf87307bf977331f61411
data/README.md CHANGED
@@ -1,203 +1,337 @@
1
- [![MIT License](https://img.shields.io/github/license/divinity666/ruby-grafana-reporter.svg?style=flat-square)](https://github.com/divinity666/ruby-grafana-reporter/blob/master/LICENSE)
2
- [![Build Status](https://travis-ci.com/divinity666/ruby-grafana-reporter.svg?branch=master)](https://travis-ci.com/github/divinity666/ruby-grafana-reporter?branch=master)
3
- [![Coverage Status](https://coveralls.io/repos/github/divinity666/ruby-grafana-reporter/badge.svg?branch=master)](https://coveralls.io/github/divinity666/ruby-grafana-reporter?branch=master)
4
- [![Gem Version](https://badge.fury.io/rb/ruby-grafana-reporter.svg)](https://badge.fury.io/rb/ruby-grafana-reporter)
5
-
6
- # Ruby Grafana Reporter
7
- Reporting Service for Grafana
8
-
9
- ## Table of Contents
10
-
11
- * [About the project](#about-the-project)
12
- * [Features](#features)
13
- * [Supported datasources](#supported-datasources)
14
- * [Quick Start](#quick-start)
15
- * [Grafana integration](#grafana-integration)
16
- * [Webservice overview](#webservice-overview)
17
- * [Roadmap](#roadmap)
18
- * [Donations](#donations)
19
-
20
- ## About the project
21
-
22
- [Grafana](https://github.com/grafana/grafana) is a great tool for monitoring and
23
- visualizing data from different sources. Anyway the free version is lacking a
24
- professional reporting functionality. And this is, where the ruby grafana reporter
25
- steps in.
26
-
27
- The key functionality of the reporter is to capture data and images from grafana
28
- dashboards and to use it in your custom reports to finally create reports in PDF,
29
- HTML, or any other format.
30
-
31
- By default (an extended version of) Asciidoctor is enabled as template language.
32
-
33
- ## Features
34
-
35
- * Supports creation of reports for multiple [grafana](https://github.com/grafana/grafana)
36
- dashboards (and also multiple grafana installations!) in one resulting report
37
- * PDF (default), HTML and many other report formats are supported
38
- * Easy-to-use configuration wizard, including fully automated functionality to create a
39
- demo report for your dashboard
40
- * Include dynamic content from grafana (find here a reference for all
41
- [asciidcotor reporter calls](FUNCTION_CALLS.md)):
42
- * panels as images
43
- * tables based on grafana panel queries or custom database queries (no images!)
44
- * single values to be integrated in text, based on grafana panel queries or custom
45
- database queries
46
- * Runs as
47
- * webservice to be called directly from grafana
48
- * standalone command line tool, e.g. to be automated with `cron` or `bash` scrips
49
- * microservice from standard asciidoctor docker container without any dependencies
50
- * Supports webhook callbacks on before, on cancel and on finishing a report (see
51
- configuration file)
52
- * Solid as a rock, also in case of template errors and whatever else may happen
53
- * Full [API documentation](https://rubydoc.info/gems/ruby-grafana-reporter) available
54
-
55
- ## Supported datasources
56
-
57
- Functionalities are provided as shown here:
58
-
59
- Database | Image rendering | Raw queries | Composed queries
60
- ------------------------- | :-------------: | :-----------: | :------------:
61
- all SQL based datasources | supported | supported | supported
62
- Graphite | supported | supported | supported
63
- InfluxDB | supported | supported | not (yet) supported
64
- Prometheus | supported | supported | n/a in grafana
65
- other datasources | supported | not supported | not supported
66
-
67
- The characteristics of a raw query are, that the query is either specified manually in
68
- the panel specification or in the calling template.
69
-
70
- Composed queries are all kinds of query, where the grafana UI feature (aka visual editor
71
- mode) for query specifications are used. In this case grafana is translating the UI query
72
- specification to a raw query, which then in fact is sent to the database.
73
-
74
- ## Quick Start
75
-
76
- You don't have a grafana setup runnning already? No worries, just configure
77
- `https://play.grafana.org` in the configuration wizard and see the magic
78
- happen!
79
-
80
- If your grafana setup requires a login, you'll have to setup an api key for
81
- the reporter. Please follow the steps
82
- [described here](https://github.com/divinity666/ruby-grafana-reporter/issues/2#issuecomment-811836757)
83
- first.
84
-
85
- **Windows:**
86
-
87
- * [Download latest Windows executable](https://github.com/divinity666/ruby-grafana-reporter/releases/latest)
88
- * `ruby-grafana-reporter -w`
89
-
90
- **Raspberry Pi:**
91
-
92
- * `sudo apt-get install ruby`
93
- * `gem install ruby-grafana-reporter`
94
- * `ruby-grafana-reporter -w`
95
-
96
- **Ruby environment:**
97
-
98
- * `gem install ruby-grafana-reporter`
99
- * `ruby-grafana-reporter -w`
100
-
101
- **Docker environment** (advanced users):
102
-
103
- * [Download latest single-rb file](https://github.com/divinity666/ruby-grafana-reporter/releases/latest)
104
- to an empty folder
105
- * create a configuration file by calling `ruby ruby-grafana-reporter -w` (if in doubt,
106
- run the command within your docker container)
107
- * create file `/<<path-to-single-rb-file-folder>>/startup.sh` with the following
108
- content:
109
-
110
- ```
111
- cd /documents
112
- ruby bin/ruby-grafana-reporter
113
- ```
114
- * add the startup script to your asciidoctor section in your docker-compose.yaml:
115
-
116
- ```
117
- asciidoctor:
118
- image: asciidoctor/docker-asciidoctor
119
- container_name: asciidoctor
120
- hostname: asciidoctor
121
- volumes:
122
- - /<<path-to-single-rb-file-folder>>:/documents
123
- command:
124
- sh /documents/startup.sh
125
- restart: unless-stopped
126
- ```
127
- * start/restart the asciidoctor docker container
128
-
129
- ## Grafana integration
130
-
131
- For using the reporter directly from grafana, you need to simply add a link to your
132
- grafana dashboard:
133
-
134
- * Open the dashboard configuration
135
- * Select `Links`
136
- * Select `Add`
137
- * Fill out as following:
138
- * Type: `link`
139
- * Url: `http://<<your-server-url>>:<<your-webservice-port>>/render?var-template=demo_report`
140
- * Title: `Demo Report`
141
- * Select `Time range`
142
- * Select `Variable values`
143
- * Select `Add`
144
-
145
- Now go back to your dashboard and click the newly generated `Demo Report`
146
- link on it. Now the renderer should start it's task and show you the expected
147
- results.
148
-
149
- Please note, that the reporter won't automatically refresh your screen to update
150
- the progress. Simply hit `F5` to refresh your browser. After the report has been
151
- successfully built, it will show the PDF after the next refresh automatically.
152
-
153
- You want to select a template in grafana, which shall then be rendered?
154
- Piece of cake: Just add a dashboard variable to your grafana dashboard named
155
- `template` and let the user select or enter a template name. To make use of it,
156
- you should change the link of the `Demo Report` link to
157
- `http://<<your-server-url>>:<<your-webservice-port>>/render?`. On
158
- hitting the new link in the dashboard, grafana will add the selected template as
159
- a variable and forward it to the reporter.
160
-
161
- ## Webservice overview
162
-
163
- Running the reporter as a webservice provides the following URLs
164
-
165
- /overview - for all running or retained renderings
166
- /render - for rendering a template, 'var-template' is the only mandatory GET parameter
167
- /view_report - for viewing the status or receving the result of a specific rendering, is automatically called after a successfull /render call
168
- /cancel_report - for cancelling the rendering of a specific report, normally not called manually, but on user interaction in the /view_report or /overview URL
169
-
170
- The main endpoint to call for report generation is configured in the previous chapter [Grafana integration](#grafana-integration).
171
-
172
- However, if you would like to see, currently running report generations and previously generated reports, you may want to call the endpoint `/overview`.
173
-
174
- ## Roadmap
175
-
176
- This is just a collection of things, I am heading for in future, without a schedule.
177
-
178
- * Support all grafana datasources
179
- * Solve code TODOs
180
- * Become [rubocop](https://rubocop.org/) ready
181
-
182
- ## Contributing
183
-
184
- If you'd like to contribute, please fork the repository and use a feature
185
- branch. Pull requests are warmly welcome.
186
-
187
- ## Licensing
188
-
189
- The code in this project is licensed under MIT license.
190
-
191
- ## Acknowledgements
192
- * [asciidoctor](https://github.com/asciidoctor/asciidoctor)
193
- * [asciidoctor-pdf](https://github.com/asciidoctor/asciidoctor-pdf)
194
- * [grafana](https://github.com/grafana/grafana)
195
-
196
- Inspired by [Izak Marai's grafana reporter](https://github.com/IzakMarais/reporter)
197
-
198
- ## Donations
199
-
200
- If this project saves you as much time as I hope it does, and if you'd like to
201
- support my work, feel free donate. :)
202
-
203
- [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate?hosted_button_id=35LH6JNLPHPHQ)
1
+ [![MIT License](https://img.shields.io/github/license/divinity666/ruby-grafana-reporter.svg?style=flat-square)](https://github.com/divinity666/ruby-grafana-reporter/blob/master/LICENSE)
2
+ [![Build Status](https://travis-ci.com/divinity666/ruby-grafana-reporter.svg?branch=master)](https://travis-ci.com/github/divinity666/ruby-grafana-reporter?branch=master)
3
+ [![Coverage Status](https://coveralls.io/repos/github/divinity666/ruby-grafana-reporter/badge.svg?branch=master)](https://coveralls.io/github/divinity666/ruby-grafana-reporter?branch=master)
4
+ [![Gem Version](https://badge.fury.io/rb/ruby-grafana-reporter.svg)](https://badge.fury.io/rb/ruby-grafana-reporter)
5
+
6
+ # Ruby Grafana Reporter
7
+ Reporting Service for Grafana
8
+
9
+ ## Table of Contents
10
+
11
+ * [About the project](#about-the-project)
12
+ * [Features](#features)
13
+ * [Supported datasources](#supported-datasources)
14
+ * [Quick Start](#quick-start)
15
+ * [Setup](#setup)
16
+ * [Grafana integration](#grafana-integration)
17
+ * [Advanced information](#advanced-information)
18
+ * [Webservice](#webservice)
19
+ * [Using ERB templates](#using-erb-templates)
20
+ * [Using webhooks](#using-webhooks)
21
+ * [Developing your own plugin](#developing-your-own-plugin)
22
+ * [Roadmap](#roadmap)
23
+ * [Donations](#donations)
24
+
25
+ ## About the project
26
+
27
+ [Grafana](https://github.com/grafana/grafana) is a great tool for monitoring and
28
+ visualizing data from different sources. Anyway the free version is lacking a
29
+ professional reporting functionality. And this is, where the ruby grafana reporter
30
+ steps in.
31
+
32
+ The key functionality of the reporter is to capture data and images from grafana
33
+ dashboards and to use it in your custom reports to finally create reports in PDF,
34
+ HTML, or any other format.
35
+
36
+ By default (an extended version of) Asciidoctor is enabled as template language.
37
+
38
+ ## Features
39
+
40
+ * Supports creation of reports for multiple [grafana](https://github.com/grafana/grafana)
41
+ dashboards (and also multiple grafana installations!) in one resulting report
42
+ * PDF (default), HTML and many other report formats are supported
43
+ * Easy-to-use configuration wizard, including fully automated functionality to create a
44
+ demo report for your dashboard
45
+ * Include dynamic content from grafana (find here a reference for all
46
+ [asciidcotor reporter calls](FUNCTION_CALLS.md)):
47
+ * panels as images
48
+ * tables based on grafana panel queries or custom database queries (no images!)
49
+ * single values to be integrated in text, based on grafana panel queries or custom
50
+ database queries
51
+ * Runs as
52
+ * webservice to be called directly from grafana
53
+ * standalone command line tool, e.g. to be automated with `cron` or `bash` scrips
54
+ * microservice from standard asciidoctor docker container without any dependencies
55
+ * Supports webhook callbacks on before, on cancel and on finishing a report (see
56
+ configuration file)
57
+ * Solid as a rock, also in case of template errors and whatever else may happen
58
+ * Full [API documentation](https://rubydoc.info/gems/ruby-grafana-reporter) available
59
+
60
+ ## Supported datasources
61
+
62
+ Functionalities are provided as shown here:
63
+
64
+ Database | Image rendering | Raw queries | Composed queries
65
+ ------------------------- | :-------------: | :-----------: | :------------:
66
+ all SQL based datasources | supported | supported | supported
67
+ Graphite | supported | supported | supported
68
+ InfluxDB | supported | supported | not (yet) supported
69
+ Prometheus | supported | supported | n/a in grafana
70
+ other datasources | supported | not supported | not supported
71
+
72
+ The characteristics of a raw query are, that the query is either specified manually in
73
+ the panel specification or in the calling template.
74
+
75
+ Composed queries are all kinds of query, where the grafana UI feature (aka visual editor
76
+ mode) for query specifications are used. In this case grafana is translating the UI query
77
+ specification to a raw query, which then in fact is sent to the database.
78
+
79
+ ## Quick Start
80
+
81
+
82
+ ### Setup
83
+
84
+ You don't have a grafana setup runnning already? No worries, just configure
85
+ `https://play.grafana.org` in the configuration wizard and see the magic
86
+ happen!
87
+
88
+ If your grafana setup requires a login, you'll have to setup an api key for
89
+ the reporter. Please follow the steps
90
+ [described here](https://github.com/divinity666/ruby-grafana-reporter/issues/2#issuecomment-811836757)
91
+ first.
92
+
93
+ **Windows:**
94
+
95
+ * [Download latest Windows executable](https://github.com/divinity666/ruby-grafana-reporter/releases/latest)
96
+ * `ruby-grafana-reporter -w`
97
+
98
+ **Raspberry Pi:**
99
+
100
+ * `sudo apt-get install ruby`
101
+ * `gem install ruby-grafana-reporter`
102
+ * `ruby-grafana-reporter -w`
103
+
104
+ **Ruby environment:**
105
+
106
+ * `gem install ruby-grafana-reporter`
107
+ * `ruby-grafana-reporter -w`
108
+
109
+ **Docker environment** (advanced users):
110
+
111
+ * [Download latest single-rb file](https://github.com/divinity666/ruby-grafana-reporter/releases/latest)
112
+ to an empty folder
113
+ * create a configuration file by calling `ruby ruby-grafana-reporter -w` (if in doubt,
114
+ run the command within your docker container)
115
+ * create file `/<<path-to-single-rb-file-folder>>/startup.sh` with the following
116
+ content:
117
+
118
+ ```
119
+ cd /documents
120
+ ruby bin/ruby-grafana-reporter
121
+ ```
122
+ * add the startup script to your asciidoctor section in your docker-compose.yaml:
123
+
124
+ ```
125
+ asciidoctor:
126
+ image: asciidoctor/docker-asciidoctor
127
+ container_name: asciidoctor
128
+ hostname: asciidoctor
129
+ volumes:
130
+ - /<<path-to-single-rb-file-folder>>:/documents
131
+ command:
132
+ sh /documents/startup.sh
133
+ restart: unless-stopped
134
+ ```
135
+ * start/restart the asciidoctor docker container
136
+
137
+ ### Grafana integration
138
+
139
+ For using the reporter directly from grafana, you need to simply add a link to your
140
+ grafana dashboard:
141
+
142
+ * Open the dashboard configuration
143
+ * Select `Links`
144
+ * Select `Add`
145
+ * Fill out as following:
146
+ * Type: `link`
147
+ * Url: `http://<<your-server-url>>:<<your-webservice-port>>/render?var-template=demo_report`
148
+ * Title: `Demo Report`
149
+ * Select `Time range`
150
+ * Select `Variable values`
151
+ * Select `Add`
152
+
153
+ Now go back to your dashboard and click the newly generated `Demo Report`
154
+ link on it. Now the renderer should start it's task and show you the expected
155
+ results.
156
+
157
+ Please note, that the reporter won't automatically refresh your screen to update
158
+ the progress. Simply hit `F5` to refresh your browser. After the report has been
159
+ successfully built, it will show the PDF after the next refresh automatically.
160
+
161
+ You want to select a template in grafana, which shall then be rendered?
162
+ Piece of cake: Just add a dashboard variable to your grafana dashboard named
163
+ `template` and let the user select or enter a template name. To make use of it,
164
+ you should change the link of the `Demo Report` link to
165
+ `http://<<your-server-url>>:<<your-webservice-port>>/render?`. On
166
+ hitting the new link in the dashboard, grafana will add the selected template as
167
+ a variable and forward it to the reporter.
168
+
169
+ ## Advanced information
170
+
171
+ ### Webservice
172
+
173
+ Running the reporter as a webservice provides the following URLs
174
+
175
+ /overview - for all running or retained renderings
176
+ /render - for rendering a template, 'var-template' is the only mandatory GET parameter, all parameters will be passed to the report templates as attributes
177
+ /view_report - for viewing the status or receving the result of a specific rendering, is automatically called after a successfull /render call
178
+ /cancel_report - for cancelling the rendering of a specific report, normally not called manually, but on user interaction in the /view_report or /overview URL
179
+
180
+ The main endpoint to call for report generation is configured in the previous chapter [Grafana integration](#grafana-integration).
181
+
182
+ However, if you would like to see, currently running report generations and previously generated reports, you may want to call the endpoint `/overview`.
183
+
184
+ ### Using ERB templates
185
+
186
+ By default the configuration wizard will setup the reporter with the asciidoctor
187
+ template language enabled. For several reasons, you may want to take advantage of
188
+ the ruby included
189
+ [ERB template language](https://docs.ruby-lang.org/en/master/ERB.html).
190
+
191
+ Anyway you should consider, that ERB templates can include harmful code. So make
192
+ sure, that you will only use ERB templates in a safe environment.
193
+
194
+ To enable the ERB template language, you need to modify your configuration file
195
+ in the section `grafana-reporter`:
196
+
197
+ ````
198
+ grafana-reporter:
199
+ report-class: GrafanaReporter::ERB::Report
200
+ ````
201
+
202
+ Restart the grafana reporter instance, if running as webservice. That's all.
203
+
204
+ In ERB templates, you have access to the variables `report`, which is a reference
205
+ to the currently executed
206
+ [ERB Report object](https://rubydoc.info/gems/ruby-grafana-reporter/GrafanaReporter/ERB/Report)
207
+ and `attributes`, which contains a hash
208
+ of variables, which have been handed over to the report generations, e.g. from
209
+ a webservice call.
210
+
211
+ To test the configuration, you may want to run the configuration wizard again,
212
+ which will create an ERB template for you.
213
+
214
+ ### Using webhooks
215
+
216
+ Webhooks provide an easy way to get automatically informed about the progress
217
+ of a report. The nice thing is, that this is completely independent from
218
+ running the reporter as webservice, i.e. these callbacks are also called if you
219
+ run the reporter standalone.
220
+
221
+ To use webhooks, you have to specify, in which progress states of a report you
222
+ are interested. Therefore you have to configure it in the `grafana-reporter`
223
+ section of your configuration file, e.g.
224
+
225
+ ````
226
+ grafana-reporter:
227
+ callbacks:
228
+ all:
229
+ - http://<<your_callback_url>>
230
+ ````
231
+
232
+ Remember to restart the reporter, if it is running as a webservice.
233
+
234
+ After having done so, your callback url will be called for each event with
235
+ a JSON body including all necessary information of the report. For details see
236
+ [callback](https://rubydoc.info/gems/ruby-grafana-reporter/GrafanaReporter/ReportWebhook#callback-instance_method).
237
+
238
+ ### Developing your own plugin
239
+
240
+ The reporter is designed to allow easy integration of your own plugins,
241
+ without having to modify the reporter base source on github (or anywhere
242
+ else). This section shows how to implement and load a custom datasource.
243
+
244
+ Implementing a custom datasource is needed, if you use a custom datasource
245
+ grafana plugin, which is not yet supported by the reporter. In that case you
246
+ can build your own custom datasource for the reporter and load it on demand
247
+ with a command line parameter, without having to build your own fork of this
248
+ project.
249
+
250
+ This documentation will provide a simple, but mocked implementation of an
251
+ imagined grafana datasource.
252
+
253
+ First of all, let's create a new text file, e.g. `my_datasource.rb` with the
254
+ following content:
255
+
256
+ ````
257
+ class MyDatasource < ::Grafana::AbstractDatasource
258
+ def self.handles?(model)
259
+ tmp = new(model)
260
+ tmp.type == 'my_datasource'
261
+ end
262
+
263
+ def request(query_description)
264
+ # see https://rubydoc.info/gems/ruby-grafana-reporter/Grafana/AbstractDatasource#request-instance_method
265
+ # for detailed information of given parameters and expected return format
266
+
267
+ # TODO: call your datasource, e.g. via REST call
268
+ # TODO: return the value in the needed format
269
+ end
270
+
271
+ def raw_query_from_panel_model(panel_query_target)
272
+ # TODO: extract or build the query from the given grafana panel query target hash
273
+ end
274
+
275
+ def default_variable_format
276
+ # TODO, specify the default variable format
277
+ # see https://rubydoc.info/gems/ruby-grafana-reporter/Grafana/Variable#value_formatted-instance_method
278
+ # for detailed information.
279
+ end
280
+ end
281
+ ````
282
+
283
+ The only thing left to do now, is to make this datasource known to the
284
+ reporter. This can be done with the `-r` command line flag, e.g.
285
+
286
+ ````
287
+ ruby-grafana-reporter -r my_datasource.rb
288
+ ````
289
+
290
+ The reporter implemented some magic, to automatically register datasource
291
+ implementations on load, if they inherit from `::Grafana::AbstractDatasource`.
292
+ This means, that you don't have to do anything else here.
293
+
294
+ Now the reporter knows about your datasource implementation and will use it,
295
+ if you request information from a panel, which is linked to the type
296
+ `my_datasource` as specified in the `handles?` method above. If any errors
297
+ occur during execution, the reporter will catch them and show them in the error
298
+ log.
299
+
300
+ Registering a custom ruby file is independent from running the reporter as a
301
+ webservice or as a standalone executable. In any case the reporter will apply
302
+ the file.
303
+
304
+ Technically, loading your own plugin will call require for your ruby file,
305
+ _after_ all reporter files have been loaded and _before_ the execution of the
306
+ webservice or a rendering process starts.
307
+
308
+ ## Roadmap
309
+
310
+ This is just a collection of things, I am heading for in future, without a schedule.
311
+
312
+ * Support grafana internal datasources
313
+ * Solve code TODOs
314
+ * Become [rubocop](https://rubocop.org/) ready
315
+
316
+ ## Contributing
317
+
318
+ If you'd like to contribute, please fork the repository and use a feature
319
+ branch. Pull requests are warmly welcome.
320
+
321
+ ## Licensing
322
+
323
+ The code in this project is licensed under MIT license.
324
+
325
+ ## Acknowledgements
326
+ * [asciidoctor](https://github.com/asciidoctor/asciidoctor)
327
+ * [asciidoctor-pdf](https://github.com/asciidoctor/asciidoctor-pdf)
328
+ * [grafana](https://github.com/grafana/grafana)
329
+
330
+ Inspired by [Izak Marai's grafana reporter](https://github.com/IzakMarais/reporter)
331
+
332
+ ## Donations
333
+
334
+ If this project saves you as much time as I hope it does, and if you'd like to
335
+ support my work, feel free donate. :)
336
+
337
+ [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate?hosted_button_id=35LH6JNLPHPHQ)