wavefront-cli 4.2.1 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +1 -14
- data/.travis.yml +4 -4
- data/Gemfile +2 -0
- data/HISTORY.md +82 -60
- data/Rakefile +2 -0
- data/bin/wf +1 -0
- data/lib/wavefront-cli/alert.rb +13 -5
- data/lib/wavefront-cli/apitoken.rb +2 -0
- data/lib/wavefront-cli/base.rb +95 -47
- data/lib/wavefront-cli/cloudintegration.rb +6 -0
- data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
- data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
- data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
- data/lib/wavefront-cli/commands/alert.rb +2 -1
- data/lib/wavefront-cli/commands/apitoken.rb +6 -0
- data/lib/wavefront-cli/commands/base.rb +30 -21
- data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
- data/lib/wavefront-cli/commands/config.rb +2 -0
- data/lib/wavefront-cli/commands/dashboard.rb +2 -0
- data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/commands/event.rb +3 -1
- data/lib/wavefront-cli/commands/integration.rb +2 -1
- data/lib/wavefront-cli/commands/link.rb +2 -0
- data/lib/wavefront-cli/commands/message.rb +2 -0
- data/lib/wavefront-cli/commands/metric.rb +2 -0
- data/lib/wavefront-cli/commands/notificant.rb +2 -0
- data/lib/wavefront-cli/commands/proxy.rb +2 -0
- data/lib/wavefront-cli/commands/query.rb +2 -0
- data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
- data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
- data/lib/wavefront-cli/commands/settings.rb +2 -0
- data/lib/wavefront-cli/commands/source.rb +3 -1
- data/lib/wavefront-cli/commands/user.rb +4 -1
- data/lib/wavefront-cli/commands/usergroup.rb +3 -0
- data/lib/wavefront-cli/commands/webhook.rb +2 -0
- data/lib/wavefront-cli/commands/window.rb +2 -0
- data/lib/wavefront-cli/commands/write.rb +2 -0
- data/lib/wavefront-cli/config.rb +23 -12
- data/lib/wavefront-cli/constants.rb +10 -4
- data/lib/wavefront-cli/controller.rb +53 -22
- data/lib/wavefront-cli/dashboard.rb +3 -0
- data/lib/wavefront-cli/derivedmetric.rb +12 -11
- data/lib/wavefront-cli/display/alert.rb +7 -4
- data/lib/wavefront-cli/display/apitoken.rb +2 -0
- data/lib/wavefront-cli/display/base.rb +34 -8
- data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
- data/lib/wavefront-cli/display/dashboard.rb +2 -0
- data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/display/distribution.rb +2 -0
- data/lib/wavefront-cli/display/event.rb +2 -0
- data/lib/wavefront-cli/display/externallink.rb +2 -0
- data/lib/wavefront-cli/display/integration.rb +2 -0
- data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
- data/lib/wavefront-cli/display/message.rb +7 -3
- data/lib/wavefront-cli/display/metric.rb +3 -1
- data/lib/wavefront-cli/display/notificant.rb +3 -1
- data/lib/wavefront-cli/display/printer/long.rb +36 -11
- data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
- data/lib/wavefront-cli/display/printer/terse.rb +6 -1
- data/lib/wavefront-cli/display/proxy.rb +2 -0
- data/lib/wavefront-cli/display/query.rb +35 -24
- data/lib/wavefront-cli/display/savedsearch.rb +2 -0
- data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
- data/lib/wavefront-cli/display/settings.rb +2 -0
- data/lib/wavefront-cli/display/source.rb +18 -4
- data/lib/wavefront-cli/display/user.rb +56 -10
- data/lib/wavefront-cli/display/usergroup.rb +25 -19
- data/lib/wavefront-cli/display/webhook.rb +2 -0
- data/lib/wavefront-cli/display/write.rb +6 -2
- data/lib/wavefront-cli/event.rb +83 -62
- data/lib/wavefront-cli/exception.rb +3 -0
- data/lib/wavefront-cli/externallink.rb +6 -4
- data/lib/wavefront-cli/integration.rb +2 -0
- data/lib/wavefront-cli/maintenancewindow.rb +28 -17
- data/lib/wavefront-cli/message.rb +4 -0
- data/lib/wavefront-cli/metric.rb +4 -1
- data/lib/wavefront-cli/notificant.rb +2 -0
- data/lib/wavefront-cli/opt_handler.rb +2 -0
- data/lib/wavefront-cli/output/base.rb +8 -3
- data/lib/wavefront-cli/output/csv.rb +2 -0
- data/lib/wavefront-cli/output/csv/base.rb +2 -0
- data/lib/wavefront-cli/output/csv/query.rb +14 -7
- data/lib/wavefront-cli/output/hcl.rb +2 -0
- data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
- data/lib/wavefront-cli/output/hcl/base.rb +10 -4
- data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
- data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
- data/lib/wavefront-cli/output/json.rb +2 -0
- data/lib/wavefront-cli/output/ruby.rb +2 -0
- data/lib/wavefront-cli/output/wavefront.rb +2 -0
- data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
- data/lib/wavefront-cli/output/yaml.rb +2 -0
- data/lib/wavefront-cli/proxy.rb +15 -3
- data/lib/wavefront-cli/query.rb +14 -12
- data/lib/wavefront-cli/savedsearch.rb +2 -0
- data/lib/wavefront-cli/serviceaccount.rb +179 -0
- data/lib/wavefront-cli/settings.rb +2 -0
- data/lib/wavefront-cli/source.rb +2 -0
- data/lib/wavefront-cli/stdlib/array.rb +3 -0
- data/lib/wavefront-cli/stdlib/string.rb +17 -11
- data/lib/wavefront-cli/user.rb +10 -4
- data/lib/wavefront-cli/usergroup.rb +4 -2
- data/lib/wavefront-cli/version.rb +3 -1
- data/lib/wavefront-cli/webhook.rb +2 -0
- data/lib/wavefront-cli/write.rb +80 -46
- data/spec/.rubocop.yml +3 -16
- data/spec/constants.rb +21 -0
- data/spec/spec_helper.rb +8 -422
- data/spec/support/command_base.rb +82 -0
- data/spec/support/minitest_assertions.rb +262 -0
- data/spec/support/output_tester.rb +32 -0
- data/spec/support/supported_commands.rb +19 -0
- data/spec/test_mixins/acl.rb +169 -0
- data/spec/test_mixins/delete.rb +25 -0
- data/spec/test_mixins/deleteundelete.rb +106 -0
- data/spec/test_mixins/describe.rb +24 -0
- data/spec/test_mixins/dump.rb +43 -0
- data/spec/test_mixins/general.rb +11 -0
- data/spec/test_mixins/history.rb +35 -0
- data/spec/test_mixins/import.rb +65 -0
- data/spec/test_mixins/list.rb +29 -0
- data/spec/test_mixins/search.rb +98 -0
- data/spec/test_mixins/set.rb +47 -0
- data/spec/test_mixins/tag.rb +99 -0
- data/spec/wavefront-cli/alert_spec.rb +288 -111
- data/spec/wavefront-cli/apitoken_spec.rb +53 -24
- data/spec/wavefront-cli/base_spec.rb +9 -27
- data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
- data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
- data/spec/wavefront-cli/commands/base_spec.rb +15 -13
- data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
- data/spec/wavefront-cli/commands/config_spec.rb +3 -0
- data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
- data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/event_spec.rb +1 -0
- data/spec/wavefront-cli/commands/link_spec.rb +1 -0
- data/spec/wavefront-cli/commands/message_spec.rb +1 -0
- data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
- data/spec/wavefront-cli/commands/query_spec.rb +1 -0
- data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
- data/spec/wavefront-cli/commands/window_spec.rb +1 -0
- data/spec/wavefront-cli/commands/write_spec.rb +1 -0
- data/spec/wavefront-cli/config_spec.rb +25 -14
- data/spec/wavefront-cli/controller_spec.rb +13 -3
- data/spec/wavefront-cli/dashboard_spec.rb +125 -76
- data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
- data/spec/wavefront-cli/display/base_spec.rb +5 -7
- data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
- data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
- data/spec/wavefront-cli/event_spec.rb +360 -18
- data/spec/wavefront-cli/externallink_spec.rb +92 -58
- data/spec/wavefront-cli/integration_spec.rb +129 -31
- data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
- data/spec/wavefront-cli/message_spec.rb +73 -30
- data/spec/wavefront-cli/metric_spec.rb +60 -22
- data/spec/wavefront-cli/notificant_spec.rb +45 -32
- data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
- data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
- data/spec/wavefront-cli/output/csv_spec.rb +5 -2
- data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
- data/spec/wavefront-cli/output/helpers.rb +18 -0
- data/spec/wavefront-cli/output/json_spec.rb +3 -1
- data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
- data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
- data/spec/wavefront-cli/proxy_spec.rb +49 -27
- data/spec/wavefront-cli/query_spec.rb +174 -92
- data/spec/wavefront-cli/resources/responses/query.json +1 -0
- data/spec/wavefront-cli/resources/updates/alert.json +15 -0
- data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
- data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
- data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
- data/spec/wavefront-cli/settings_spec.rb +42 -11
- data/spec/wavefront-cli/source_spec.rb +120 -23
- data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
- data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
- data/spec/wavefront-cli/user_spec.rb +278 -108
- data/spec/wavefront-cli/usergroup_spec.rb +152 -102
- data/spec/wavefront-cli/webhook_spec.rb +30 -15
- data/spec/wavefront-cli/write_spec.rb +25 -1
- data/wavefront-cli.gemspec +5 -3
- metadata +65 -21
- data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
- data/spec/wavefront-cli/display/spec_helper.rb +0 -3
@@ -1,8 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require_relative '../../../support/output_tester'
|
3
6
|
require_relative '../../../../lib/wavefront-cli/display/printer/terse'
|
4
|
-
require_relative '../spec_helper'
|
5
|
-
require_relative '../../../spec_helper'
|
6
7
|
|
7
8
|
TERSE_DATA = [{ id: 'id1', name: 'name1', fa: 1, fb: 2, fc: 3 },
|
8
9
|
{ id: 'id2', name: 'name2', fa: 11, fb: 21, fc: 31 }].freeze
|
@@ -50,8 +51,8 @@ class WavefrontDisplayPrinterTerse < MiniTest::Test
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def test_end_to_end
|
53
|
-
input, expected =
|
54
|
-
|
54
|
+
input, expected = OutputTester.new.in_and_out('alerts-input.json',
|
55
|
+
'alerts-human-terse')
|
55
56
|
out = WavefrontDisplayPrinter::Terse.new(input, %i[id status name]).to_s
|
56
57
|
assert_equal(expected, out + "\n")
|
57
58
|
end
|
@@ -1,21 +1,363 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
require 'tmpdir'
|
5
|
+
require_relative '../support/command_base'
|
6
|
+
require_relative '../../lib/wavefront-cli/event'
|
7
|
+
require 'wavefront-sdk/support/mixins'
|
8
|
+
|
9
|
+
TEST_EVENT_DIR = Pathname.new('/tmp/wf_event_test')
|
10
|
+
|
11
|
+
# Test the 'event' command behaves as it should. Unit tests for class methods
|
12
|
+
# come later.
|
13
|
+
#
|
14
|
+
class EventEndToEndTest < EndToEndTest
|
15
|
+
attr_reader :test_state_dir
|
16
|
+
include Wavefront::Mixins
|
17
|
+
|
18
|
+
include WavefrontCliTest::Describe
|
19
|
+
include WavefrontCliTest::Delete
|
20
|
+
# Ones above work, ones below don't
|
21
|
+
# include WavefrontCliTest::Search
|
22
|
+
# include WavefrontCliTest::Set
|
23
|
+
# include WavefrontCliTest::Tags
|
24
|
+
|
25
|
+
def before_setup
|
26
|
+
@test_state_dir = Pathname.new(Dir.mktmpdir)
|
27
|
+
ENV['WF_EVENT_STATE_DIR'] = test_state_dir.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
FileUtils.rm_r(test_state_dir)
|
32
|
+
end
|
33
|
+
|
34
|
+
def cmd_instance
|
35
|
+
cmd_class.new(event_state_dir: TEST_EVENT_DIR)
|
36
|
+
puts cmd_class
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_list_no_options
|
40
|
+
str = '/api/v2/event\?' \
|
41
|
+
'earliestStartTimeEpochMillis=\d{13}+&' \
|
42
|
+
'latestStartTimeEpochMillis=\d{13}+&' \
|
43
|
+
'limit=100'
|
44
|
+
|
45
|
+
quietly { assert_cmd_gets('list', Regexp.new(str)) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_list_start_and_end_time
|
49
|
+
quietly do
|
50
|
+
assert_cmd_gets("list #{start_and_end_opts}",
|
51
|
+
'/api/v2/event?earliestStartTimeEpochMillis=' \
|
52
|
+
"#{epoch_time[0]}&latestStartTimeEpochMillis=" \
|
53
|
+
"#{epoch_time[1]}&limit=100")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_list_start_and_end_time_offset_and_cursor
|
58
|
+
quietly do
|
59
|
+
assert_cmd_gets("list #{start_and_end_opts} -o #{id} --limit 8",
|
60
|
+
'/api/v2/event' \
|
61
|
+
"?earliestStartTimeEpochMillis=#{epoch_time[0]}" \
|
62
|
+
"&latestStartTimeEpochMillis=#{epoch_time[1]}" \
|
63
|
+
"&cursor=#{id}" \
|
64
|
+
'&limit=8')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_create
|
69
|
+
mock_id = "#{start_time}:#{event_name}:1"
|
70
|
+
state_file = state_dir + mock_id
|
71
|
+
|
72
|
+
out, err = capture_io do
|
73
|
+
assert_cmd_posts("create #{event_name}",
|
74
|
+
'/api/v2/event',
|
75
|
+
{ name: event_name,
|
76
|
+
startTime: a_ms_timestamp,
|
77
|
+
annotations: {},
|
78
|
+
hosts: [],
|
79
|
+
tags: [] },
|
80
|
+
{ name: event_name,
|
81
|
+
id: mock_id,
|
82
|
+
startTime: start_time,
|
83
|
+
tags: [] }.to_json)
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_empty(err)
|
87
|
+
assert_match(/^Event state recorded at #{state_file}\.\n/, out)
|
88
|
+
assert state_file.exist?
|
89
|
+
assert_equal(
|
90
|
+
"{\"hosts\":[],\"description\":null,\"severity\":null,\"tags\":[]}\n",
|
91
|
+
IO.read(state_file)
|
92
|
+
)
|
93
|
+
|
94
|
+
assert_abort_on_missing_creds("create #{event_name}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_create_with_hosts
|
98
|
+
mock_id = "#{start_time}:#{event_name}:1"
|
99
|
+
state_file = state_dir + mock_id
|
100
|
+
refute state_file.exist?
|
101
|
+
|
102
|
+
out, err = capture_io do
|
103
|
+
assert_cmd_posts('create -d reason -H host1 -H host2 -g ' \
|
104
|
+
"mytag #{event_name}",
|
105
|
+
'/api/v2/event',
|
106
|
+
{ name: event_name,
|
107
|
+
startTime: a_ms_timestamp,
|
108
|
+
annotations: { details: 'reason' },
|
109
|
+
hosts: %w[host1 host2],
|
110
|
+
tags: %w[mytag] },
|
111
|
+
{ name: event_name,
|
112
|
+
id: mock_id,
|
113
|
+
startTime: start_time,
|
114
|
+
hosts: %w[host1 host2],
|
115
|
+
tags: %w[mytag] }.to_json)
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_empty(err)
|
119
|
+
assert_match(/^Event state recorded at #{state_file}\.\n/, out)
|
120
|
+
assert state_file.exist?
|
121
|
+
assert_equal('{"hosts":["host1","host2"],"description":"reason",' \
|
122
|
+
"\"severity\":null,\"tags\":[\"mytag\"]}\n",
|
123
|
+
IO.read(state_file))
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_create_instantaneous_with_start_time
|
127
|
+
out, err = capture_io do
|
128
|
+
assert_cmd_posts("create -i -s #{start_time} -g tag1 " \
|
129
|
+
"-g tag2 #{event_name}",
|
130
|
+
'/api/v2/event',
|
131
|
+
{ name: event_name,
|
132
|
+
startTime: start_time,
|
133
|
+
endTime: start_time + 1,
|
134
|
+
annotations: {},
|
135
|
+
hosts: [],
|
136
|
+
tags: %w[tag1 tag2] },
|
137
|
+
{ name: event_name,
|
138
|
+
annotations: {},
|
139
|
+
id: "#{start_time}:#{event_name}:1",
|
140
|
+
endTime: start_time + 1,
|
141
|
+
startTime: start_time,
|
142
|
+
tags: %w[tag1 tag2] }.to_json)
|
143
|
+
end
|
144
|
+
|
145
|
+
assert_empty(err)
|
146
|
+
assert_match(/^id 1481553823153:test_event:1\n/, out)
|
147
|
+
assert_match(/\nannotations <none>\n/, out)
|
148
|
+
assert_match(/\ntags tag1\n tag2\n/, out)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_close_named_event
|
152
|
+
quietly do
|
153
|
+
assert_cmd_posts('close 1568133440520:ev2:0',
|
154
|
+
'/api/v2/event/1568133440520:ev2:0/close')
|
155
|
+
end
|
156
|
+
|
157
|
+
assert_abort_on_missing_creds("close #{id}")
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_close_with_no_local_events
|
161
|
+
quietly { assert_cmd_posts("close #{id}", "/api/v2/event/#{id}/close") }
|
162
|
+
assert_exits_with('No locally recorded events.', 'close')
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_close_with_local_events_no_match
|
166
|
+
setup_test_state_dir
|
167
|
+
assert_exits_with("No locally stored event matches 'X'.", 'close X')
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_close_with_local_events_pop
|
171
|
+
setup_test_state_dir
|
172
|
+
assert((state_dir + '1568133440530:ev3:0').exist?)
|
173
|
+
|
174
|
+
quietly do
|
175
|
+
assert_cmd_posts('close', '/api/v2/event/1568133440530:ev3:0/close')
|
176
|
+
end
|
177
|
+
|
178
|
+
refute((state_dir + '1568133440530:ev3:0').exist?)
|
179
|
+
assert((state_dir + '1568133440520:ev2:0').exist?)
|
180
|
+
|
181
|
+
quietly do
|
182
|
+
assert_cmd_posts('close', '/api/v2/event/1568133440520:ev2:0/close')
|
183
|
+
end
|
184
|
+
|
185
|
+
refute((state_dir + '1568133440520:ev2:0').exist?)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_wrap
|
189
|
+
mock_id = "#{start_time}:#{event_name}:1"
|
190
|
+
state_file = state_dir + mock_id
|
191
|
+
|
192
|
+
all_permutations do |p|
|
193
|
+
open_stub = wrap_open_stub(p, mock_id)
|
194
|
+
close_stub = wrap_close_stub(p, mock_id)
|
195
|
+
|
196
|
+
out, err = capture_io do
|
197
|
+
assert_raises(SystemExit) do
|
198
|
+
wf.new('event wrap -C date -d reason -g mytag ' \
|
199
|
+
"#{event_name} #{p[:cmdline]}".split)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
lines = out.split("\n")
|
204
|
+
|
205
|
+
assert_equal("Event state recorded at #{state_file}.", lines[0])
|
206
|
+
assert_equal('Command output follows, on STDERR:', lines[1])
|
207
|
+
assert_match(/^-+$/, lines[2])
|
208
|
+
assert_match(/^-+$/, lines[3])
|
209
|
+
refute_empty(err)
|
210
|
+
assert_requested(open_stub)
|
211
|
+
assert_requested(close_stub)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_show
|
216
|
+
setup_test_state_dir
|
217
|
+
|
218
|
+
out, err = capture_io do
|
219
|
+
assert_raises(SystemExit) { wf.new("event show -c #{CF}".split) }
|
220
|
+
end
|
221
|
+
|
222
|
+
assert_empty(err)
|
223
|
+
assert_equal("1568133440530:ev3:0\n1568133440520:ev2:0\n" \
|
224
|
+
"1568133440515:ev1:1\n1568133440510:ev1:0\n", out)
|
225
|
+
end
|
226
|
+
|
227
|
+
private
|
228
|
+
|
229
|
+
def id
|
230
|
+
'1481553823153:testev'
|
231
|
+
end
|
232
|
+
|
233
|
+
def event_name
|
234
|
+
'test_event'
|
235
|
+
end
|
236
|
+
|
237
|
+
def invalid_id
|
238
|
+
'__BAD__'
|
239
|
+
end
|
240
|
+
|
241
|
+
def cmd_word
|
242
|
+
'event'
|
243
|
+
end
|
244
|
+
|
245
|
+
def start_time
|
246
|
+
1_481_553_823_153
|
247
|
+
end
|
248
|
+
|
249
|
+
def import_fields
|
250
|
+
%i[method title creatorId triggers template]
|
251
|
+
end
|
252
|
+
|
253
|
+
def state_dir
|
254
|
+
test_state_dir + (Etc.getlogin || 'notty')
|
255
|
+
end
|
256
|
+
|
257
|
+
def setup_test_state_dir
|
258
|
+
FileUtils.mkdir_p(state_dir)
|
259
|
+
|
260
|
+
%w[1568133440510:ev1:0
|
261
|
+
1568133440515:ev1:1
|
262
|
+
1568133440520:ev2:0
|
263
|
+
1568133440530:ev3:0].each do |f|
|
264
|
+
File.open(state_dir + f, 'w') { |fh| fh.puts('dummy_data') }
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def wrap_open_stub(perm, mock_id)
|
269
|
+
stub_request(:post, "https://#{perm[:endpoint]}/api/v2/event")
|
270
|
+
.with(body: { name: event_name,
|
271
|
+
startTime: a_ms_timestamp,
|
272
|
+
annotations: { details: 'reason' },
|
273
|
+
hosts: [],
|
274
|
+
tags: %w[mytag] })
|
275
|
+
.to_return(body: { name: event_name,
|
276
|
+
id: mock_id,
|
277
|
+
startTime: start_time,
|
278
|
+
hosts: [],
|
279
|
+
tags: %w[mytag] }.to_json,
|
280
|
+
status: 200)
|
281
|
+
end
|
282
|
+
|
283
|
+
def wrap_close_stub(perm, mock_id)
|
284
|
+
stub_request(:post,
|
285
|
+
"https://#{perm[:endpoint]}/api/v2/event/#{mock_id}/close")
|
286
|
+
.with(body: 'null')
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
# Unit tests for class methods
|
291
|
+
#
|
292
|
+
class EventMethodTests < Minitest::Test
|
293
|
+
attr_reader :wf, :wfse
|
294
|
+
|
295
|
+
def setup
|
296
|
+
@wf = WavefrontCli::Event.new({})
|
297
|
+
@wfse = WavefrontCli::Event.new(start: wall_time[0],
|
298
|
+
end: wall_time[1],
|
299
|
+
limit: 55,
|
300
|
+
cursor: '1481553823153:testev')
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_create_dir_ok
|
304
|
+
base = Pathname.new(Dir.mktmpdir)
|
305
|
+
dir = base + 'testdir'
|
306
|
+
refute dir.exist?
|
307
|
+
wf.create_dir(dir)
|
308
|
+
assert dir.exist?
|
309
|
+
dir.unlink
|
310
|
+
base.unlink
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_create_dir_fail
|
314
|
+
spy = Spy.on(FileUtils, :mkdir_p).and_return(false)
|
315
|
+
|
316
|
+
assert_raises(WavefrontCli::Exception::SystemError) do
|
317
|
+
wf.create_dir(Pathname.new('/any/old/directory'))
|
318
|
+
end
|
319
|
+
|
320
|
+
assert spy.has_been_called?
|
321
|
+
spy.unhook
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_list_args_defaults
|
325
|
+
x = wf.list_args
|
326
|
+
assert_instance_of(Array, x)
|
327
|
+
assert_equal(4, x.size)
|
328
|
+
assert_in_delta(((Time.now - 600).to_i * 1000), x[0], 1000)
|
329
|
+
assert_in_delta((Time.now.to_i * 1000), x[1], 1000)
|
330
|
+
assert_equal(100, x[2])
|
331
|
+
assert_nil(x[3])
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_list_args_options
|
335
|
+
x = wfse.list_args
|
336
|
+
assert_instance_of(Array, x)
|
337
|
+
assert_equal(4, x.size)
|
338
|
+
assert_equal(epoch_ms_time[0], x[0])
|
339
|
+
assert_equal(epoch_ms_time[1], x[1])
|
340
|
+
assert_equal(55, x[2])
|
341
|
+
assert_equal('1481553823153:testev', x[3])
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_window_start
|
345
|
+
assert_kind_of(Numeric, wf.window_start)
|
346
|
+
assert_equal(epoch_ms_time[0], wfse.window_start)
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_window_end
|
350
|
+
assert_kind_of(Numeric, wf.window_end)
|
351
|
+
assert_equal(epoch_ms_time[1], wfse.window_end)
|
352
|
+
end
|
353
|
+
|
354
|
+
private
|
355
|
+
|
356
|
+
def wall_time
|
357
|
+
[Time.at(1_568_112_000), Time.at(1_568_112_999)]
|
358
|
+
end
|
359
|
+
|
360
|
+
def epoch_ms_time
|
361
|
+
wall_time.map { |t| (t.to_i * 1000) }
|
362
|
+
end
|
21
363
|
end
|
@@ -1,63 +1,97 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require_relative '../
|
4
|
+
require_relative '../support/command_base'
|
4
5
|
require_relative '../../lib/wavefront-cli/externallink'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
7
|
+
# Ensure 'link' commands produce the correct API calls.
|
8
|
+
#
|
9
|
+
class ExternalLinkEndToEndTest < EndToEndTest
|
10
|
+
include WavefrontCliTest::List
|
11
|
+
include WavefrontCliTest::Describe
|
12
|
+
include WavefrontCliTest::Dump
|
13
|
+
# include WavefrontCliTest::Import
|
14
|
+
include WavefrontCliTest::Set
|
15
|
+
include WavefrontCliTest::Delete
|
16
|
+
include WavefrontCliTest::Search
|
17
|
+
|
18
|
+
def test_create_without_options
|
19
|
+
quietly do
|
20
|
+
assert_cmd_posts('create myname mydescription mytemplate',
|
21
|
+
'/api/v2/extlink',
|
22
|
+
name: 'myname',
|
23
|
+
template: 'mytemplate',
|
24
|
+
description: 'mydescription')
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_noop('create myname mydescription mytemplate',
|
28
|
+
'uri: POST https://default.wavefront.com/api/v2/extlink',
|
29
|
+
'body: ' + { name: 'myname',
|
30
|
+
template: 'mytemplate',
|
31
|
+
description: 'mydescription' }.to_json)
|
32
|
+
|
33
|
+
assert_abort_on_missing_creds('create myname mydescription mytemplate')
|
34
|
+
assert_usage('create myname mydescription')
|
35
|
+
assert_usage('create myname')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_create_with_regexes
|
39
|
+
quietly do
|
40
|
+
assert_cmd_posts('create -m metricregex -s sourceregex myname ' \
|
41
|
+
'mydescription mytemplate',
|
42
|
+
'/api/v2/extlink',
|
43
|
+
name: 'myname',
|
44
|
+
template: 'mytemplate',
|
45
|
+
description: 'mydescription',
|
46
|
+
metricFilterRegex: 'metricregex',
|
47
|
+
sourceFilterRegex: 'sourceregex')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_create_with_keys_and_regexes
|
52
|
+
quietly do
|
53
|
+
assert_cmd_posts('create -p key1=reg1 -p key2=reg2 ' \
|
54
|
+
'-m metricregex myname mydescription mytemplate',
|
55
|
+
'/api/v2/extlink',
|
56
|
+
name: 'myname',
|
57
|
+
template: 'mytemplate',
|
58
|
+
description: 'mydescription',
|
59
|
+
metricFilterRegex: 'metricregex',
|
60
|
+
pointFilterRegex: {
|
61
|
+
key1: 'reg1',
|
62
|
+
key2: 'reg2'
|
63
|
+
})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def id
|
70
|
+
'lq6rPlSg2CFMSrg6'
|
71
|
+
end
|
72
|
+
|
73
|
+
def invalid_id
|
74
|
+
'__BAD__'
|
75
|
+
end
|
76
|
+
|
77
|
+
def cmd_word
|
78
|
+
'link'
|
79
|
+
end
|
80
|
+
|
81
|
+
def api_path
|
82
|
+
'extlink'
|
83
|
+
end
|
84
|
+
|
85
|
+
def sdk_class_name
|
86
|
+
'ExternalLink'
|
87
|
+
end
|
88
|
+
|
89
|
+
def friendly_name
|
90
|
+
'external link'
|
91
|
+
end
|
92
|
+
|
93
|
+
def import_fields
|
94
|
+
%i[condition displayExpression resolveAfterMinutes minutes severity
|
95
|
+
tags target name]
|
96
|
+
end
|
63
97
|
end
|