growthforecast-client 0.62.0 → 0.62.3

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
  SHA1:
3
- metadata.gz: 4e380347aae163347f8aff0e1cfa188113cc3350
4
- data.tar.gz: 4a82887db1bd53783f3132ad1fbf50d86a491296
3
+ metadata.gz: 2aa8e954466d6a600a54404856ea29e0acf5a1cb
4
+ data.tar.gz: 613aef8e40914d64cac2dfba25734435dea1d6d3
5
5
  SHA512:
6
- metadata.gz: 98882b9370b43b92a4ec1045a3f27f8d2c2b0a3a9408e0f0d2f45551d9336e2a98c616509dbf1be1c791dcfba69bc7bea58b20235829753e5bc307b310ae97fd
7
- data.tar.gz: 5217464da3ac661d186abe1e615cdcf16fe5aa1849e4226053bdf572f07a67276182b6359fc04b182645a4058457be7b772017e84f43fa918414043fefc804b3
6
+ metadata.gz: 0c1a97d6d60df53dcae6e2d34954d985799295269148fdc6d8da5e1cc37c6756989741477c41b1b6ef4d2c8b1c9f295d6478f64e9cbe651c5f04e997b860c76e
7
+ data.tar.gz: 36bfaf46fc2fe603f4df520cd1d5b7aee52792212be118c9cd63e48215b9509b3df9e3fa0c9cb997097faabbb7903d86879c17608486fd171b00218f4372495a
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ vendor
10
10
  doc/*
11
11
  tmp/*
12
12
  .yardoc
13
+ pkg
data/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # 0.62.3 (2013/09/20)
2
+
3
+ Features:
4
+
5
+ - Add -g and -s options to `delete` command
6
+
7
+ # 0.62.2 (2013/09/19)
8
+
9
+ Changes:
10
+
11
+ - Change option -u to an argument of `color`, `create_complex` command
12
+
13
+ # 0.62.1 (2013/09/19)
14
+
15
+ Features:
16
+
17
+ - Add `growthforecast-client color` command
18
+ - Add `growthforecast-client create_complex` command
19
+
20
+ Changes:
21
+
22
+ - Change `growthforecast-client delete_graph` to `delete` command
23
+
24
+ # 0.62.0 (2013/07/02)
25
+
26
+ Changes:
27
+
28
+ - Version up!
29
+
1
30
  # 0.0.6 (2013/05/17)
2
31
 
3
32
  Features:
data/README.md CHANGED
@@ -14,6 +14,28 @@ With growthforecast-client, for example, you can edit properties of a graph such
14
14
 
15
15
  See [examples](examples) directory.
16
16
 
17
+ ### CLI
18
+
19
+ GrowthForecast Client also provides a CLI named `growthforecast-client`.
20
+
21
+ Delete a graph or graphs under a path (copy and paste the URL from your GrowthForecast):
22
+
23
+ ```
24
+ $ growthforecast-client delete 'http://fqdn.to.growthforecast:5125/list/service_name'
25
+ ```
26
+
27
+ Change the colors of graphs
28
+
29
+ ```
30
+ $ growthforecast-client color 'http://fqdn.to.growthforecast:5125/list/service_name' -c 'graph_name:#1111cc' ...
31
+ ```
32
+
33
+ See help for more:
34
+
35
+ ```
36
+ $ growthforecast-client help
37
+ ```
38
+
17
39
  ## Contributing
18
40
 
19
41
  1. Fork it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.62.0
1
+ 0.62.3
@@ -2,49 +2,140 @@
2
2
  require 'thor'
3
3
 
4
4
  class GrowthForecast::CLI < Thor
5
- desc 'delete_graph <url>', 'delete a graph or graphs under a url'
5
+ class_option :silent, :aliases => ["-S"], :type => :boolean
6
+
7
+ def initialize(args = [], opts = [], config = {})
8
+ super(args, opts, config)
9
+ end
10
+
11
+ desc 'delete <url>', 'delete a graph or graphs under a url'
6
12
  long_desc <<-LONGDESC
7
- Delete a graph or graphs under a <url> where <url> is the one obtained from the view, e.g.,
13
+ Delete a graph or graphs under a <url> where <url> is the one obtained from the GrowthForecast URI, e.g.,
8
14
  http://{hostname}:{port}/list/{service_name}/{section_name}?t=sh
9
15
  or
10
16
  http://{hostname}:{port}/view_graph/{service_name}/{section_name}/{graph_name}?t=sh
17
+
18
+ ex) growthforecast-client delete 'http://{hostname}:{port}/list/{service_name}/{section_name}'
11
19
  LONGDESC
12
- def delete_graph(url)
13
- uri = URI.parse(url)
14
- client = client(uri)
15
- service_name, section_name, graph_name = split_path(uri.path)
16
- graphs = client.list_graph(service_name, section_name, graph_name)
17
- graphs.each do |graph|
18
- begin
19
- client.delete_graph(graph['service_name'], graph['section_name'], graph['graph_name'])
20
- puts "Deleted #{e graph['service_name']}/#{e graph['section_name']}/#{e graph['graph_name']}"
21
- rescue => e
22
- puts "\tclass:#{e.class}\t#{e.message}"
20
+ option :graph_names, :type => :array, :aliases => '-g'
21
+ option :section_names, :type => :array, :aliases => '-s'
22
+ def delete(url)
23
+ section_names, graph_names = options[:section_names], options[:graph_names]
24
+
25
+ base_uri, service_name, section_name, graph_name = split_url(url)
26
+ @client = client(base_uri)
27
+
28
+ graphs = @client.list_graph(service_name, section_name, graph_name)
29
+ delete_graphs(graphs, graph_names, section_names)
30
+
31
+ complexes = @client.list_complex(service_name, section_name, graph_name)
32
+ delete_complexes(complexes, graph_names, section_names)
33
+ end
34
+
35
+ desc 'color <url>', 'change the color of graphs'
36
+ long_desc <<-LONGDESC
37
+ Change the color of graphs
38
+
39
+ ex) growthforecast-client color 'http://{hostname}:{port}/list/{service_name}/{section_name}' -c '2xx_count:#1111cc' '3xx_count:#11cc11'
40
+ LONGDESC
41
+ option :colors, :type => :hash, :aliases => '-c', :required => true, :banner => 'GRAPH_NAME:COLOR ...'
42
+ def color(url)
43
+ colors = options[:colors]
44
+
45
+ base_uri, service_name, section_name, graph_name = split_url(url)
46
+ @client = client(base_uri)
47
+
48
+ graphs = @client.list_graph(service_name, section_name, graph_name)
49
+ setup_colors(colors, graphs)
50
+ end
51
+
52
+ desc 'create_complex <url>', 'create complex graphs'
53
+ long_desc <<-LONGDESC
54
+ Create complex graphs under a url
55
+
56
+ ex) growthforecast-client create_complex 'http://{hostname}:{port}/list/{service_name}' -f 2xx_count 3xx_count -t status_count
57
+ LONGDESC
58
+ option :from_graphs, :type => :array, :aliases => '-f', :required => true, :banner => 'GRAPH_NAMES ...'
59
+ option :to_complex, :type => :string, :aliases => '-t', :required => true
60
+ def create_complex(url)
61
+ from_graphs, to_complex = options[:from_graphs], options[:to_complex]
62
+ base_uri, service_name, section_name, graph_name = split_url(url)
63
+ @client = client(base_uri)
64
+
65
+ graphs = @client.list_graph(service_name, section_name, graph_name)
66
+ setup_complex(from_graphs, to_complex, graphs)
67
+ end
68
+
69
+ no_tasks do
70
+ def delete_graphs(graphs, graph_names = nil, section_names = nil)
71
+ graphs.each do |graph|
72
+ service_name, section_name, graph_name = graph['service_name'], graph['section_name'], graph['graph_name']
73
+ next if section_names and !section_names.include?(section_name)
74
+ next if graph_names and !graph_names.include?(graph_name)
75
+
76
+ puts "Delete #{service_name}/#{section_name}/#{graph_name}" unless @options[:silent]
77
+ exec { @client.delete_graph(service_name, section_name, graph_name) }
78
+ end
79
+ end
80
+
81
+ def delete_complexes(complexes, graph_names = nil, section_names = nil)
82
+ complexes.each do |graph|
83
+ service_name, section_name, graph_name = graph['service_name'], graph['section_name'], graph['graph_name']
84
+ next if section_names and !section_names.include?(section_name)
85
+ next if graph_names and !graph_names.include?(graph_name)
86
+
87
+ puts "Delete #{service_name}/#{section_name}/#{graph_name}" unless @options[:silent]
88
+ exec { @client.delete_complex(service_name, section_name, graph_name) }
89
+ end
90
+ end
91
+
92
+ def setup_colors(colors, graphs)
93
+ graphs.each do |graph|
94
+ service_name, section_name, graph_name = graph['service_name'], graph['section_name'], graph['graph_name']
95
+ next unless color = colors[graph_name]
96
+
97
+ params = { 'color' => color }
98
+ puts "Setup #{service_name}/#{section_name}/#{graph_name} with #{color}" unless @options[:silent]
99
+ exec { @client.edit_graph(service_name, section_name, graph_name, params) }
23
100
  end
24
101
  end
25
- graphs = client.list_complex(service_name, section_name, graph_name)
26
- graphs.each do |graph|
102
+
103
+ def setup_complex(from_graphs, to_complex, graphs)
104
+ from_graph_first = from_graphs.first
105
+ graphs.each do |graph|
106
+ service_name, section_name, graph_name = graph['service_name'], graph['section_name'], graph['graph_name']
107
+ next unless graph_name == from_graph_first
108
+
109
+ base = { "service_name" => service_name, "section_name" => section_name, "gmode" => 'gauge', "stack" => true, "type" => 'AREA' }
110
+ from_graphs_params = from_graphs.map {|graph_name| base.merge('graph_name' => graph_name) }
111
+ to_complex_params = { "service_name" => service_name, "section_name" => section_name, "graph_name" => to_complex, "sort" => 0 }
112
+
113
+ puts "Setup #{service_name}/#{section_name}/#{to_complex} with #{from_graphs}" unless @options[:silent]
114
+ exec { @client.create_complex(from_graphs_params, to_complex_params) }
115
+ end
116
+ end
117
+
118
+ def exec(&blk)
27
119
  begin
28
- client.delete_complex(graph['service_name'], graph['section_name'], graph['graph_name'])
29
- puts "Deleted #{e graph['service_name']}/#{e graph['section_name']}/#{e graph['graph_name']}"
120
+ yield
30
121
  rescue => e
31
- puts "\tclass:#{e.class}\t#{e.message}"
122
+ $stderr.puts "\tclass:#{e.class}\t#{e.message}"
32
123
  end
33
124
  end
34
- end
35
125
 
36
- no_tasks do
37
- def e(str)
38
- CGI.escape(str).gsub('+', '%20') if str
126
+ def client(base_uri)
127
+ GrowthForecast::Client.new(base_uri)
39
128
  end
40
129
 
41
- def split_path(path)
42
- path = path.gsub(/.*list\//, '').gsub(/.*view_graph\//, '')
43
- path.split('/').map {|p| CGI.unescape(p.gsub('%20', '+')) }
130
+ def split_url(url)
131
+ uri = URI.parse(url)
132
+ base_uri = "#{uri.scheme}://#{uri.host}:#{uri.port}"
133
+ [base_uri] + split_path(uri.path)
44
134
  end
45
135
 
46
- def client(uri)
47
- GrowthForecast::Client.new("#{uri.scheme}://#{uri.host}:#{uri.port}")
136
+ def split_path(path)
137
+ path = path.gsub(/.*list\/?/, '').gsub(/.*view_graph\/?/, '')
138
+ path.split('/').map {|p| CGI.unescape(p.gsub('%20', '+')) }
48
139
  end
49
140
  end
50
141
  end
@@ -100,8 +100,8 @@ module GrowthForecast
100
100
  # "section_name2",
101
101
  # ],
102
102
  # }
103
- def list_section
104
- graphs = list_graph
103
+ def list_section(service_name = nil, section_name = nil, graph_name = nil)
104
+ graphs = list_graph(service_name, section_name, graph_name)
105
105
  services = {}
106
106
  graphs.each do |graph|
107
107
  service_name, section_name = graph['service_name'], graph['section_name']
@@ -118,8 +118,8 @@ module GrowthForecast
118
118
  # "service_name1",
119
119
  # "service_name2",
120
120
  # ]
121
- def list_service
122
- graphs = list_graph
121
+ def list_service(service_name = nil, section_name = nil, graph_name = nil)
122
+ graphs = list_graph(service_name, section_name, graph_name)
123
123
  services = {}
124
124
  graphs.each do |graph|
125
125
  service_name = graph['service_name']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growthforecast-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.62.0
4
+ version: 0.62.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-02 00:00:00.000000000 Z
11
+ date: 2013-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.0.2
160
+ rubygems_version: 2.0.3
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: A Ruby Client Library for GrowthForecast API