ruby-grafana-reporter 0.9.3 → 0.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c90ce3f15b0a5fa90cb7569a54467e10a251fce77d3642b75053b6792288d72d
4
- data.tar.gz: 3855618dd7c3a721340516b7949777f2efe045a0c093f0d1b7d3457eb1bcfc01
3
+ metadata.gz: 57a3edcb1aa6c41ed2a26688dc6a8a80fba3b9169aa79ee061eeb2d2c0df1cb9
4
+ data.tar.gz: 897ae84eb2672b645528e118ff7107e2fab7a4f334f63a4c87bb29a020cf93a8
5
5
  SHA512:
6
- metadata.gz: a7d90bac8d4dee595da22401d53f27380d4119ccca5df73020ae6abd12eb71ad4cee577f9b8bfc4200ca73e90a4467060aab6e3ffcb6db52af4682c1926f2feb
7
- data.tar.gz: 6851b6fc6714cf4376499dc585449040ed2f341536c80856c012eaf58bacdaca2f71813f66e07ce6c18926c973f3586cb364eedbb8896c66fea61f9674c0a17e
6
+ metadata.gz: b3889cace3794d62bfd50978a24c4eb39cda1148398a4bed8c4354d5c51ad339faa7da7a81b4f001cb29c383ac98334494520a9cbeec2b44019dcafae883bfdb
7
+ data.tar.gz: 9a7fbf743f0e48e114deaa1d518ba993ea0318229ab391d90481bad43f859b20fca9f8ffaafe6799729a81ace22673d4904797963c776cf9a22c942289f35c23
data/lib/VERSION.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Version information
4
- GRAFANA_REPORTER_VERSION = [0, 9, 3].freeze
4
+ GRAFANA_REPORTER_VERSION = [0, 9, 4].freeze
5
5
  # Release date
6
- GRAFANA_REPORTER_RELEASE_DATE = '2024-07-13'
6
+ GRAFANA_REPORTER_RELEASE_DATE = '2024-08-22'
@@ -62,8 +62,7 @@ module Grafana
62
62
  begin
63
63
  @variables << Variable.new(item, self)
64
64
  rescue => e
65
- # TODO: show this message as a warning - needs test cleanup
66
- @grafana.logger.debug(e.message)
65
+ @grafana.logger.warn(e.message)
67
66
  end
68
67
  end
69
68
  end
@@ -23,6 +23,7 @@ module Grafana
23
23
 
24
24
  result = webrequest.execute(query_description[:timeout])
25
25
  return unless result
26
+ return result.body unless result.code.to_s == "200"
26
27
 
27
28
  json = JSON.parse(result.body)
28
29
 
@@ -240,7 +240,7 @@ module Grafana
240
240
  if !@config['current'].nil?
241
241
  self.raw_value = @config['current']['value']
242
242
  else
243
- raise GrafanaError.new("Grafana variable with type '#{@config['type']}' and name '#{@config['name']}' cannot be handled properly by the reporter. Check your results and raise a ticket on github.")
243
+ raise GrafanaError.new("Dashboard variable with type '#{@config['type']}' and name '#{@config['name']}' cannot be handled properly by the reporter in queries. Check your resulting report and raise a ticket on github if you face issues.")
244
244
  end
245
245
  end
246
246
  end
@@ -134,6 +134,7 @@ module GrafanaReporter
134
134
  begin
135
135
  template_ext = config.report_class.default_template_extension
136
136
  report_ext = config.report_class.default_result_extension
137
+ report_ext = 'zip' if config.default_document_attributes["convert-backend"] != "pdf" and not config.default_document_attributes["convert-backend"].nil?
137
138
  default_to_file = File.basename(config.template.to_s.gsub(/(?:\.#{template_ext})?$/, ".#{report_ext}"))
138
139
 
139
140
  to_file = config.to_file
@@ -80,6 +80,7 @@ module GrafanaReporter
80
80
  # @see ProcessorMixin#build_demo_entry
81
81
  def build_demo_entry(panel)
82
82
  return nil unless panel
83
+ return nil unless panel.model['targets']
83
84
 
84
85
  ref_id = nil
85
86
  panel.model['targets'].each do |item|
@@ -74,6 +74,7 @@ module GrafanaReporter
74
74
  # @see ProcessorMixin#build_demo_entry
75
75
  def build_demo_entry(panel)
76
76
  return nil unless panel
77
+ return nil unless panel.model['targets']
77
78
 
78
79
  ref_id = nil
79
80
  panel.model['targets'].each do |item|
@@ -41,36 +41,29 @@ module GrafanaReporter
41
41
  ::Asciidoctor.convert_file(@template, extension_registry: registry, backend: attrs['convert-backend'],
42
42
  to_file: path, attributes: attrs, header_footer: true)
43
43
 
44
- # store report including als images as ZIP file, if the result is not a PDF
44
+ # store report including all images as ZIP file, if the result is not a PDF
45
45
  if attrs['convert-backend'] != 'pdf'
46
46
  # build zip file
47
- zip_file = Tempfile.new('gf_zip')
48
47
  buffer = Zip::OutputStream.write_buffer do |zipfile|
49
48
  # add report file
50
- zipfile.put_next_entry("#{path.gsub(@config.reports_folder, '')}.#{attrs['convert-backend']}")
51
- zipfile.write File.read(path)
49
+ zipfile.put_next_entry("#{path.gsub(@config.reports_folder, '').gsub(/\.[\w\d]+$/, '')}.#{attrs['convert-backend']}")
50
+ zipfile.write File.open(path, 'rb') { |f| f.read }
52
51
 
53
52
  # add image files
54
53
  @image_files.each do |file|
55
54
  zipfile.put_next_entry(file.path.gsub(@config.images_folder, ''))
56
- zipfile.write File.read(file.path)
55
+ zipfile.write File.open(file.path, 'rb') { |f| f.read }
57
56
  end
58
57
  end
59
- File.open(zip_file, 'wb') do |f|
60
- f.write buffer.string
61
- end
62
58
 
63
- # replace original file with zip file
64
- zip_file.rewind
59
+ # write zip file
65
60
  begin
66
- File.write(path, zip_file.read)
61
+ File.open(path, 'wb') do |f|
62
+ f.write buffer.string
63
+ end
67
64
  rescue StandardError => e
68
- logger.fatal("Could not overwrite report file '#{path}' with ZIP file. (#{e.message}).")
65
+ logger.fatal("Could not overwrite file '#{path}' with zipped file. (#{e.message}).")
69
66
  end
70
-
71
- # cleanup temporary zip file
72
- zip_file.close
73
- zip_file.unlink
74
67
  end
75
68
 
76
69
  clean_image_files
@@ -84,6 +84,8 @@ module GrafanaReporter
84
84
  end
85
85
  end
86
86
  return nil unless ref_id
87
+ # FIXME this filters out e.g. prometheus in demo reports, as the query method returns a Hash instead of a string
88
+ return nil unless panel.query(ref_id).is_a?(String)
87
89
 
88
90
  "|===\ninclude::grafana_sql_table:#{panel.dashboard.grafana.datasource_by_model_entry(panel.model['datasource']).id}"\
89
91
  "[sql=\"#{panel.query(ref_id).gsub(/"/, '\"').gsub("\r\n", ' ').gsub("\n", ' ').gsub(/\\/, '\\\\')}\",filter_columns=\"time\","\
@@ -89,6 +89,8 @@ module GrafanaReporter
89
89
  end
90
90
  end
91
91
  return nil unless ref_id
92
+ # FIXME this filters out e.g. prometheus in demo reports, as the query method returns a Hash instead of a string
93
+ return nil unless panel.query(ref_id).is_a?(String)
92
94
 
93
95
  "grafana_sql_value:#{panel.dashboard.grafana.datasource_by_model_entry(panel.model['datasource']).id}"\
94
96
  "[sql=\"#{panel.query(ref_id).gsub(/"/, '\"').gsub("\r\n", ' ').gsub("\n", ' ').gsub(/\\/, '\\\\')}\",from=\"now-1h\","\
@@ -319,8 +319,10 @@ default-document-attributes:
319
319
  end
320
320
 
321
321
  def user_input(text, default)
322
+ $stdout.sync = true
322
323
  print "#{text} [#{default}]: "
323
- input = gets.gsub(/\n$/, '')
324
+ $stdout.sync = false
325
+ input = gets.gsub(/[\n\r]*$/, '')
324
326
  input = default if input.empty?
325
327
  input
326
328
  end
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
- require 'rubygems/name_tuple'
5
- require 'rubygems/specification_policy'
6
- require 'rubygems/ext'
3
+ require 'rubygems' # for OCRAN
7
4
  require 'net/http'
8
5
  require 'fileutils'
9
6
  require 'yaml'
@@ -17,7 +14,7 @@ require 'date'
17
14
  require 'time'
18
15
  require 'logger'
19
16
  require 'asciidoctor'
20
- require 'asciidoctor/extensions'
17
+ require 'asciidoctor/converter/html5' # for OCRAN
21
18
  require 'asciidoctor-pdf'
22
19
  require 'zip'
23
20
  require_relative 'VERSION'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-grafana-reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kohlmeyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-13 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor