Class: GrafanaReporter::ReportWebhook
- Inherits:
-
Object
- Object
- GrafanaReporter::ReportWebhook
- Defined in:
- lib/grafana_reporter/report_webhook.rb
Overview
This class provides a default webhook implementation for report events. It sends out a webrequest to the configured callback_url
with all necessary information about the event and the report.
Instance Method Summary collapse
-
#callback(event, report) ⇒ Object
Implements the call of the configured webhook.
-
#initialize(callback_url) ⇒ ReportWebhook
constructor
A new instance of ReportWebhook.
Constructor Details
#initialize(callback_url) ⇒ ReportWebhook
Returns a new instance of ReportWebhook.
8 9 10 |
# File 'lib/grafana_reporter/report_webhook.rb', line 8 def initialize(callback_url) @callback_url = callback_url end |
Instance Method Details
#callback(event, report) ⇒ Object
Implements the call of the configured webhook. Provides the following report information in JSON format:
:object_id - id of the current report
:path - file path to the report
:status - report status as string, e.g. `cancelled`, `finished` or `in progress`
:execution_time - execution time in seconds of the report
:template - name of the used template
:start_time - time when the report creation started
:end_time - time when the report creation ended
:event - event, which has happened, e.g. `on-before-create`
Please note that this callback is a non-blocking event, i.e. the report generation is proceeding, no matter if the callback is successfull and no matter how long the execution of the callback does take.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grafana_reporter/report_webhook.rb', line 27 def callback(event, report) # build report information as JSON data = { object_id: report.object_id, path: report.path, status: report.status, execution_time: report.execution_time, template: report.template, start_time: report.start_time, end_time: report.end_time, event: event } request = { body: JSON.generate(data), accept: nil, content_type: nil } res = ::Grafana::WebRequest.new(@callback_url, request).execute "#{res} - Body: #{res.body}" end |