wavefront-cli 8.5.1 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +4 -4
- data/.github/workflows/test.yml +2 -2
- data/.rubocop.yml +1 -4
- data/HISTORY.md +12 -0
- data/README.md +4 -2
- data/lib/wavefront-cli/base.rb +2 -2
- data/lib/wavefront-cli/commands/base.rb +10 -9
- data/lib/wavefront-cli/commands/derivedmetric.rb +1 -1
- data/lib/wavefront-cli/commands/metric.rb +3 -3
- data/lib/wavefront-cli/commands/metricspolicy.rb +33 -0
- data/lib/wavefront-cli/commands/query.rb +5 -5
- data/lib/wavefront-cli/commands/write.rb +12 -12
- data/lib/wavefront-cli/config.rb +4 -4
- data/lib/wavefront-cli/constants.rb +2 -1
- data/lib/wavefront-cli/controller.rb +19 -15
- data/lib/wavefront-cli/display/metricspolicy.rb +15 -0
- data/lib/wavefront-cli/display/printer/long.rb +11 -13
- data/lib/wavefront-cli/display/printer/sparkline.rb +3 -3
- data/lib/wavefront-cli/display/query.rb +1 -1
- data/lib/wavefront-cli/display/write.rb +2 -1
- data/lib/wavefront-cli/event.rb +2 -2
- data/lib/wavefront-cli/exception_handler.rb +4 -1
- data/lib/wavefront-cli/helpers/load_file.rb +2 -2
- data/lib/wavefront-cli/maintenancewindow.rb +1 -1
- data/lib/wavefront-cli/metricspolicy.rb +42 -0
- data/lib/wavefront-cli/opt_handler.rb +2 -3
- data/lib/wavefront-cli/output/csv/query.rb +2 -2
- data/lib/wavefront-cli/output/hcl/dashboard.rb +6 -6
- data/lib/wavefront-cli/output/hcl/stdlib/array.rb +1 -1
- data/lib/wavefront-cli/output/wavefront/query.rb +7 -7
- data/lib/wavefront-cli/stdlib/string.rb +4 -4
- data/lib/wavefront-cli/usage.rb +1 -1
- data/lib/wavefront-cli/version.rb +1 -1
- data/lib/wavefront-cli/write.rb +13 -17
- data/spec/constants.rb +4 -5
- data/spec/support/command_base.rb +12 -0
- data/spec/support/minitest_assertions.rb +14 -10
- data/spec/support/output_tester.rb +2 -2
- data/spec/support/supported_commands.rb +3 -1
- data/spec/test_mixins/import.rb +2 -2
- data/spec/test_mixins/search.rb +9 -7
- data/spec/test_mixins/set.rb +1 -1
- data/spec/wavefront-cli/account_spec.rb +6 -4
- data/spec/wavefront-cli/alert_spec.rb +29 -6
- data/spec/wavefront-cli/commands/base_spec.rb +2 -2
- data/spec/wavefront-cli/commands/config_spec.rb +2 -2
- data/spec/wavefront-cli/config_spec.rb +3 -3
- data/spec/wavefront-cli/controller_spec.rb +2 -0
- data/spec/wavefront-cli/dashboard_spec.rb +1 -1
- data/spec/wavefront-cli/derivedmetric_spec.rb +9 -7
- data/spec/wavefront-cli/display/printer/long_spec.rb +5 -3
- data/spec/wavefront-cli/display/printer/terse_spec.rb +1 -1
- data/spec/wavefront-cli/event_spec.rb +14 -11
- data/spec/wavefront-cli/event_store_spec.rb +16 -12
- data/spec/wavefront-cli/externallink_spec.rb +5 -3
- data/spec/wavefront-cli/maintenancewindow_spec.rb +25 -19
- data/spec/wavefront-cli/message_spec.rb +3 -3
- data/spec/wavefront-cli/metricspolicy_spec.rb +30 -0
- data/spec/wavefront-cli/opt_handler_spec.rb +1 -1
- data/spec/wavefront-cli/output/helpers.rb +1 -1
- data/spec/wavefront-cli/proxy_spec.rb +1 -1
- data/spec/wavefront-cli/query_spec.rb +1 -1
- data/spec/wavefront-cli/role_spec.rb +4 -3
- data/spec/wavefront-cli/serviceaccount_spec.rb +7 -5
- data/spec/wavefront-cli/stdlib/string_spec.rb +3 -1
- data/spec/wavefront-cli/usage_spec.rb +1 -1
- data/spec/wavefront-cli/{write_spec.rb → write_class_spec.rb} +1 -14
- data/wavefront-cli.gemspec +13 -15
- metadata +32 -149
- data/spec/spec_helper.rb +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1040d65b6cf4352d960ff941f05f3bd5e924a4ebc13d1a0cff48c8920f1b426a
|
4
|
+
data.tar.gz: 841d25680790e0c8cf8623d09fc6bc6720c725f7b415f7342263d9e66501eb02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 120360b39776bd3711df4bd455cc4785d880447fc33c625ce5b30d9a69f29f51717f5133be78af65657f424d31188fc69afe8183d72cf8d88717cd20825922aa
|
7
|
+
data.tar.gz: 452d2d4e951dfeb02ca1a104fab5401feaaf8a9f3c7b1e649afb3eaebe3e5307f47fb0273cefc947de0e0fd655c761eee0e25bea5289279b7132458f071f6cf6
|
@@ -11,14 +11,14 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v3
|
15
15
|
- name: Set env
|
16
16
|
run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
|
17
17
|
|
18
|
-
- name: Set up Ruby
|
18
|
+
- name: Set up Ruby 3.0
|
19
19
|
uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
|
-
ruby-version:
|
21
|
+
ruby-version: 3.0
|
22
22
|
- run: bundle install
|
23
23
|
|
24
24
|
- name: Run tests
|
@@ -34,4 +34,4 @@ jobs:
|
|
34
34
|
chmod 0600 ${HOME}/.gem/credentials
|
35
35
|
gem push pkg/*.gem
|
36
36
|
env:
|
37
|
-
GEM_HOST_API_KEY: "${{secrets.
|
37
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_PUSH_KEY}}"
|
data/.github/workflows/test.yml
CHANGED
@@ -9,9 +9,9 @@ jobs:
|
|
9
9
|
runs-on: ubuntu-latest
|
10
10
|
strategy:
|
11
11
|
matrix:
|
12
|
-
ruby-version: [2.
|
12
|
+
ruby-version: [2.7.7, 3.1.3, 3.2.0]
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v3
|
15
15
|
- name: Set up Ruby
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
---
|
2
2
|
AllCops:
|
3
|
-
TargetRubyVersion: 2.
|
3
|
+
TargetRubyVersion: 2.7
|
4
4
|
NewCops: enable
|
5
5
|
|
6
6
|
require:
|
7
7
|
- rubocop-rake
|
8
8
|
- rubocop-minitest
|
9
9
|
- rubocop-performance
|
10
|
-
- rubocop-performance
|
11
10
|
|
12
11
|
Layout/LineLength:
|
13
12
|
Max: 80 # Is nothing sacred?
|
@@ -17,7 +16,5 @@ Naming/VariableNumber:
|
|
17
16
|
Enabled: false
|
18
17
|
Style/IfUnlessModifier:
|
19
18
|
Enabled: false # because it wants to make lines >80 chars
|
20
|
-
Style/StringConcatenation:
|
21
|
-
Enabled: false
|
22
19
|
Style/OptionalBooleanParameter:
|
23
20
|
Enabled: false
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 9.0.0 (2023-01-20)
|
4
|
+
|
5
|
+
* Drop support for Ruby 2.5. (Breaking change.)
|
6
|
+
* Drop support for Ruby 2.6. (Breaking change.)
|
7
|
+
* Add `metricspolicy` command.
|
8
|
+
* `wf write` has changed. Tokens and API endpoints are now specified exactly
|
9
|
+
like other commands. This means certain options had to change. A proxy is
|
10
|
+
now specified with `-y` instead of `-E`; A timestamp is given with `-s`, not
|
11
|
+
`-t`. (Breaking change.)
|
12
|
+
* Unless told otherwise, `wf write` will write to a proxy over HTTP, rather
|
13
|
+
than over a socket. (Breaking change.)
|
14
|
+
|
3
15
|
## 8.5.1 (2021-01-28)
|
4
16
|
* Fix stack trace when specifying an invalid time such as `Sunday`.
|
5
17
|
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Wavefront CLI
|
2
|
-
[![
|
2
|
+
[![Test](https://github.com/snltd/wavefront-cli/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/snltd/wavefront-cli/actions/workflows/test.yml) ![Release](https://github.com/snltd/wavefront-sdk/workflows/Release/badge.svg) [![Maintainability](https://api.codeclimate.com/v1/badges/9b712047af0b2dafc146/maintainability)](https://codeclimate.com/github/snltd/wavefront-cli/maintainability) [![Gem Version](https://badge.fury.io/rb/wavefront-cli.svg)](https://badge.fury.io/rb/wavefront-cli) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-cli?type=total)
|
3
3
|
|
4
4
|
This is a complete command-line interface to
|
5
5
|
[Wavefront](https://www.wavefront.com/)'s API. It also provides easy
|
@@ -15,7 +15,7 @@ $ gem install wavefront-cli
|
|
15
15
|
|
16
16
|
It is built on [our Wavefront Ruby
|
17
17
|
SDK](https://github.com/snltd/wavefront-sdk) and requires Ruby >=
|
18
|
-
2.
|
18
|
+
2.7. It has no "native extension" dependencies.
|
19
19
|
|
20
20
|
For a far more comprehensive overview/tutorial, please read [this
|
21
21
|
article](https://sysdef.xyz/article/wavefront-cli).
|
@@ -30,6 +30,7 @@ Usage:
|
|
30
30
|
wf --help
|
31
31
|
|
32
32
|
Commands:
|
33
|
+
account view and manage Wavefront accounts
|
33
34
|
alert view and manage alerts
|
34
35
|
apitoken view and your own API tokens
|
35
36
|
cloudintegration view and manage cloud integrations
|
@@ -45,6 +46,7 @@ Commands:
|
|
45
46
|
notificant view and manage Wavefront alert targets
|
46
47
|
proxy view and manage proxies
|
47
48
|
query run Wavefront queries
|
49
|
+
role view and manage roles
|
48
50
|
savedsearch view and manage saved searches
|
49
51
|
serviceaccount view and manage service accounts
|
50
52
|
settings view and manage system preferences
|
data/lib/wavefront-cli/base.rb
CHANGED
@@ -206,7 +206,7 @@ module WavefrontCli
|
|
206
206
|
#
|
207
207
|
def method_word_list
|
208
208
|
do_methods = methods.select { |m| m.to_s.start_with?('do_') }
|
209
|
-
do_methods.map { |m| m.to_s.split('_')[1
|
209
|
+
do_methods.map { |m| m.to_s.split('_')[1..] }.sort_by(&:length)
|
210
210
|
end
|
211
211
|
|
212
212
|
# Display a Ruby object as JSON, YAML, or human-readable. We
|
@@ -545,7 +545,7 @@ module WavefrontCli
|
|
545
545
|
when Hash
|
546
546
|
obj.each_pair do |k, v|
|
547
547
|
if k == key && !v.to_s.empty?
|
548
|
-
aggr
|
548
|
+
aggr << v
|
549
549
|
else
|
550
550
|
extract_values(v, key, aggr)
|
551
551
|
end
|
@@ -29,7 +29,7 @@ class WavefrontCommandBase
|
|
29
29
|
# @return [Array]
|
30
30
|
#
|
31
31
|
def common_options
|
32
|
-
['-E, --endpoint=URI cluster endpoint',
|
32
|
+
['-E, --endpoint=URI Wavefront cluster endpoint',
|
33
33
|
'-t, --token=TOKEN Wavefront authentication token']
|
34
34
|
end
|
35
35
|
|
@@ -80,7 +80,7 @@ class WavefrontCommandBase
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def things
|
83
|
-
thing
|
83
|
+
"#{thing}s"
|
84
84
|
end
|
85
85
|
|
86
86
|
# @return [String] the name of the SDK class which does the work
|
@@ -105,10 +105,11 @@ class WavefrontCommandBase
|
|
105
105
|
text_arr = %w[Usage:]
|
106
106
|
|
107
107
|
_commands.flatten.each do |cmd|
|
108
|
-
|
108
|
+
folded = "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width)
|
109
|
+
text_arr << " #{folded}"
|
109
110
|
end
|
110
111
|
|
111
|
-
text_arr
|
112
|
+
text_arr << " #{CMD} #{word} --help"
|
112
113
|
text_arr.join("\n")
|
113
114
|
end
|
114
115
|
|
@@ -124,15 +125,15 @@ class WavefrontCommandBase
|
|
124
125
|
global_option_text(width, term_width)
|
125
126
|
end
|
126
127
|
|
127
|
-
text_arr
|
128
|
-
_options.flatten.each { |o| text_arr
|
128
|
+
text_arr << 'Options:'
|
129
|
+
_options.flatten.each { |o| text_arr << opt_row(o, width, term_width) }
|
129
130
|
text_arr.join("\n")
|
130
131
|
end
|
131
132
|
|
132
133
|
def global_option_text(width, term_width)
|
133
134
|
text_arr = ['Global options:']
|
134
|
-
global_options.each { |o| text_arr
|
135
|
-
text_arr
|
135
|
+
global_options.each { |o| text_arr << opt_row(o, width, term_width) }
|
136
|
+
text_arr << ''
|
136
137
|
end
|
137
138
|
|
138
139
|
# Formats an option string.
|
@@ -165,6 +166,6 @@ class WavefrontCommandBase
|
|
165
166
|
# @return [String] a full options string which docopt understands
|
166
167
|
#
|
167
168
|
def docopt
|
168
|
-
commands
|
169
|
+
"#{commands}\n\n#{options}\n\n#{postscript}"
|
169
170
|
end
|
170
171
|
end
|
@@ -45,7 +45,7 @@ class WavefrontCommandDerivedmetric < WavefrontCommandBase
|
|
45
45
|
'-d, --desc=STRING additional information about query',
|
46
46
|
'-i, --interval=INTEGER execute query every n minutes [default: 1]',
|
47
47
|
'-r, --range=INTEGER include results in the last n minutes ' \
|
48
|
-
|
48
|
+
'[default: 5]',
|
49
49
|
"-u, --update update an existing #{thing}",
|
50
50
|
"-U, --upsert import new or update existing #{thing}"]
|
51
51
|
end
|
@@ -23,8 +23,8 @@ class WavefrontCommandMetric < WavefrontCommandBase
|
|
23
23
|
|
24
24
|
def postscript
|
25
25
|
"\nNOTE: the 'list under' and 'list all' sub-commands use the unoffical " \
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
"'chart' endpoint, which is not guaranteed to remain stable.\n\n" \
|
27
|
+
'Both commands have to make a lot of API calls, and may take a ' \
|
28
|
+
'very long time to run.'.cmd_fold(TW, 0)
|
29
29
|
end
|
30
30
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
# Define the metricspolicy command.
|
6
|
+
#
|
7
|
+
class WavefrontCommandMetricspolicy < WavefrontCommandBase
|
8
|
+
def thing
|
9
|
+
'metrics policy'
|
10
|
+
end
|
11
|
+
|
12
|
+
def things
|
13
|
+
'metrics policies'
|
14
|
+
end
|
15
|
+
|
16
|
+
def sdk_class
|
17
|
+
'MetricsPolicy'
|
18
|
+
end
|
19
|
+
|
20
|
+
def _commands
|
21
|
+
["describe #{CMN} [-v version]",
|
22
|
+
"history #{CMN} [-o offset] [-L limit]",
|
23
|
+
"revert #{CMN} <version>",
|
24
|
+
"update #{CMN} <file>"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def _options
|
28
|
+
[common_options,
|
29
|
+
"-o, --offset=n start from nth #{thing}",
|
30
|
+
"-L, --limit=COUNT number of #{things} or revisions to list",
|
31
|
+
"-v, --version=INTEGER version of #{thing}"]
|
32
|
+
end
|
33
|
+
end
|
@@ -12,11 +12,11 @@ class WavefrontCommandQuery < WavefrontCommandBase
|
|
12
12
|
def _commands
|
13
13
|
['aliases [-DV] [-c file] [-P profile]',
|
14
14
|
"#{CMN} [-g granularity] [-s time] [-e time] " \
|
15
|
-
|
15
|
+
'[-ikvCGKOW] [-S mode] [-N name] [-p points] [-F options] <query>',
|
16
16
|
"raw #{CMN} [-H host] [-s time] [-e time] " \
|
17
|
-
|
17
|
+
'[-F options] <metric>',
|
18
18
|
"run #{CMN} [-g granularity] [-s time] [-e time] " \
|
19
|
-
|
19
|
+
'[-F options] [-WkivO] [-S mode] [-N name] [-p points] <alias>']
|
20
20
|
end
|
21
21
|
|
22
22
|
def _options
|
@@ -34,7 +34,7 @@ class WavefrontCommandQuery < WavefrontCommandBase
|
|
34
34
|
'-O, --obsolete include metrics unreported for > 4 weeks',
|
35
35
|
'-H, --host=STRING host or source to query on',
|
36
36
|
'-F, --format-opts=STRING comma-separated options to pass to ' \
|
37
|
-
|
37
|
+
'output formatter',
|
38
38
|
'-k, --nospark do not show sparkline',
|
39
39
|
'-C, --nocache do not use the query cache',
|
40
40
|
'-K, --nostrict allow points outside the query window',
|
@@ -45,7 +45,7 @@ class WavefrontCommandQuery < WavefrontCommandBase
|
|
45
45
|
def postscript
|
46
46
|
'The query command has an additional output format. Using ' \
|
47
47
|
"'-f wavefront' produces output suitable for feeding back into a " \
|
48
|
-
"proxy. Other output formats are 'yaml', 'json', 'ruby', "\
|
48
|
+
"proxy. Other output formats are 'yaml', 'json', 'ruby', " \
|
49
49
|
"and 'csv'. CSV format options are 'headers' (print column headers); " \
|
50
50
|
"'tagkeys' (print tags as key=value rather than value); and 'quote' " \
|
51
51
|
'(force quoting of every CSV element).'.cmd_fold(TW, 0)
|
@@ -10,24 +10,24 @@ class WavefrontCommandWrite < WavefrontCommandBase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def _commands
|
13
|
-
[
|
13
|
+
["point #{CMN} [-iq] [-y proxy] [-s time] " \
|
14
14
|
'[-p port] [-H host] [-T tag...] [-u method] [-S socket] <metric> ' \
|
15
15
|
'[--] <value>',
|
16
|
-
|
17
|
-
'[-p port] [-T tag...] [-u method] [-S socket] [-I interval] ' \
|
16
|
+
"distribution #{CMN} [-iq] [-y proxy] " \
|
17
|
+
'[-H host] [-p port] [-T tag...] [-u method] [-S socket] [-I interval] ' \
|
18
18
|
'<metric> [--] <val>...',
|
19
|
-
|
19
|
+
"file #{CMN} [-iq] [-y proxy] [-H host] " \
|
20
20
|
'[-p port] [-F infileformat] [-m metric] [-T tag...] [-I interval] ' \
|
21
21
|
'[-u method] [-S socket] <file>',
|
22
|
-
|
22
|
+
"noise #{CMN} [-iq] [-y proxy] [-H host] [-p port] " \
|
23
23
|
'[-T tag...] [-I interval] [-x value] [-X value] <metric>']
|
24
24
|
end
|
25
25
|
|
26
26
|
def _options
|
27
|
-
[
|
28
|
-
'-
|
29
|
-
'
|
30
|
-
'-H, --host=STRING source host',
|
27
|
+
[common_options,
|
28
|
+
'-y, --proxy=URI proxy endpoint',
|
29
|
+
'-s, --ts=TIME timestamp of data point (omit for "now")',
|
30
|
+
'-H, --host=STRING source host',
|
31
31
|
'-p, --port=INT Wavefront proxy port',
|
32
32
|
'-T, --tag=TAG point tag in key=value form',
|
33
33
|
'-F, --infileformat=STRING format of input file or stdin',
|
@@ -50,9 +50,9 @@ class WavefrontCommandWrite < WavefrontCommandBase
|
|
50
50
|
"with the '-F' option. Use 't' for timestamp, 'm' for metric " \
|
51
51
|
"name, 'v' for value, 's' for source, 'd' for a comma-separated " \
|
52
52
|
"distribution, and 'T' for tags. Put 'T' last. Currently " \
|
53
|
-
"supported transport methods are '
|
54
|
-
"default); 'api' (write directly to Wavefront); '
|
55
|
-
"a proxy
|
53
|
+
"supported transport methods are 'http' (write to a proxy over HTTP: " \
|
54
|
+
"the default); 'api' (write directly to Wavefront); 'proxy' (send raw " \
|
55
|
+
"data to a proxy); and 'socket' (write to a local Unix socket)."
|
56
56
|
.cmd_fold(TW, 0)
|
57
57
|
end
|
58
58
|
end
|
data/lib/wavefront-cli/config.rb
CHANGED
@@ -54,7 +54,7 @@ module WavefrontCli
|
|
54
54
|
|
55
55
|
def do_show
|
56
56
|
present?
|
57
|
-
puts
|
57
|
+
puts File.read(config_file)
|
58
58
|
end
|
59
59
|
|
60
60
|
def do_about
|
@@ -97,7 +97,7 @@ module WavefrontCli
|
|
97
97
|
prof_arr = ["[#{profile}]"]
|
98
98
|
|
99
99
|
CONFIGURABLES.each do |c|
|
100
|
-
prof_arr
|
100
|
+
prof_arr << format('%<key>s=%<value>s',
|
101
101
|
key: c[:key],
|
102
102
|
value: read_thing(c))
|
103
103
|
end
|
@@ -138,8 +138,8 @@ module WavefrontCli
|
|
138
138
|
|
139
139
|
def input_prompt(label, default)
|
140
140
|
ret = format(' %<label>s', label: label)
|
141
|
-
ret
|
142
|
-
ret
|
141
|
+
ret << format(' [%<value>s]', value: default) unless default.nil?
|
142
|
+
"#{ret}:> "
|
143
143
|
end
|
144
144
|
|
145
145
|
# Read STDIN and strip the whitespace. The rescue is there to
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
5
|
module WavefrontCli
|
6
|
+
#
|
6
7
|
# Universal truths
|
7
8
|
#
|
8
9
|
module Constants
|
@@ -24,7 +25,7 @@ module WavefrontCli
|
|
24
25
|
|
25
26
|
# Default configuration file
|
26
27
|
#
|
27
|
-
DEFAULT_CONFIG =
|
28
|
+
DEFAULT_CONFIG = Pathname.new(Dir.home).join('.wavefront').freeze
|
28
29
|
|
29
30
|
# Split regex for searches
|
30
31
|
#
|
@@ -7,8 +7,8 @@
|
|
7
7
|
|
8
8
|
if defined?(DEVELOPMENT)
|
9
9
|
dir = Pathname.new(__dir__).realpath.parent.parent.parent
|
10
|
-
$LOAD_PATH
|
11
|
-
$LOAD_PATH
|
10
|
+
$LOAD_PATH << dir.join('lib')
|
11
|
+
$LOAD_PATH << dir.join('wavefront-sdk', 'lib')
|
12
12
|
end
|
13
13
|
|
14
14
|
require 'pathname'
|
@@ -20,7 +20,7 @@ require_relative 'opt_handler'
|
|
20
20
|
require_relative 'exception_handler'
|
21
21
|
require_relative 'stdlib/string'
|
22
22
|
|
23
|
-
CMD_DIR = Pathname.new(__dir__)
|
23
|
+
CMD_DIR = Pathname.new(__dir__).join('commands')
|
24
24
|
|
25
25
|
# Dynamically generate a CLI interface from files which describe
|
26
26
|
# each subcomand.
|
@@ -65,13 +65,13 @@ class WavefrontCliController
|
|
65
65
|
'Commands:']
|
66
66
|
|
67
67
|
cmds.sort.each do |k, v|
|
68
|
-
s
|
68
|
+
s << format(' %-18<command>s %<desc>s',
|
69
69
|
command: k,
|
70
70
|
desc: v.description)
|
71
71
|
end
|
72
72
|
|
73
|
-
s
|
74
|
-
s
|
73
|
+
s << ''
|
74
|
+
s << "Use '#{CMD} <command> --help' for further information."
|
75
75
|
s.join("\n")
|
76
76
|
end
|
77
77
|
# rubocop:enable Metrics/MethodLength
|
@@ -124,7 +124,7 @@ class WavefrontCliController
|
|
124
124
|
|
125
125
|
def load_cli_class(cmd, opts)
|
126
126
|
require_relative File.join('.', cmds[cmd].sdk_file)
|
127
|
-
Object.const_get(
|
127
|
+
Object.const_get(:WavefrontCli).const_get(cmds[cmd].sdk_class).new(opts)
|
128
128
|
end
|
129
129
|
|
130
130
|
def run_command(cli_class_obj)
|
@@ -145,15 +145,19 @@ class WavefrontCliController
|
|
145
145
|
# @param error [WavefrontCli::Exception::CredentialError]
|
146
146
|
#
|
147
147
|
def handle_missing_credentials(error)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
148
|
+
message = error.message.capitalize
|
149
|
+
message << ('.') unless message.end_with?('.')
|
150
|
+
|
151
|
+
puts "Credential error. #{message}"
|
152
|
+
|
153
|
+
unless DEFAULT_CONFIG.exist? && DEFAULT_CONFIG.file?
|
154
|
+
puts
|
155
|
+
puts 'You can pass credentials on the command line or via ' \
|
156
|
+
"environment variables. You may also run 'wf config setup' to " \
|
157
|
+
'create a config file.'.fold(TW, 0)
|
156
158
|
end
|
159
|
+
|
160
|
+
exit 1
|
157
161
|
end
|
158
162
|
|
159
163
|
# Each command is defined in its own file. Dynamically load all
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
module WavefrontDisplay
|
6
|
+
#
|
7
|
+
# Format human-readable output of the metrics policy.
|
8
|
+
#
|
9
|
+
class MetricsPolicy < Base
|
10
|
+
def do_history
|
11
|
+
readable_time_arr(:updateTime)
|
12
|
+
long_output
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -84,7 +84,7 @@ module WavefrontDisplayPrinter
|
|
84
84
|
elsif data.is_a?(Array)
|
85
85
|
append_array(data, aggr, depth, last_key)
|
86
86
|
else
|
87
|
-
aggr
|
87
|
+
aggr << ['', preened_value(data), depth]
|
88
88
|
end
|
89
89
|
end
|
90
90
|
# rubocop:enable Style/CaseLikeIf
|
@@ -99,16 +99,14 @@ module WavefrontDisplayPrinter
|
|
99
99
|
# @return [Integer]
|
100
100
|
#
|
101
101
|
def longest_key_col(data)
|
102
|
-
data.map { |d| d[0].size + opts[:padding] + opts[:indent] * d[2] }.max
|
102
|
+
data.map { |d| d[0].size + opts[:padding] + (opts[:indent] * d[2]) }.max
|
103
103
|
end
|
104
104
|
|
105
105
|
# Turn the list made by #make_list into user output
|
106
106
|
# @return [String]
|
107
107
|
#
|
108
108
|
def to_s
|
109
|
-
list.map
|
110
|
-
stringify_line(item)
|
111
|
-
end.join("\n")
|
109
|
+
list.map { |item| stringify_line(item) }.join("\n")
|
112
110
|
end
|
113
111
|
|
114
112
|
# @param item [Array] of the form [key, value, indent_level]
|
@@ -162,7 +160,7 @@ module WavefrontDisplayPrinter
|
|
162
160
|
elsif v.is_a?(Array)
|
163
161
|
aggr = append_array_values(k, v, aggr, depth)
|
164
162
|
else
|
165
|
-
aggr
|
163
|
+
aggr << [k, smart_value(v), depth]
|
166
164
|
end
|
167
165
|
end
|
168
166
|
|
@@ -183,7 +181,7 @@ module WavefrontDisplayPrinter
|
|
183
181
|
|
184
182
|
if opts[:separator] && element.is_a?(Hash) && i < data.size &&
|
185
183
|
depth < opts[:sep_depth]
|
186
|
-
aggr
|
184
|
+
aggr << ['', :separator, depth]
|
187
185
|
end
|
188
186
|
end
|
189
187
|
|
@@ -202,9 +200,9 @@ module WavefrontDisplayPrinter
|
|
202
200
|
#
|
203
201
|
def append_hash_values(key, values, aggr, depth)
|
204
202
|
if values.empty? && opts[:none]
|
205
|
-
aggr
|
203
|
+
aggr << [key, '<none>', depth]
|
206
204
|
else
|
207
|
-
aggr
|
205
|
+
aggr << [key, nil, depth]
|
208
206
|
make_list(values, aggr, depth + 1)
|
209
207
|
end
|
210
208
|
end
|
@@ -218,13 +216,13 @@ module WavefrontDisplayPrinter
|
|
218
216
|
#
|
219
217
|
def append_array_values(key, values, aggr, depth)
|
220
218
|
if values.empty? && opts[:none]
|
221
|
-
aggr
|
222
|
-
elsif values.all?
|
219
|
+
aggr << [key, '<none>', depth]
|
220
|
+
elsif values.all?(String)
|
223
221
|
values.sort!
|
224
|
-
aggr
|
222
|
+
aggr << [key, preened_value(values.shift), depth]
|
225
223
|
make_list(values, aggr, depth, key)
|
226
224
|
else
|
227
|
-
aggr
|
225
|
+
aggr << [key, nil, depth]
|
228
226
|
make_list(values, aggr, depth + 1, key)
|
229
227
|
end
|
230
228
|
end
|
@@ -16,7 +16,7 @@ class WavefrontSparkline
|
|
16
16
|
attr_reader :sparkline
|
17
17
|
|
18
18
|
def initialize(series)
|
19
|
-
@sparkline =
|
19
|
+
@sparkline = ">#{generate_sparkline(series)}<"
|
20
20
|
end
|
21
21
|
|
22
22
|
# @return [String] the block corresponding to the given value in
|
@@ -38,8 +38,8 @@ class WavefrontSparkline
|
|
38
38
|
def make_fit(vals)
|
39
39
|
return vals if vals.size < SPARK_WIDTH
|
40
40
|
|
41
|
-
vals
|
42
|
-
ret = vals.each_slice(2).with_object([]) { |s, a| a
|
41
|
+
vals << vals.last if vals.size.odd?
|
42
|
+
ret = vals.each_slice(2).with_object([]) { |s, a| a << (s.sum / 2) }
|
43
43
|
make_fit(ret)
|
44
44
|
end
|
45
45
|
|
data/lib/wavefront-cli/event.rb
CHANGED
@@ -38,7 +38,7 @@ module WavefrontCli
|
|
38
38
|
def do_show
|
39
39
|
events = state.list
|
40
40
|
|
41
|
-
if events.
|
41
|
+
if events.empty?
|
42
42
|
puts 'No open events.'
|
43
43
|
else
|
44
44
|
events.sort.reverse_each { |e| puts e.basename }
|
@@ -94,7 +94,7 @@ module WavefrontCli
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def window_start
|
97
|
-
parse_time((options[:start] || Time.now - 600), true)
|
97
|
+
parse_time((options[:start] || (Time.now - 600)), true)
|
98
98
|
end
|
99
99
|
|
100
100
|
def window_end
|
@@ -19,7 +19,8 @@ module WavefrontCli
|
|
19
19
|
abort "\nOperation aborted at user request."
|
20
20
|
when WavefrontCli::Exception::ConfigFileNotFound
|
21
21
|
abort "Configuration file #{exception}' not found."
|
22
|
-
when WavefrontCli::Exception::CredentialError
|
22
|
+
when WavefrontCli::Exception::CredentialError,
|
23
|
+
Wavefront::Exception::CredentialError
|
23
24
|
handle_missing_credentials(exception)
|
24
25
|
when WavefrontCli::Exception::MandatoryValue
|
25
26
|
abort 'A value must be supplied.'
|
@@ -41,6 +42,8 @@ module WavefrontCli
|
|
41
42
|
abort "'#{exception}' is not a valid API token ID."
|
42
43
|
when Wavefront::Exception::InvalidIngestionPolicyId
|
43
44
|
abort "'#{exception}' is not a valid ingestion policy ID."
|
45
|
+
when Wavefront::Exception::InvalidVersion
|
46
|
+
abort "'#{exception}' is not a valid version."
|
44
47
|
when WavefrontCli::Exception::InvalidValue
|
45
48
|
abort "Invalid value for #{exception}."
|
46
49
|
when WavefrontCli::Exception::ProfileExists
|
@@ -40,11 +40,11 @@ module WavefrontCli
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def load_json(file)
|
43
|
-
read_json(
|
43
|
+
read_json(File.read(file))
|
44
44
|
end
|
45
45
|
|
46
46
|
def load_yaml(file)
|
47
|
-
read_yaml(
|
47
|
+
read_yaml(File.read(file))
|
48
48
|
end
|
49
49
|
|
50
50
|
# Read STDIN and return a Ruby object, assuming that STDIN is
|