wavefront-cli 2.2.0 → 2.3.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
  SHA256:
3
- metadata.gz: f672ae4ac7f81edd35c18b5ceff7a187b2e2450cf31ec4b8551de2b3c2f5521f
4
- data.tar.gz: 4c6d64235013f1a56c92f129347d9e006d72c213f51eabc66cc2055aa7497dcb
3
+ metadata.gz: d72f979bcf612478ecbde4f9b0ac5e6a5e3bb0be3cf756b80a23f5c75d25a3bd
4
+ data.tar.gz: deec46d8e93bec91ec04ce09cad50fcf69930257bc1655ab60b4e011b3cff08b
5
5
  SHA512:
6
- metadata.gz: 8b6e35748122d99bcef965a0f86224679537b0b23b7175ac822255c5ee6321c42938c12eba5a1aca2bbe4dd256435c61525558fed3155dbe6eb70b1e5d3d9255
7
- data.tar.gz: db39b5d27705c1d5d4a7f8431e306c0f137ef55322ca8bb958895b0ee0b2331f53d1a7d69fce50c5042de2faf8a9d247cb757277139c8bcd6f4c0ddb2388d6c2
6
+ metadata.gz: 14517c7aaf32a9f6c16c30cc797ed6d4901e9501f31535f60e7b893e526d2e6368c5aa358dabcd7707bebd8e957429774cc316c085eca1620934bcbc4e8e49c6
7
+ data.tar.gz: 1b935a46c79c0ad620364e03e9c7213267498d4733f91b0eb906af861240a6bd871e1089d4d52e6600824ffc700fe9f5e2e630399c78af31a250a22b1d5d0a9c
@@ -37,6 +37,18 @@ module WavefrontCli
37
37
  send(:post_initialize, options) if respond_to?(:post_initialize)
38
38
  end
39
39
 
40
+ # Some subcommands don't make an API call, so they don't return
41
+ # a Wavefront::Response object. You can override this method
42
+ # with something which returns an array of methods like that.
43
+ # They will bypass the usual response checking.
44
+ #
45
+ # @return [Array[String]] methods which do not include an API
46
+ # response
47
+ #
48
+ def no_api_response
49
+ []
50
+ end
51
+
40
52
  def options_and_exit
41
53
  puts options
42
54
  exit 0
@@ -47,9 +59,9 @@ module WavefrontCli
47
59
  dispatch
48
60
  end
49
61
 
50
- # We normally validate with a predictable method name. Alert IDs are
51
- # validated with #wf_alert_id? etc. If you need to change that, override
52
- # this method.
62
+ # We normally validate with a predictable method name. Alert IDs
63
+ # are validated with #wf_alert_id? etc. If you need to change
64
+ # that, override this method.
53
65
  #
54
66
  def validator_method
55
67
  "wf_#{klass_word}_id?".to_sym
@@ -169,6 +181,10 @@ module WavefrontCli
169
181
  # this output. Used to find a suitable humanize method.
170
182
  #
171
183
  def display(data, method)
184
+ if no_api_response.include?(method)
185
+ return display_no_api_response(data, method)
186
+ end
187
+
172
188
  exit if options[:noop]
173
189
 
174
190
  %i[status response].each do |b|
@@ -183,6 +199,10 @@ module WavefrontCli
183
199
  handle_response(data.response, format_var, method)
184
200
  end
185
201
 
202
+ def display_no_api_response(data, method)
203
+ handle_response(data, format_var, method)
204
+ end
205
+
186
206
  def check_status(status)
187
207
  status.respond_to?(:result) && status.result == 'OK'
188
208
  end
@@ -8,10 +8,14 @@ class WavefrontCommandQuery < WavefrontCommandBase
8
8
  end
9
9
 
10
10
  def _commands
11
- ["#{CMN} [-g granularity] [-s time] [-e time] [-f format] " \
11
+ ['aliases [-DV] [-c file] [-P profile]',
12
+ "#{CMN} [-g granularity] [-s time] [-e time] [-f format] " \
12
13
  '[-ivO] [-S mode] [-N name] [-p points] <query>',
13
- "raw #{CMN} [-H host] [-s time] [-e time] [-f format] <metric>"]
14
+ "raw #{CMN} [-H host] [-s time] [-e time] [-f format] <metric>",
15
+ "run #{CMN} [-g granularity] [-s time] [-e time] [-f format] " \
16
+ '[-ivO] [-S mode] [-N name] [-p points] <alias>']
14
17
  end
18
+
15
19
  def _options
16
20
  [common_options,
17
21
  '-g, --granularity=STRING query granularity (d, h, m, or s)',
@@ -20,17 +20,19 @@ module WavefrontDisplay
20
20
  []
21
21
  end
22
22
 
23
- new = {
24
- name: data.name,
25
- query: data.query,
26
- timeseries: ts,
27
- events: events
28
- }
23
+ new = { name: data.name,
24
+ query: data.query,
25
+ timeseries: ts,
26
+ events: events }
29
27
 
30
28
  @data = new
31
29
  long_output
32
30
  end
33
31
 
32
+ def do_run
33
+ do_default
34
+ end
35
+
34
36
  def do_raw
35
37
  data.each { |ts| puts humanize_series(ts[:points]).join("\n") }
36
38
  end
@@ -39,6 +41,16 @@ module WavefrontDisplay
39
41
  puts 'API 404: metric does not exist.'
40
42
  end
41
43
 
44
+ def do_aliases
45
+ if data.empty?
46
+ puts 'No aliases defined.'
47
+ else
48
+ data.each { |k, _v| puts k.to_s[2..-1] }
49
+ end
50
+ end
51
+
52
+ private
53
+
42
54
  def humanize_event(data)
43
55
  data[:start] = human_time(data[:start])
44
56
  data[:end] = human_time(data[:end]) if data[:end]
@@ -6,17 +6,49 @@ module WavefrontCli
6
6
  # CLI coverage for the v2 'query' API.
7
7
  #
8
8
  class Query < WavefrontCli::Base
9
+ attr_reader :query_string
10
+
9
11
  include Wavefront::Mixins
10
12
 
13
+ def no_api_response
14
+ %w[do_aliases]
15
+ end
16
+
11
17
  def do_default
18
+ qs = query_string || options[:'<query>']
19
+
12
20
  t_start = window_start
13
21
  t_end = window_end
14
22
  granularity = granularity(t_start, t_end)
15
23
  t_end = nil unless options[:end]
16
24
 
17
- wf.query(options[:'<query>'], granularity, t_start, t_end, q_opts)
25
+ wf.query(qs, granularity, t_start, t_end, q_opts)
26
+ end
27
+
28
+ def do_raw
29
+ wf.raw(options[:'<metric>'], options[:host], options[:start],
30
+ options[:end])
31
+ end
32
+
33
+ def do_run
34
+ alias_key = format('q_%s', options[:'<alias>']).to_sym
35
+ query = all_aliases.fetch(alias_key, nil)
36
+
37
+ unless query
38
+ abort "Query not found. 'wf query aliases' will show all " \
39
+ 'aliased queries.'
40
+ end
41
+
42
+ @query_string = query
43
+ do_default
18
44
  end
19
45
 
46
+ def do_aliases
47
+ all_aliases
48
+ end
49
+
50
+ private
51
+
20
52
  # @return [Hash] options for the SDK query method
21
53
  #
22
54
  def q_opts
@@ -82,9 +114,12 @@ module WavefrontCli
82
114
  end
83
115
  end
84
116
 
85
- def do_raw
86
- wf.raw(options[:'<metric>'], options[:host], options[:start],
87
- options[:end])
117
+ # @return [Hash] all query aliases for the active profile
118
+ #
119
+ def all_aliases
120
+ WavefrontCli::OptHandler.new(options).opts.select do |line|
121
+ line.to_s.start_with?('q_')
122
+ end
88
123
  end
89
124
  end
90
125
  end
@@ -1 +1 @@
1
- WF_CLI_VERSION = '2.2.0'.freeze
1
+ WF_CLI_VERSION = '2.3.0'.freeze
@@ -12,5 +12,6 @@ class WavefrontCommmandQueryTest < WavefrontCommmandBaseTest
12
12
  def setup
13
13
  @wf = WavefrontCommandQuery.new
14
14
  @col_width = 24
15
+ @skip_cmd = /aliases/
15
16
  end
16
17
  end
@@ -1,2 +1,3 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/spec'
3
+ require_relative '../../spec_helper'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-19 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt