wavefront-cli 4.2.1 → 4.3.0
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/.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,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module WavefrontCli
|
|
2
4
|
#
|
|
3
5
|
# CLI-specific exceptions. These should generally be caught in the
|
|
@@ -11,6 +13,7 @@ module WavefrontCli
|
|
|
11
13
|
class ImpossibleSearch < RuntimeError; end
|
|
12
14
|
class InsufficientData < RuntimeError; end
|
|
13
15
|
class InvalidInput < RuntimeError; end
|
|
16
|
+
class InvalidQuery < RuntimeError; end
|
|
14
17
|
class InvalidValue < RuntimeError; end
|
|
15
18
|
class ProfileExists < RuntimeError; end
|
|
16
19
|
class ProfileNotFound < RuntimeError; end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'base'
|
|
2
4
|
|
|
3
5
|
module WavefrontCli
|
|
@@ -14,12 +16,12 @@ module WavefrontCli
|
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def do_create
|
|
17
|
-
body = { name:
|
|
18
|
-
template:
|
|
19
|
-
description:
|
|
19
|
+
body = { name: options[:'<name>'],
|
|
20
|
+
template: options[:'<template>'],
|
|
21
|
+
description: options[:'<description>'],
|
|
20
22
|
metricFilterRegex: options[:metricregex],
|
|
21
23
|
sourceFilterRegex: options[:sourceregex],
|
|
22
|
-
pointFilterRegex:
|
|
24
|
+
pointFilterRegex: point_filter_regexes }
|
|
23
25
|
|
|
24
26
|
wf.create(body.select { |_k, v| v })
|
|
25
27
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'wavefront-sdk/support/mixins'
|
|
2
4
|
require_relative 'base'
|
|
3
5
|
|
|
@@ -29,9 +31,9 @@ module WavefrontCli
|
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
def build_body
|
|
32
|
-
ret = { title:
|
|
34
|
+
ret = { title: options[:'<title>'],
|
|
33
35
|
startTimeInSeconds: window_start,
|
|
34
|
-
endTimeInSeconds:
|
|
36
|
+
endTimeInSeconds: window_end }
|
|
35
37
|
|
|
36
38
|
ret[:reason] = options[:desc] if options[:desc]
|
|
37
39
|
ret
|
|
@@ -60,21 +62,25 @@ module WavefrontCli
|
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
def do_extend_by
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
rescue ArgumentError
|
|
66
|
-
abort "Could not parse time range '#{options[:'<time>']}'."
|
|
67
|
-
end
|
|
68
|
-
|
|
65
|
+
cannot_noop!
|
|
66
|
+
to_add = parse_range_to_add
|
|
69
67
|
old_end = wf.describe(options[:'<id>']).response.endTimeInSeconds
|
|
70
68
|
change_end_time(old_end + to_add)
|
|
71
69
|
end
|
|
72
70
|
|
|
71
|
+
def parse_range_to_add
|
|
72
|
+
options[:'<time>'].to_seconds
|
|
73
|
+
rescue ArgumentError
|
|
74
|
+
abort "Could not parse time range '#{options[:'<time>']}'."
|
|
75
|
+
end
|
|
76
|
+
|
|
73
77
|
def do_extend_to
|
|
78
|
+
cannot_noop!
|
|
74
79
|
change_end_time(parse_time(options[:'<time>']))
|
|
75
80
|
end
|
|
76
81
|
|
|
77
82
|
def do_close
|
|
83
|
+
cannot_noop!
|
|
78
84
|
change_end_time(Time.now.to_i)
|
|
79
85
|
end
|
|
80
86
|
|
|
@@ -83,22 +89,27 @@ module WavefrontCli
|
|
|
83
89
|
end
|
|
84
90
|
|
|
85
91
|
def do_ongoing
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
ret = wf.ongoing
|
|
93
|
+
|
|
94
|
+
exit if options[:noop]
|
|
95
|
+
|
|
96
|
+
return ret unless ret.is_a?(Wavefront::Response) && ret.empty?
|
|
97
|
+
|
|
98
|
+
ok_exit('No maintenance windows currently ongoing.')
|
|
89
99
|
end
|
|
90
100
|
|
|
91
101
|
def do_pending
|
|
92
102
|
range = options[:'<hours>'].to_f
|
|
93
103
|
range = 24 unless range.positive?
|
|
94
104
|
|
|
95
|
-
|
|
105
|
+
ret = wf.pending(range)
|
|
96
106
|
|
|
97
|
-
if
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
exit if options[:noop]
|
|
108
|
+
|
|
109
|
+
return ret unless ret.is_a?(Wavefront::Response) && ret.empty?
|
|
110
|
+
|
|
111
|
+
ok_exit(format('No maintenance windows in the next %<range>s hours.',
|
|
112
|
+
range: range))
|
|
102
113
|
end
|
|
103
114
|
end
|
|
104
115
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'base'
|
|
2
4
|
|
|
3
5
|
module WavefrontCli
|
|
@@ -16,6 +18,8 @@ module WavefrontCli
|
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def do_read
|
|
21
|
+
cannot_noop!
|
|
22
|
+
|
|
19
23
|
resp = wf.list(0, :all, false).response.items.select do |msg|
|
|
20
24
|
msg[:id] == options[:'<id>']
|
|
21
25
|
end
|
data/lib/wavefront-cli/metric.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'base'
|
|
2
4
|
|
|
3
5
|
module WavefrontCli
|
|
@@ -14,10 +16,11 @@ module WavefrontCli
|
|
|
14
16
|
|
|
15
17
|
def extra_validation
|
|
16
18
|
return unless options[:'<metric>']
|
|
19
|
+
|
|
17
20
|
begin
|
|
18
21
|
wf_metric_name?(options[:'<metric>'])
|
|
19
22
|
rescue Wavefront::Exception::InvalidMetricName
|
|
20
|
-
abort "'#{options[:'<metric>']}' is not a valid metric."
|
|
23
|
+
abort "'#{options[:'<metric>']}' is not a valid metric ID."
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module WavefrontOutput
|
|
2
4
|
#
|
|
3
5
|
# WavefrontCli::Base looks for a class WavefrontOutput::Format
|
|
@@ -33,6 +35,7 @@ module WavefrontOutput
|
|
|
33
35
|
|
|
34
36
|
def filtered_response(resp)
|
|
35
37
|
return resp unless options[:itemsonly]
|
|
38
|
+
|
|
36
39
|
items_only(resp)
|
|
37
40
|
end
|
|
38
41
|
|
|
@@ -45,8 +48,8 @@ module WavefrontOutput
|
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
raise(WavefrontCli::Exception::UnsupportedOutput,
|
|
48
|
-
format("'
|
|
49
|
-
my_format))
|
|
51
|
+
format("'%<format>s' format does not support items-only output.",
|
|
52
|
+
format: my_format))
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
def my_format
|
|
@@ -54,7 +57,9 @@ module WavefrontOutput
|
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
def command_class_name
|
|
57
|
-
format('Wavefront
|
|
60
|
+
format('Wavefront%<format>sOutput::%<command>s',
|
|
61
|
+
format: my_format.capitalize,
|
|
62
|
+
command: cmd.capitalize)
|
|
58
63
|
end
|
|
59
64
|
|
|
60
65
|
def command_file
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'set'
|
|
2
4
|
require_relative 'base'
|
|
3
5
|
|
|
@@ -21,8 +23,8 @@ module WavefrontCsvOutput
|
|
|
21
23
|
def post_initialize
|
|
22
24
|
@headers = []
|
|
23
25
|
@formatopts = extract_formatopts
|
|
24
|
-
@data_map
|
|
25
|
-
@columns
|
|
26
|
+
@data_map = options[:raw] ? raw_output : query_output
|
|
27
|
+
@columns = all_keys.freeze
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
# @return [Array[Hash]] which goes in the @data_map
|
|
@@ -66,6 +68,7 @@ module WavefrontCsvOutput
|
|
|
66
68
|
#
|
|
67
69
|
def csv_headers
|
|
68
70
|
return [] unless formatopts.include?('headers')
|
|
71
|
+
|
|
69
72
|
[columns.map { |c| csv_value(c) }.join(',')]
|
|
70
73
|
end
|
|
71
74
|
|
|
@@ -89,7 +92,7 @@ module WavefrontCsvOutput
|
|
|
89
92
|
end
|
|
90
93
|
|
|
91
94
|
def quote_value(value)
|
|
92
|
-
format('"
|
|
95
|
+
format('"%<value>s"', value: value.to_s.gsub(/"/, '\"'))
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
# Turn a string of output options into an easy-to-query array
|
|
@@ -102,10 +105,10 @@ module WavefrontCsvOutput
|
|
|
102
105
|
# Tags have their keys removed.
|
|
103
106
|
#
|
|
104
107
|
def csv_format(path, value, timestamp, source, tags = nil)
|
|
105
|
-
ret = { path:
|
|
106
|
-
value:
|
|
108
|
+
ret = { path: path,
|
|
109
|
+
value: value,
|
|
107
110
|
timestamp: timestamp,
|
|
108
|
-
source:
|
|
111
|
+
source: source }
|
|
109
112
|
|
|
110
113
|
ret.tap { |r| tags.each { |k, v| r[k.to_sym] = tag_val(k, v) } }
|
|
111
114
|
end
|
|
@@ -113,7 +116,11 @@ module WavefrontCsvOutput
|
|
|
113
116
|
# We may be doing key=val or just val, depending on the formatter options
|
|
114
117
|
#
|
|
115
118
|
def tag_val(key, val)
|
|
116
|
-
formatopts.include?('tagkeys')
|
|
119
|
+
if formatopts.include?('tagkeys')
|
|
120
|
+
format('%<key>s=%<value>s', key: key, value: val)
|
|
121
|
+
else
|
|
122
|
+
val
|
|
123
|
+
end
|
|
117
124
|
end
|
|
118
125
|
end
|
|
119
126
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'securerandom'
|
|
2
4
|
require 'json'
|
|
3
5
|
|
|
@@ -27,8 +29,9 @@ module WavefrontHclOutput
|
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def open_output
|
|
30
|
-
format('resource "wavefront_
|
|
31
|
-
|
|
32
|
+
format('resource "wavefront_%<name>s" "%<uuid>s" {',
|
|
33
|
+
name: resource_name,
|
|
34
|
+
uuid: SecureRandom.uuid)
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
def close_output
|
|
@@ -48,6 +51,7 @@ module WavefrontHclOutput
|
|
|
48
51
|
#
|
|
49
52
|
def required_fields
|
|
50
53
|
return resp if hcl_fields.empty?
|
|
54
|
+
|
|
51
55
|
resp.select { |k, _v| hcl_fields.include?(k) }
|
|
52
56
|
end
|
|
53
57
|
|
|
@@ -65,7 +69,9 @@ module WavefrontHclOutput
|
|
|
65
69
|
|
|
66
70
|
quote_handler = :quote_value unless respond_to?(quote_handler)
|
|
67
71
|
|
|
68
|
-
format('
|
|
72
|
+
format(' %<key>s = %<value>s',
|
|
73
|
+
key: key.to_snake,
|
|
74
|
+
value: send(quote_handler, val))
|
|
69
75
|
end
|
|
70
76
|
|
|
71
77
|
# Tags need to be in an array. They aren't always called "tags"
|
|
@@ -86,7 +92,7 @@ module WavefrontHclOutput
|
|
|
86
92
|
def quote_value(val)
|
|
87
93
|
case val.class.to_s.to_sym
|
|
88
94
|
when :String
|
|
89
|
-
format('"
|
|
95
|
+
format('"%<value>s"', value: val.gsub(/\"/, '\"'))
|
|
90
96
|
else
|
|
91
97
|
val
|
|
92
98
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'base'
|
|
2
4
|
require_relative 'stdlib/string'
|
|
3
5
|
require_relative 'stdlib/array'
|
|
@@ -54,7 +56,9 @@ module WavefrontHclOutput
|
|
|
54
56
|
fields = %w[units name description]
|
|
55
57
|
|
|
56
58
|
lines = chart.each_with_object([]) do |(k, v), a|
|
|
57
|
-
|
|
59
|
+
next unless fields.include?(k)
|
|
60
|
+
|
|
61
|
+
a.<< format('%<key>s = %<value>s', key: k, value: quote_value(v))
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
lines.<< "source = #{handle_sources(chart[:sources])}"
|
|
@@ -66,17 +70,22 @@ module WavefrontHclOutput
|
|
|
66
70
|
end
|
|
67
71
|
|
|
68
72
|
def handle_source(source)
|
|
69
|
-
fields = %w[name query disabled scatterPlotSource querybuilderEnabled
|
|
70
|
-
sourceDescription]
|
|
71
|
-
|
|
72
73
|
source.each_with_object([]) do |(k, v), a|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
next unless source_fields.include?(k)
|
|
75
|
+
|
|
76
|
+
k = 'queryBuilderEnabled' if k == 'querybuilderEnabled'
|
|
77
|
+
|
|
78
|
+
a.<< format('%<key>s = %<value>s',
|
|
79
|
+
key: k.to_snake,
|
|
80
|
+
value: quote_value(v))
|
|
77
81
|
end.to_hcl_obj(14)
|
|
78
82
|
end
|
|
79
83
|
|
|
84
|
+
def source_fields
|
|
85
|
+
%w[name query disabled scatterPlotSource querybuilderEnabled
|
|
86
|
+
sourceDescription]
|
|
87
|
+
end
|
|
88
|
+
|
|
80
89
|
def qhandle_sections(val)
|
|
81
90
|
val
|
|
82
91
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'wavefront-sdk/stdlib/hash'
|
|
2
4
|
require_relative '../csv/base'
|
|
3
5
|
|
|
@@ -30,19 +32,20 @@ module WavefrontWavefrontOutput
|
|
|
30
32
|
def query_output
|
|
31
33
|
check_query_response
|
|
32
34
|
|
|
33
|
-
resp[:timeseries].each_with_object(
|
|
35
|
+
resp[:timeseries].each_with_object([]) do |ts, a|
|
|
34
36
|
ts[:data].each do |point|
|
|
35
37
|
a.<< wavefront_format(ts[:label],
|
|
36
38
|
point[1],
|
|
37
39
|
point[0],
|
|
38
40
|
ts[:host],
|
|
39
|
-
ts[:tags])
|
|
41
|
+
ts[:tags])
|
|
40
42
|
end
|
|
41
|
-
end
|
|
43
|
+
end.join("\n")
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
def wavefront_format(path, value, timestamp, source, tags = nil)
|
|
45
|
-
arr = [path, value, timestamp, format('source
|
|
47
|
+
arr = [path, value, timestamp, format('source=%<source>s',
|
|
48
|
+
source: source)]
|
|
46
49
|
arr.<< tags.to_wf_tag if tags && !tags.empty?
|
|
47
50
|
arr.join(' ')
|
|
48
51
|
end
|