grafana-rb 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c327536b433f8d1a7ee301f62448bb85fa5b87bb
4
- data.tar.gz: cb9ff0e4f9d98c5d84feea2cecb1f212442b67b6
3
+ metadata.gz: 3156ec2300608d7d5823033df58876cdf87ed54e
4
+ data.tar.gz: b4a2f11146e868cb6499d7ae954ae05f2ba0c9d7
5
5
  SHA512:
6
- metadata.gz: f6b74e99e30807939dc72d9c1cc19c5c3cb45687cbcecc2c671036f88a635db49ef0e5417de604359d86ad9a852acaccecdacc81bbf890e67d2c7d9531ec6e9a
7
- data.tar.gz: 4d935e6572aedfb577417dc3b4b5c63b3dac6d55e9d4364000276bb9468705f1865cc42ada0aafd10a6f136851f186d637701d1ccbd3168339f379a1d088a59a
6
+ metadata.gz: a640c8ebbf28899e98017853f94168deaaaf9890d4267344b8cdd06043c38b8bda991ecc9ff9267742fb7be2d8ebfbeacc8a2babdd773299c8c16d941a196ffc
7
+ data.tar.gz: 5486cd0110270a11c408f6a1b26f8805b9ee1181f9f0c2a88ddf030ed6a4a949436e5fd3aec13eb352464110c4e8f36d825833183639501b9162248036eef740
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Grafana-rb 0.11.0 (April 6, 2017) ##
2
+
3
+ * Add `tool_version` param to check minimum version
4
+ * Add param to alow use custom working directory
5
+
1
6
  ## Grafana-rb 0.10.0 (April 3, 2017) ##
2
7
 
3
8
  * Add optional `duration` param.
@@ -7,11 +7,15 @@ module GrafanaRb
7
7
  class Cli
8
8
  def initialize(argv)
9
9
  @argv = argv
10
+ @workdir = Dir.pwd
10
11
  @panel_id = 0
11
12
  end
12
13
 
13
14
  def run
14
- if @argv[0] == "apply" || @argv[0] == "a" || @argv[0] == "q"
15
+ if @argv.last == "apply" || @argv.last == "a" || @argv.last == "q"
16
+ if @argv.size >= 2
17
+ @workdir = @argv[0]
18
+ end
15
19
  apply
16
20
  else
17
21
  usage
@@ -19,12 +23,15 @@ module GrafanaRb
19
23
  end
20
24
 
21
25
  private
22
- CONFIG_FILE = "grafana.yml"
23
26
  REQUIRE_DEFAULT_TEMPLATE = ["*.yml"]
24
27
  DEFAULT_GRAFANA_USER = "admin"
25
28
  DEFAULT_GRAFANA_PASSWORD = "admin"
26
29
  TAG = "grafana-rb"
27
30
 
31
+ def config_file
32
+ @config_file ||= File.join(@workdir, "grafana.yml")
33
+ end
34
+
28
35
  def request(method, path, params = {})
29
36
  uri = URI("http://" + config["grafana_url"] + path)
30
37
  http = Net::HTTP.new(uri.host, uri.port)
@@ -60,11 +67,12 @@ module GrafanaRb
60
67
  end
61
68
 
62
69
  def check_config_existance
63
- unless File.exists?(CONFIG_FILE)
64
- puts "FATAL: missed #{CONFIG_FILE} in current directory"
65
- puts "#{CONFIG_FILE} example:"
70
+ unless File.exists?(config_file)
71
+ puts "FATAL: missed #{config_file} in current directory"
72
+ puts "#{config_file} example:"
66
73
  puts ""
67
74
  puts "---"
75
+ puts "tool_version: #{GrafanaRb::VERSION}"
68
76
  puts "grafana_url: monitoring.your-domain.com:3000 # required"
69
77
  puts "prometheus_url: monitoring.your-domain.com:9090 # required"
70
78
  puts "grafana_user: user # 'admin' if missed"
@@ -79,7 +87,7 @@ module GrafanaRb
79
87
  end
80
88
 
81
89
  def config
82
- @config ||= YAML.load(File.read(CONFIG_FILE)) || {}
90
+ @config ||= YAML.load(File.read(config_file)) || {}
83
91
  end
84
92
 
85
93
  def grafana_user
@@ -92,8 +100,8 @@ module GrafanaRb
92
100
 
93
101
  def require_files
94
102
  @require_files ||= (config["require"] || REQUIRE_DEFAULT_TEMPLATE).flat_map { |template|
95
- Dir[template]
96
- }.map { |path| File.expand_path(path) } - [File.expand_path(CONFIG_FILE)]
103
+ Dir[File.join(@workdir, template)]
104
+ }.map { |path| File.expand_path(path) } - [File.expand_path(config_file)]
97
105
  end
98
106
 
99
107
  def dashboards
@@ -312,6 +320,13 @@ module GrafanaRb
312
320
  check_config_existance
313
321
  die("missed grafana_url variable") unless config["grafana_url"]
314
322
  die("missed prometheus_url variable") unless config["prometheus_url"]
323
+
324
+ tool_version = config["version"] || GrafanaRb::VERSION
325
+ if compare_versions(tool_version, GrafanaRb::VERSION) > 0
326
+ puts "FATAL: need at least '#{tool_version}' tool version but current version is '#{GrafanaRb::VERSION}'"
327
+ exit -1
328
+ end
329
+
315
330
  create_or_update_prometheus_datasource
316
331
  create_or_update_slack_notifications if config["slack_url"] && config["slack_channel"]
317
332
  dashboards.each do |dashboard|
@@ -321,12 +336,17 @@ module GrafanaRb
321
336
  puts "done."
322
337
  end
323
338
 
339
+ def compare_versions(a, b)
340
+ parse = proc { |v| v.split(".", 3).map(&:to_i) + [v.index("-dev") ? 1 : 0] }
341
+ parse.call(a) <=> parse.call(b)
342
+ end
343
+
324
344
  def usage
325
345
  puts "Grafana-rb: utility to configure grafana dashboards as a code"
326
346
  puts "Version: #{VERSION}"
327
347
  puts ""
328
348
  puts "Usage:"
329
- puts " grafana-rb <cmd>"
349
+ puts " grafana-rb [work-dir] <cmd>"
330
350
  puts ""
331
351
  puts "Commands:"
332
352
  puts " apply - update dashboards"
@@ -1,3 +1,3 @@
1
1
  module GrafanaRb
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grafana-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Vakhov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler