wavefront-cli 1.0.1 → 1.0.2
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 +4 -4
- data/README.md +13 -1
- data/lib/wavefront-cli/commands/event.rb +2 -2
- data/lib/wavefront-cli/commands/window.rb +10 -0
- data/lib/wavefront-cli/controller.rb +2 -2
- data/lib/wavefront-cli/maintenancewindow.rb +53 -0
- data/lib/wavefront-cli/string.rb +25 -0
- data/lib/wavefront-cli/version.rb +1 -1
- data/spec/wavefront-cli/maintanancewindow_spec.rb +9 -1
- data/spec/wavefront-cli/string_spec.rb +9 -14
- data/wavefront-cli.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5fe5e6006694e0e3683bcc58dbb55e1ad703ff8
|
4
|
+
data.tar.gz: 96154590a344297b93be93b7e3cad81f42ffbb4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 981838fe6e017bd0bb1d1c14612ef2cec3ff746bcceb90cbac243c9b245aeb02010f76eadb6aac1d75b2c4e3945186c771e49f1a52465948e161dea62c7aa3ab
|
7
|
+
data.tar.gz: b760924a3672f4e1ff8b909940feb2d13cd9003d83a1be7188e2330d71ada5b134af80e9ae4e5abae3817023d40ab37da27bf351e9287592ad04b2c65dff8811
|
data/README.md
CHANGED
@@ -5,8 +5,20 @@
|
|
5
5
|
This package provides a command-line interface to Wavefront's API. Each API path
|
6
6
|
is covered by a different command keyword.
|
7
7
|
|
8
|
+
The gem is hosted [on
|
9
|
+
Rubygems](https://rubygems.org/gems/wavefront-cli) and can be
|
10
|
+
installed with
|
11
|
+
|
12
|
+
```
|
13
|
+
$ gem install wavefront-cli
|
14
|
+
```
|
15
|
+
|
8
16
|
It is built on [the Wavefront Ruby
|
9
|
-
SDK](https://github.com/snltd/wavefront-sdk) and requires Ruby >=
|
17
|
+
SDK](https://github.com/snltd/wavefront-sdk) and requires Ruby >=
|
18
|
+
2.2. It has no "native extension" dependencies.
|
19
|
+
|
20
|
+
I also maintain [a reasonably thorough
|
21
|
+
tutorial](http://sysdef.xyz/post/2017-07-26-wavefront-cli).
|
10
22
|
|
11
23
|
```
|
12
24
|
$ wf --help
|
@@ -28,8 +28,8 @@ class WavefrontCommandEvent < WavefrontCommandBase
|
|
28
28
|
'-l, --long list events in detail',
|
29
29
|
'-o, --cursor=EVENT start listing from given event',
|
30
30
|
'-L, --limit=COUNT number of events to list',
|
31
|
-
'-s, --start=TIME time at which event
|
32
|
-
'-e, --end=TIME time at which
|
31
|
+
'-s, --start=TIME time at which event begins',
|
32
|
+
'-e, --end=TIME time at which event ends',
|
33
33
|
'-S, --severity=SEVERITY severity of event',
|
34
34
|
'-i, --instant create an instantaneous event',
|
35
35
|
'-T, --type=TYPE type of event',
|
@@ -18,6 +18,10 @@ class WavefrontCommandWindow < WavefrontCommandBase
|
|
18
18
|
def _commands
|
19
19
|
["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
|
20
20
|
"describe #{CMN} [-f format] <id>",
|
21
|
+
"create #{CMN} -d reason [-s time] [-e time] " \
|
22
|
+
'[-A alert_tag...] [-T host_tag...] [-H host...] <title>',
|
23
|
+
"close #{CMN} <id>",
|
24
|
+
"extend #{CMN} (by|to) <time> <id>",
|
21
25
|
"delete #{CMN} <id>",
|
22
26
|
"import #{CMN} <file>",
|
23
27
|
"update #{CMN} <key=value> <id>",
|
@@ -29,6 +33,12 @@ class WavefrontCommandWindow < WavefrontCommandBase
|
|
29
33
|
'-l, --long list maintenance windows in detail',
|
30
34
|
'-o, --offset=n start from nth maintenance window',
|
31
35
|
'-L, --limit=COUNT number of maintenance windows to list',
|
36
|
+
'-d, --desc=STRING reason for maintenance window',
|
37
|
+
'-s, --start=TIME time at which window begins',
|
38
|
+
'-e, --end=TIME time at which window ends',
|
39
|
+
'-A, --atag=STRING alert tag to which window applies',
|
40
|
+
'-H, --host=STRING host to which window applies',
|
41
|
+
'-T, --htag=STRING host tag to which window applies',
|
32
42
|
'-f, --format=STRING output format']
|
33
43
|
end
|
34
44
|
end
|
@@ -6,9 +6,9 @@ require_relative './opt_handler'
|
|
6
6
|
require_relative './exception'
|
7
7
|
|
8
8
|
# $LOAD_PATH.<< Pathname.new(__FILE__).dirname.realpath.parent.parent
|
9
|
-
|
9
|
+
# .parent + 'lib'
|
10
10
|
# $LOAD_PATH.<< Pathname.new(__FILE__).dirname.realpath.parent.parent
|
11
|
-
|
11
|
+
# .parent + 'wavefront-sdk' + 'lib'
|
12
12
|
|
13
13
|
CMD_DIR = Pathname.new(__FILE__).dirname + 'commands'
|
14
14
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'wavefront-sdk/mixins'
|
1
2
|
require_relative './base'
|
2
3
|
|
3
4
|
module WavefrontCli
|
@@ -5,6 +6,9 @@ module WavefrontCli
|
|
5
6
|
# CLI coverage for the v2 'maintenancewindow' API.
|
6
7
|
#
|
7
8
|
class MaintenanceWindow < WavefrontCli::Base
|
9
|
+
|
10
|
+
include Wavefront::Mixins
|
11
|
+
|
8
12
|
def validator_method
|
9
13
|
:wf_maintenance_window_id?
|
10
14
|
end
|
@@ -12,5 +16,54 @@ module WavefrontCli
|
|
12
16
|
def validator_exception
|
13
17
|
Wavefront::Exception::InvalidMaintenanceWindowId
|
14
18
|
end
|
19
|
+
|
20
|
+
def do_create
|
21
|
+
body = { title: options[:'<title>'] }
|
22
|
+
|
23
|
+
body[:startTimeInSeconds] = if options[:start]
|
24
|
+
parse_time(options[:start])
|
25
|
+
else
|
26
|
+
Time.now.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
body[:endTimeInSeconds] = if options[:end]
|
30
|
+
parse_time(options[:end])
|
31
|
+
else
|
32
|
+
body[:startTimeInSeconds] + 3600
|
33
|
+
end
|
34
|
+
|
35
|
+
body[:reason] = options[:desc] if options[:desc]
|
36
|
+
|
37
|
+
[%i(CustomerTags atag), %i(HostTags htag),
|
38
|
+
%i(HostNames host)].each do |key, opt|
|
39
|
+
k = ('relevant' + key.to_s).to_sym
|
40
|
+
body[k] = options[opt] unless options[opt].empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
wf.create(body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def do_extend_by
|
47
|
+
begin
|
48
|
+
to_add = options[:'<time>'].to_seconds
|
49
|
+
rescue
|
50
|
+
abort "Could not parse time range '#{options[:'<time>']}'."
|
51
|
+
end
|
52
|
+
|
53
|
+
old_end = wf.describe(options[:'<id>']).response.endTimeInSeconds
|
54
|
+
change_end_time(old_end + to_add)
|
55
|
+
end
|
56
|
+
|
57
|
+
def do_extend_to
|
58
|
+
change_end_time(parse_time(options[:'<time>']))
|
59
|
+
end
|
60
|
+
|
61
|
+
def do_close
|
62
|
+
change_end_time(Time.now.to_i)
|
63
|
+
end
|
64
|
+
|
65
|
+
def change_end_time(ts)
|
66
|
+
wf.update(options[:'<id>'], { endTimeInSeconds: ts })
|
67
|
+
end
|
15
68
|
end
|
16
69
|
end
|
data/lib/wavefront-cli/string.rb
CHANGED
@@ -56,4 +56,29 @@ class String
|
|
56
56
|
def scan_line(width)
|
57
57
|
scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/)
|
58
58
|
end
|
59
|
+
|
60
|
+
def to_seconds
|
61
|
+
begin
|
62
|
+
number, unit = self.match(/^(\d+)([smhdw])$/).captures
|
63
|
+
rescue
|
64
|
+
raise ArgumentError
|
65
|
+
end
|
66
|
+
|
67
|
+
factor = case unit
|
68
|
+
when 's'
|
69
|
+
1
|
70
|
+
when 'm'
|
71
|
+
60
|
72
|
+
when 'h'
|
73
|
+
3600
|
74
|
+
when 'd'
|
75
|
+
86400
|
76
|
+
when 'w'
|
77
|
+
604800
|
78
|
+
else
|
79
|
+
raise ArgumentError
|
80
|
+
end
|
81
|
+
|
82
|
+
number.to_i * factor
|
83
|
+
end
|
59
84
|
end
|
@@ -1 +1 @@
|
|
1
|
-
WF_CLI_VERSION = '1.0.
|
1
|
+
WF_CLI_VERSION = '1.0.2'.freeze
|
@@ -17,7 +17,7 @@ describe "#{word} command" do
|
|
17
17
|
{ method: :delete, path: "/api/v2/maintenancewindow/#{id}" }, k)
|
18
18
|
invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}"])
|
19
19
|
cmd_to_call(word, "search -o 100 id=#{id}",
|
20
|
-
{ method: :post, path:
|
20
|
+
{ method: :post, path: '/api/v2/search/maintenancewindow',
|
21
21
|
body: { limit: 10,
|
22
22
|
offset: "100",
|
23
23
|
query: [{key: 'id',
|
@@ -26,4 +26,12 @@ describe "#{word} command" do
|
|
26
26
|
sort: {field: 'id', ascending: true}},
|
27
27
|
headers: JSON_POST_HEADERS },
|
28
28
|
WavefrontCli::MaintenanceWindow)
|
29
|
+
|
30
|
+
cmd_to_call(word, 'create -d testing -H shark tester',
|
31
|
+
{ method: :post, path: '/api/v2/maintenancewindow',
|
32
|
+
body: {
|
33
|
+
},
|
34
|
+
headers: JSON_POST_HEADERS },
|
35
|
+
WavefrontCli::MaintenanceWindow)
|
36
|
+
|
29
37
|
end
|
@@ -34,18 +34,13 @@ class StringTest < MiniTest::Test
|
|
34
34
|
assert_equal(str.opt_fold(100), " #{str}\n")
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
#" have to fold it twice",
|
46
|
-
#
|
47
|
-
#wf.mk_line('key', 'a very long string whose very length means that the method is going to have to fold it twice', 40))
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#end
|
37
|
+
def test_to_seconds
|
38
|
+
assert_equal(14, '14s'.to_seconds)
|
39
|
+
assert_equal(300, '5m'.to_seconds)
|
40
|
+
assert_equal(10800, '3h'.to_seconds)
|
41
|
+
assert_equal(1209600, '2w'.to_seconds)
|
42
|
+
assert_raises(ArgumentError) { 'm'.to_seconds }
|
43
|
+
assert_raises(ArgumentError) { '3m5s'.to_seconds }
|
44
|
+
end
|
51
45
|
end
|
46
|
+
|
data/wavefront-cli.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.require_paths = %w(lib)
|
24
24
|
|
25
25
|
gem.add_dependency 'docopt', '0.6.0'
|
26
|
-
gem.add_dependency 'wavefront-sdk', '>= 1.0.
|
26
|
+
gem.add_dependency 'wavefront-sdk', '>= 1.0.2'
|
27
27
|
|
28
28
|
gem.add_development_dependency 'bundler', '~> 1.3'
|
29
29
|
gem.add_development_dependency 'rake', '~> 12.0'
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Fisher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docopt
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.
|
33
|
+
version: 1.0.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0.
|
40
|
+
version: 1.0.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|