wavefront-sdk 1.6.0 → 1.6.1
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/.rubocop.yml +9 -2
- data/HISTORY.md +11 -0
- data/lib/wavefront-sdk/base.rb +31 -46
- data/lib/wavefront-sdk/base_write.rb +28 -29
- data/lib/wavefront-sdk/event.rb +11 -7
- data/lib/wavefront-sdk/exception.rb +1 -0
- data/lib/wavefront-sdk/externallink.rb +2 -1
- data/lib/wavefront-sdk/logger.rb +65 -0
- data/lib/wavefront-sdk/metric.rb +5 -6
- data/lib/wavefront-sdk/mixins.rb +16 -5
- data/lib/wavefront-sdk/response.rb +36 -25
- data/lib/wavefront-sdk/search.rb +2 -2
- data/lib/wavefront-sdk/stdlib/hash.rb +6 -1
- data/lib/wavefront-sdk/validators.rb +123 -115
- data/lib/wavefront-sdk/version.rb +1 -1
- data/lib/wavefront-sdk/write.rb +0 -1
- data/spec/wavefront-sdk/base_write_spec.rb +82 -0
- data/spec/wavefront-sdk/logger_spec.rb +62 -0
- data/spec/wavefront-sdk/mixins_spec.rb +17 -0
- data/spec/wavefront-sdk/resources/dummy_points.rb +20 -0
- data/spec/wavefront-sdk/write_spec.rb +3 -79
- data/wavefront-sdk.gemspec +1 -0
- metadata +9 -2
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'map'
|
3
3
|
require_relative 'exception'
|
4
|
+
require_relative 'mixins'
|
4
5
|
|
5
6
|
module Wavefront
|
7
|
+
#
|
6
8
|
# Every API path has its own response class, which allows us to
|
7
9
|
# provide a stable interface. If the API changes underneath us,
|
8
10
|
# the SDK will break in a predictable way, throwing a
|
@@ -18,31 +20,36 @@ module Wavefront
|
|
18
20
|
# which allows
|
19
21
|
#
|
20
22
|
class Response
|
21
|
-
|
23
|
+
include Wavefront::Mixins
|
24
|
+
attr_reader :status, :response, :opts, :logger
|
22
25
|
|
23
26
|
# Create and return a Wavefront::Response object
|
24
27
|
# @param json [String] a raw response body from the Wavefront API
|
25
28
|
# @param status [Integer] HTTP return code from the API
|
26
|
-
# @param
|
27
|
-
# message if one is thrown
|
29
|
+
# @param opts [Hash] options passed through from calling class.
|
28
30
|
# @raise [Wavefront::Exception::UnparseableResponse] if the
|
29
31
|
# response cannot be parsed. This may be because the API
|
30
32
|
# has changed underneath us.
|
31
33
|
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
raw = raw_response(json, status)
|
36
|
-
@status = build_status(raw, status)
|
34
|
+
def initialize(json, status, opts = {})
|
35
|
+
raw = raw_response(json, status)
|
36
|
+
@status = build_status(raw, status)
|
37
37
|
@response = build_response(raw)
|
38
|
+
@opts = opts
|
39
|
+
|
40
|
+
setup_opts
|
38
41
|
|
39
|
-
|
42
|
+
logger.log(self, :debug)
|
40
43
|
rescue StandardError => e
|
41
|
-
|
42
|
-
|
44
|
+
logger.log(format("could not parse:\n%s", json), :debug)
|
45
|
+
logger.log(e.message.to_s, :debug)
|
43
46
|
raise Wavefront::Exception::UnparseableResponse
|
44
47
|
end
|
45
48
|
|
49
|
+
def setup_opts
|
50
|
+
@logger = Wavefront::Logger.new(opts)
|
51
|
+
end
|
52
|
+
|
46
53
|
def raw_response(json, status)
|
47
54
|
json.empty? ? {} : JSON.parse(json, symbolize_names: true)
|
48
55
|
rescue StandardError
|
@@ -61,7 +68,7 @@ module Wavefront
|
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
64
|
-
# Status
|
71
|
+
# Status types are used by the Wavefront::Response class
|
65
72
|
#
|
66
73
|
class Type
|
67
74
|
#
|
@@ -79,24 +86,28 @@ module Wavefront
|
|
79
86
|
# request
|
80
87
|
#
|
81
88
|
class Status
|
82
|
-
attr_reader :
|
89
|
+
attr_reader :obj, :status
|
83
90
|
|
84
|
-
# @param
|
91
|
+
# @param response [Hash] the API response, turned into a hash
|
85
92
|
# @param status [Integer] HTTP status code
|
86
93
|
#
|
87
|
-
def initialize(
|
88
|
-
obj =
|
94
|
+
def initialize(response, status)
|
95
|
+
@obj = response.fetch(:status, response)
|
96
|
+
@status = status
|
97
|
+
end
|
98
|
+
|
99
|
+
def message
|
100
|
+
obj[:message] || nil
|
101
|
+
end
|
89
102
|
|
90
|
-
|
91
|
-
|
103
|
+
def code
|
104
|
+
obj[:code] || status
|
105
|
+
end
|
92
106
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
else
|
98
|
-
'ERROR'
|
99
|
-
end
|
107
|
+
def result
|
108
|
+
return obj[:result] if obj[:result]
|
109
|
+
return 'OK' if status.between?(200, 299)
|
110
|
+
'ERROR'
|
100
111
|
end
|
101
112
|
end
|
102
113
|
end
|
data/lib/wavefront-sdk/search.rb
CHANGED
@@ -94,8 +94,8 @@ module Wavefront
|
|
94
94
|
#
|
95
95
|
def raw_facet_search(entity = nil, body = nil, deleted = false,
|
96
96
|
facet = false)
|
97
|
-
raise ArgumentError unless entity.is_a?(String)
|
98
|
-
|
97
|
+
raise ArgumentError unless entity.is_a?(String) && body.is_a?(Hash)
|
98
|
+
|
99
99
|
path = [entity]
|
100
100
|
path.<< 'deleted' if deleted
|
101
101
|
path.<< facet ? facet : 'facets'
|
@@ -6,8 +6,13 @@ class Hash
|
|
6
6
|
# Convert a tag hash into a string. The quoting is recommended in
|
7
7
|
# the WF wire-format guide. No validation is performed here.
|
8
8
|
#
|
9
|
-
# rubocop:disable Style/FormatStringToken
|
10
9
|
def to_wf_tag
|
11
10
|
map { |k, v| format('%s="%s"', k, v.tagescape) }.join(' ')
|
12
11
|
end
|
12
|
+
|
13
|
+
# Drop any key-value pairs where the value is not truthy
|
14
|
+
#
|
15
|
+
def cleanse
|
16
|
+
select { |_k, v| v }
|
17
|
+
end
|
13
18
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# rubocop:disable Naming/UncommunicativeMethodParamName
|
2
1
|
require_relative 'constants'
|
3
2
|
require_relative 'exception'
|
4
3
|
|
@@ -18,8 +17,11 @@ module Wavefront
|
|
18
17
|
# @return true if it is valid
|
19
18
|
# @raise Wavefront::Exception::InvalidTemplate if not
|
20
19
|
#
|
21
|
-
def wf_link_template?(
|
22
|
-
|
20
|
+
def wf_link_template?(template)
|
21
|
+
if template.is_a?(String) &&
|
22
|
+
template.start_with?('http://', 'https://')
|
23
|
+
return true
|
24
|
+
end
|
23
25
|
|
24
26
|
raise Wavefront::Exception::InvalidLinkTemplate
|
25
27
|
end
|
@@ -27,15 +29,15 @@ module Wavefront
|
|
27
29
|
# Ensure the given argument is a valid Wavefront metric name, or
|
28
30
|
# path.
|
29
31
|
#
|
30
|
-
# @param
|
32
|
+
# @param metric [String] the metric name to validate
|
31
33
|
# @return True if the metric name is valid
|
32
34
|
# @raise Wavefront::Exception::InvalidMetricName if metric name
|
33
35
|
# is not valid.
|
34
36
|
#
|
35
|
-
def wf_metric_name?(
|
36
|
-
if
|
37
|
-
(
|
38
|
-
|
37
|
+
def wf_metric_name?(metric)
|
38
|
+
if metric.is_a?(String) && metric.size < 1024 &&
|
39
|
+
(metric.match(/^#{DELTA}?[\w\-\.]+$/) ||
|
40
|
+
metric.match(%r{^\"#{DELTA}?[\w\-\.\/,]+\"$}))
|
39
41
|
return true
|
40
42
|
end
|
41
43
|
|
@@ -45,40 +47,42 @@ module Wavefront
|
|
45
47
|
# Ensure the given argument is a valid name, for instance for an
|
46
48
|
# event. Names can contain, AFAIK, word characters.
|
47
49
|
#
|
48
|
-
# @param
|
50
|
+
# @param name [String] the name to validate
|
49
51
|
# @return true if the name is valid
|
50
52
|
# raise Wavefront::Exception::InvalidName if name is not valid
|
51
53
|
#
|
52
|
-
def wf_name?(
|
53
|
-
return true if
|
54
|
+
def wf_name?(name)
|
55
|
+
return true if name.is_a?(String) && name.size < 1024 && name =~ /^\w+$/
|
54
56
|
raise Wavefront::Exception::InvalidName
|
55
57
|
end
|
56
58
|
|
57
59
|
# Ensure the given argument is a valid string, for a tag name.
|
58
60
|
#
|
59
|
-
# @param
|
61
|
+
# @param str [String] the string name to validate
|
60
62
|
# @return True if the string is valid
|
61
63
|
# @raise Wavefront::Exception::InvalidString if string is not valid.
|
62
64
|
#
|
63
|
-
def wf_string?(
|
65
|
+
def wf_string?(str)
|
64
66
|
#
|
65
67
|
# Only allows PCRE "word" characters, spaces, full-stops and
|
66
68
|
# commas in tags and descriptions. This might be too restrictive,
|
67
69
|
# but if it is, this is the only place we need to change it.
|
68
70
|
#
|
69
|
-
|
71
|
+
if str.is_a?(String) && str.size < 1024 && str =~ /^[\-\w \.,]*$/
|
72
|
+
return true
|
73
|
+
end
|
70
74
|
|
71
75
|
raise Wavefront::Exception::InvalidString
|
72
76
|
end
|
73
77
|
|
74
78
|
# Ensure the given argument is a valid timestamp
|
75
79
|
#
|
76
|
-
# @param
|
80
|
+
# @param timestamp [DateTime] the timestamp name to validate
|
77
81
|
# @return True if the value is valid
|
78
82
|
# @raise Wavefront::Exception::InvalidTimestamp
|
79
83
|
#
|
80
|
-
def wf_ts?(
|
81
|
-
return true if
|
84
|
+
def wf_ts?(timestamp)
|
85
|
+
return true if timestamp.is_a?(Time) || timestamp.is_a?(Date)
|
82
86
|
raise Wavefront::Exception::InvalidTimestamp
|
83
87
|
end
|
84
88
|
|
@@ -87,24 +91,24 @@ module Wavefront
|
|
87
91
|
# say that the user doesn't want to send a point relating to 1ms
|
88
92
|
# after the epoch, or a thousand years in the future?
|
89
93
|
#
|
90
|
-
# @param
|
94
|
+
# @param timestamp [Integer] the timestamp name to validate
|
91
95
|
# @return True if the value is valid
|
92
96
|
# @raise Wavefront::Exception::InvalidTimestamp
|
93
97
|
#
|
94
|
-
def wf_ms_ts?(
|
95
|
-
return true if
|
98
|
+
def wf_ms_ts?(timestamp)
|
99
|
+
return true if timestamp.is_a?(Numeric)
|
96
100
|
raise Wavefront::Exception::InvalidTimestamp
|
97
101
|
end
|
98
102
|
|
99
103
|
# Ensure the given argument is a valid epoch timestamp. Again,
|
100
104
|
# no range checking.
|
101
105
|
#
|
102
|
-
# @param
|
106
|
+
# @param timestamp [String, Integer]
|
103
107
|
# @return True if the timestamp is valid
|
104
108
|
# @raise Wavefront::Exception::InvalidMaintenanceWindow
|
105
109
|
#
|
106
|
-
def wf_epoch?(
|
107
|
-
return true if
|
110
|
+
def wf_epoch?(timestamp)
|
111
|
+
return true if timestamp.is_a?(Numeric)
|
108
112
|
raise Wavefront::Exception::InvalidTimestamp
|
109
113
|
end
|
110
114
|
|
@@ -113,13 +117,13 @@ module Wavefront
|
|
113
117
|
# can contain letters, numbers, -, _ and :, and must be less
|
114
118
|
# than 256 characters long
|
115
119
|
#
|
116
|
-
# @param
|
120
|
+
# @param tags [String, Array] a tag or list of tags
|
117
121
|
# @return True if all tags are valid
|
118
122
|
# @raise Wavefront::Exception::InvalidTag
|
119
123
|
#
|
120
|
-
def wf_tag?(*
|
121
|
-
Array(*
|
122
|
-
unless
|
124
|
+
def wf_tag?(*tags)
|
125
|
+
Array(*tags).each do |tag|
|
126
|
+
unless tag.is_a?(String) && tag.size < 255 && tag =~ /^[\w:\-\.]+$/
|
123
127
|
raise Wavefront::Exception::InvalidTag
|
124
128
|
end
|
125
129
|
end
|
@@ -130,29 +134,27 @@ module Wavefront
|
|
130
134
|
# Ensure the given argument is a valid Wavefront value. Can be
|
131
135
|
# any form of Numeric, including standard notation.
|
132
136
|
#
|
133
|
-
# @param
|
137
|
+
# @param value [Numeric] the source name to validate
|
134
138
|
# @return True if the value is valid
|
135
139
|
# @raise Wavefront::Exception::InvalidValue if the value is not valid
|
136
140
|
#
|
137
|
-
def wf_value?(
|
138
|
-
return true if
|
141
|
+
def wf_value?(value)
|
142
|
+
return true if value.is_a?(Numeric)
|
139
143
|
raise Wavefront::Exception::InvalidMetricValue
|
140
144
|
end
|
141
145
|
|
142
146
|
# Ensure the given argument is a valid version number
|
143
147
|
#
|
144
|
-
# @param
|
148
|
+
# @param version [Integer] the version number to validate
|
145
149
|
# @return True if the version is valid
|
146
150
|
# @raise Wavefront::Exception::InvalidVersion if the alert ID is
|
147
151
|
# not valid
|
148
152
|
#
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
return true if v.is_a?(Integer) && v > 0
|
153
|
+
def wf_version?(version)
|
154
|
+
version = version.to_i if version.is_a?(String) && version =~ /^\d+$/
|
155
|
+
return true if version.is_a?(Integer) && version > 0
|
153
156
|
raise Wavefront::Exception::InvalidVersion
|
154
157
|
end
|
155
|
-
# rubocop:enable Style/NumericPredicate
|
156
158
|
|
157
159
|
# Ensure a hash of key:value point tags are value. Not to be
|
158
160
|
# confused with source tags.
|
@@ -167,28 +169,30 @@ module Wavefront
|
|
167
169
|
tags.each { |k, v| wf_point_tag?(k, v) }
|
168
170
|
end
|
169
171
|
|
170
|
-
# Validate a single point tag, probably on behalf of
|
171
|
-
#
|
172
|
-
# @param
|
173
|
-
# @param v [String] tag value
|
172
|
+
# Validate a single point tag, probably on behalf of #wf_point_tags?
|
173
|
+
# @param key [String] tag key
|
174
|
+
# @param val [String] tag value
|
174
175
|
# @raise Wavefront::Exception::InvalidTag if any tag is not valid
|
175
176
|
# @return nil
|
176
177
|
#
|
177
|
-
def wf_point_tag?(
|
178
|
-
|
179
|
-
|
178
|
+
def wf_point_tag?(key, val)
|
179
|
+
if key && val && (key.size + val.size < 254) &&
|
180
|
+
key =~ /^[\w\-\.:]+$/ && val !~ /\\$/
|
181
|
+
return
|
182
|
+
end
|
183
|
+
|
180
184
|
raise Wavefront::Exception::InvalidTag
|
181
185
|
end
|
182
186
|
|
183
187
|
# Ensure the given argument is a valid Wavefront proxy ID
|
184
188
|
#
|
185
|
-
# @param
|
189
|
+
# @param id [String] the proxy ID to validate
|
186
190
|
# @return True if the proxy ID is valid
|
187
191
|
# @raise Wavefront::Exception::InvalidProxyId if the proxy ID
|
188
192
|
# is not valid
|
189
193
|
#
|
190
|
-
def wf_proxy_id?(
|
191
|
-
if
|
194
|
+
def wf_proxy_id?(id)
|
195
|
+
if id.is_a?(String) && id.match(
|
192
196
|
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
|
193
197
|
)
|
194
198
|
return true
|
@@ -201,27 +205,27 @@ module Wavefront
|
|
201
205
|
# Alerts are identified by the epoch-nanosecond at which they
|
202
206
|
# were created.
|
203
207
|
#
|
204
|
-
# @param
|
208
|
+
# @param id [String] the alert ID to validate
|
205
209
|
# @return True if the alert ID is valid
|
206
210
|
# @raise Wavefront::Exception::InvalidAlertId if the alert ID is
|
207
211
|
# not valid
|
208
212
|
#
|
209
|
-
def wf_alert_id?(
|
210
|
-
|
211
|
-
return true if
|
213
|
+
def wf_alert_id?(id)
|
214
|
+
id = id.to_s if id.is_a?(Numeric)
|
215
|
+
return true if id.is_a?(String) && id.match(/^\d{13}$/)
|
212
216
|
raise Wavefront::Exception::InvalidAlertId
|
213
217
|
end
|
214
218
|
|
215
219
|
# Ensure the given argument is a valid Wavefront cloud
|
216
220
|
# integration ID
|
217
221
|
#
|
218
|
-
# @param
|
222
|
+
# @param id [String] the integration name to validate
|
219
223
|
# @return True if the integration name is valid
|
220
224
|
# @raise Wavefront::Exception::InvalidCloudIntegrationId if the
|
221
225
|
# integration ID is not valid
|
222
226
|
#
|
223
|
-
def wf_cloudintegration_id?(
|
224
|
-
if
|
227
|
+
def wf_cloudintegration_id?(id)
|
228
|
+
if id.is_a?(String) && id.match(
|
225
229
|
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
|
226
230
|
)
|
227
231
|
return true
|
@@ -234,13 +238,13 @@ module Wavefront
|
|
234
238
|
# in a dashboard name. For now I'm going to assume up to 255 word
|
235
239
|
# characters.
|
236
240
|
#
|
237
|
-
# @param
|
241
|
+
# @param id [String] the dashboard ID to validate
|
238
242
|
# @return true if the dashboard ID is valid
|
239
243
|
# @raise Wavefront::Exception::InvalidDashboardID if the
|
240
244
|
# dashboard ID is not valid
|
241
245
|
#
|
242
|
-
def wf_dashboard_id?(
|
243
|
-
return true if
|
246
|
+
def wf_dashboard_id?(id)
|
247
|
+
return true if id.is_a?(String) && id.size < 256 && id.match(/^[\w\-]+$/)
|
244
248
|
raise Wavefront::Exception::InvalidDashboardId
|
245
249
|
end
|
246
250
|
|
@@ -248,13 +252,13 @@ module Wavefront
|
|
248
252
|
# are the millisecond epoch timestamp at which the derived
|
249
253
|
# metric was created.
|
250
254
|
#
|
251
|
-
# @param
|
255
|
+
# @param id [String, Integer]
|
252
256
|
# @return True if the ID is valid
|
253
257
|
# @raise Wavefront::Exception::InvalidDerivedMetricId
|
254
258
|
#
|
255
|
-
def wf_derivedmetric_id?(
|
256
|
-
|
257
|
-
return true if
|
259
|
+
def wf_derivedmetric_id?(id)
|
260
|
+
id = id.to_s if id.is_a?(Numeric)
|
261
|
+
return true if id.is_a?(String) && id =~ /^\d{13}$/
|
258
262
|
|
259
263
|
raise Wavefront::Exception::InvalidDerivedMetricId
|
260
264
|
end
|
@@ -263,25 +267,25 @@ module Wavefront
|
|
263
267
|
# an epoch-millisecond timestamp followed by a : followed by the
|
264
268
|
# name of the event.
|
265
269
|
#
|
266
|
-
# @param
|
270
|
+
# @param id [String] the event ID to validate
|
267
271
|
# @return true if the event ID is valid
|
268
272
|
# @raise Wavefront::Exception::InvalidEventID if the
|
269
273
|
# event ID is not valid
|
270
274
|
#
|
271
|
-
def wf_event_id?(
|
272
|
-
return true if
|
275
|
+
def wf_event_id?(id)
|
276
|
+
return true if id.is_a?(String) && id =~ /^\d{13}:.+/
|
273
277
|
raise Wavefront::Exception::InvalidEventId
|
274
278
|
end
|
275
279
|
|
276
280
|
# Ensure the given argument is a valid external Link ID
|
277
281
|
#
|
278
|
-
# @param
|
282
|
+
# @param id [String] the external link ID to validate
|
279
283
|
# @return True if the link ID is valid
|
280
284
|
# @raise Wavefront::Exception::InvalidExternalLinkId if the
|
281
285
|
# link ID is not valid
|
282
286
|
#
|
283
|
-
def wf_link_id?(
|
284
|
-
return true if
|
287
|
+
def wf_link_id?(id)
|
288
|
+
return true if id.is_a?(String) && id =~ /^\w{16}$/
|
285
289
|
raise Wavefront::Exception::InvalidExternalLinkId
|
286
290
|
end
|
287
291
|
|
@@ -289,155 +293,159 @@ module Wavefront
|
|
289
293
|
# IDs are the millisecond epoch timestamp at which the window
|
290
294
|
# was created.
|
291
295
|
#
|
292
|
-
# @param
|
296
|
+
# @param id [String, Integer]
|
293
297
|
# @return True if the ID is valid
|
294
298
|
# @raise Wavefront::Exception::InvalidMaintenanceWindowId
|
295
299
|
#
|
296
|
-
def wf_maintenance_window_id?(
|
297
|
-
|
298
|
-
return true if
|
300
|
+
def wf_maintenance_window_id?(id)
|
301
|
+
id = id.to_s if id.is_a?(Numeric)
|
302
|
+
return true if id.is_a?(String) && id =~ /^\d{13}$/
|
299
303
|
|
300
304
|
raise Wavefront::Exception::InvalidMaintenanceWindowId
|
301
305
|
end
|
302
306
|
|
303
307
|
# Ensure the given argument is a valid alert severity
|
304
308
|
#
|
305
|
-
# @param
|
309
|
+
# @param severity [String] severity
|
306
310
|
# @return true if valid
|
307
|
-
# @raise Wavefront::Exceptions::InvalidAlertSeverity if not
|
308
|
-
# valid
|
311
|
+
# @raise Wavefront::Exceptions::InvalidAlertSeverity if not valid
|
309
312
|
#
|
310
|
-
def wf_alert_severity?(
|
311
|
-
return true if %w[INFO SMOKE WARN SEVERE].include?(
|
313
|
+
def wf_alert_severity?(severity)
|
314
|
+
return true if %w[INFO SMOKE WARN SEVERE].include?(severity)
|
312
315
|
raise Wavefront::Exception::InvalidAlertSeverity
|
313
316
|
end
|
314
317
|
|
315
318
|
# Ensure the given argument is a valid message ID
|
316
319
|
#
|
317
|
-
# @param
|
320
|
+
# @param id [String] message ID
|
318
321
|
# @return true if valid
|
319
|
-
# @raise Wavefront::Exceptions::InvalidMessageId if not
|
320
|
-
# valid
|
322
|
+
# @raise Wavefront::Exceptions::InvalidMessageId if not valid
|
321
323
|
#
|
322
|
-
def wf_message_id?(
|
323
|
-
return true if
|
324
|
+
def wf_message_id?(id)
|
325
|
+
return true if id.is_a?(String) && id =~ /^\w+::\w+$/
|
324
326
|
raise Wavefront::Exception::InvalidMessageId
|
325
327
|
end
|
326
328
|
|
327
329
|
# Ensure the given argument is a valid query granularity
|
328
330
|
#
|
329
|
-
# @param
|
331
|
+
# @param granularity [String] granularity
|
330
332
|
# @return true if valid
|
331
333
|
# @raise Wavefront::Exceptions::InvalidGranularity if not
|
332
334
|
# valid
|
333
335
|
#
|
334
|
-
def wf_granularity?(
|
335
|
-
return true if %w[d h m s].include?(
|
336
|
+
def wf_granularity?(granularity)
|
337
|
+
return true if %w[d h m s].include?(granularity.to_s)
|
336
338
|
raise Wavefront::Exception::InvalidGranularity
|
337
339
|
end
|
338
340
|
|
339
341
|
# Ensure the given argument is a valid saved search ID.
|
340
342
|
#
|
341
|
-
# @param
|
343
|
+
# @param id [String] saved search ID
|
342
344
|
# @return true if valid
|
343
345
|
# @raise Wavefront::Exceptions::InvalidSavedSearchId if not valid
|
344
346
|
#
|
345
|
-
def wf_savedsearch_id?(
|
346
|
-
return true if
|
347
|
+
def wf_savedsearch_id?(id)
|
348
|
+
return true if id.is_a?(String) && id =~ /^\w{8}$/
|
347
349
|
raise Wavefront::Exception::InvalidSavedSearchId
|
348
350
|
end
|
349
351
|
|
350
352
|
# Ensure the given argument is a valid saved search entity type.
|
351
353
|
#
|
352
|
-
# @param
|
354
|
+
# @param id [String] entity type
|
353
355
|
# @return true if valid
|
354
356
|
# @raise Wavefront::Exceptions::InvalidSavedSearchEntity if not
|
355
357
|
# valid
|
356
358
|
#
|
357
|
-
def wf_savedsearch_entity?(
|
359
|
+
def wf_savedsearch_entity?(id)
|
358
360
|
return true if %w[DASHBOARD ALERT MAINTENANCE_WINDOW
|
359
361
|
NOTIFICANT EVENT SOURCE EXTERNAL_LINK AGENT
|
360
|
-
CLOUD_INTEGRATION].include?(
|
362
|
+
CLOUD_INTEGRATION].include?(id)
|
361
363
|
raise Wavefront::Exception::InvalidSavedSearchEntity
|
362
364
|
end
|
363
365
|
|
364
366
|
# Ensure the given argument is a valid Wavefront source name
|
365
367
|
#
|
366
|
-
# @param
|
368
|
+
# @param source [String] the source name to validate
|
367
369
|
# @return True if the source name is valid
|
368
370
|
# @raise Wavefront::Exception::InvalidSourceId if the source name
|
369
371
|
# is not valid
|
370
372
|
#
|
371
|
-
def wf_source_id?(
|
372
|
-
|
373
|
+
def wf_source_id?(source)
|
374
|
+
if source.is_a?(String) && source.match(/^[\w\.\-]+$/) &&
|
375
|
+
source.size < 1024
|
376
|
+
return true
|
377
|
+
end
|
373
378
|
|
374
379
|
raise Wavefront::Exception::InvalidSourceId
|
375
380
|
end
|
376
381
|
|
377
382
|
# Ensure the given argument is a valid user.
|
378
383
|
#
|
379
|
-
# @param
|
384
|
+
# @param user [String] user identifier
|
380
385
|
# @return true if valid
|
381
386
|
# @raise Wavefront::Exceptions::InvalidUserId if not valid
|
382
387
|
#
|
383
|
-
def wf_user_id?(
|
384
|
-
|
385
|
-
|
388
|
+
def wf_user_id?(user)
|
389
|
+
if user.is_a?(String) &&
|
390
|
+
user =~ /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
|
391
|
+
return true
|
392
|
+
end
|
393
|
+
|
386
394
|
raise Wavefront::Exception::InvalidUserId
|
387
395
|
end
|
388
396
|
|
389
397
|
# Ensure the given argument is a valid webhook ID.
|
390
398
|
#
|
391
|
-
# @param
|
399
|
+
# @param id [String] webhook ID
|
392
400
|
# @return true if valid
|
393
401
|
# @raise Wavefront::Exceptions::InvalidWebhook if not valid
|
394
402
|
#
|
395
|
-
def wf_webhook_id?(
|
396
|
-
return true if
|
403
|
+
def wf_webhook_id?(id)
|
404
|
+
return true if id.is_a?(String) && id =~ /^[a-zA-Z0-9]{16}$/
|
397
405
|
raise Wavefront::Exception::InvalidWebhookId
|
398
406
|
end
|
399
407
|
|
400
408
|
# Validate a point so it conforms to the standard described in
|
401
409
|
# https://community.wavefront.com/docs/DOC-1031
|
402
410
|
#
|
403
|
-
# @param
|
411
|
+
# @param point [Hash] description of point
|
404
412
|
# @return true if valie
|
405
413
|
# @raise whichever exception is thrown first when validating
|
406
414
|
# each component of the point.
|
407
415
|
#
|
408
|
-
def wf_point?(
|
409
|
-
wf_metric_name?(
|
410
|
-
wf_value?(
|
411
|
-
wf_epoch?(
|
412
|
-
wf_source_id?(
|
413
|
-
wf_point_tags?(
|
416
|
+
def wf_point?(point)
|
417
|
+
wf_metric_name?(point[:path])
|
418
|
+
wf_value?(point[:value])
|
419
|
+
wf_epoch?(point[:ts]) if point[:ts]
|
420
|
+
wf_source_id?(point[:source]) if point[:source]
|
421
|
+
wf_point_tags?(point[:tags]) if point[:tags]
|
414
422
|
true
|
415
423
|
end
|
416
424
|
|
417
|
-
# Ensure the given argument is a valid Wavefront
|
418
|
-
# notificant ID.
|
425
|
+
# Ensure the given argument is a valid Wavefront notificant ID.
|
419
426
|
#
|
420
|
-
# @param
|
421
|
-
# @return True if the notificant
|
427
|
+
# @param id [String] the notificant ID to validate
|
428
|
+
# @return True if the notificant ID is valid
|
422
429
|
# @raise Wavefront::Exception::InvalidNotificantId if the
|
423
430
|
# notificant ID is not valid
|
424
431
|
#
|
425
|
-
def wf_notificant_id?(
|
426
|
-
return true if
|
432
|
+
def wf_notificant_id?(id)
|
433
|
+
return true if id.is_a?(String) && id =~ /^\w{16}$/
|
427
434
|
raise Wavefront::Exception::InvalidNotificantId
|
428
435
|
end
|
429
436
|
|
430
437
|
# Ensure the given argument is a valid Wavefront
|
431
438
|
# integration ID. These appear to be lower-case strings.
|
432
439
|
#
|
433
|
-
# @param
|
440
|
+
# @param id [String] the integration ID to validate
|
434
441
|
# @return True if the integration name is valid
|
435
442
|
# @raise Wavefront::Exception::InvalidIntegrationId if the
|
436
443
|
# integration ID is not valid
|
437
444
|
#
|
438
|
-
def wf_integration_id?(
|
439
|
-
return true if
|
445
|
+
def wf_integration_id?(id)
|
446
|
+
return true if id.is_a?(String) && id =~ /^[a-z0-9]+$/
|
440
447
|
raise Wavefront::Exception::InvalidIntegrationId
|
441
448
|
end
|
442
449
|
end
|
450
|
+
# rubocop:enable Metrics/ModuleLength
|
443
451
|
end
|