kennel 1.98.2 → 1.99.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94cb1a40566de5e275526cfb3c28b8c36394ca22edab465493ace5107037f728
4
- data.tar.gz: d1adb172f9d04b610e76538eb1ce1fc68bc7a4615554819eb98bb5def0d9cc8f
3
+ metadata.gz: 0363ce2c85e194b4c6eca7e657a614d3eb0e27d7c0a5f4a55871bf39fc90f5f9
4
+ data.tar.gz: 075f01f5fa4f153f1a8c07ec000b7abf246e3c0dd9082d5709661240191b07f1
5
5
  SHA512:
6
- metadata.gz: 34d0f7967089bbc6bc7e9fdd8321ce6264c40d637f1e5e3bfd8be46ea3a69aad1e8894818b4f2af814d290456248dcd7d646a141fc27011eca472638cfed73f6
7
- data.tar.gz: b48cc148859210b9af80e6ecfcfc8d3fbbbe3895bd28ae071cc3459eee353b5e0976df0e9ea0927ed196cb52be83f68e9e0d02b21503e8523101101a263fb61d
6
+ metadata.gz: 6834defb05ea8844a19fdaa80a8e3cb7154305bbf3dbc6a66c24d76cc4b050305020c14ca7712a105d1514c421cf4a1f4674b9dfccc93b694e17daba8d8abf8b
7
+ data.tar.gz: 87f2c790faa21b2e63beaca026c565e6c940aa9dae0cc624b7060d81ed4b6cfce7894c77ccf56b60751a9fb3d1ed0b1dfc2c2c27a893ea88e0097b2d44138a05
data/Readme.md CHANGED
@@ -206,7 +206,7 @@ removing the `id` will cause kennel to create a new resource in datadog.
206
206
  Having many projects (and their sub-resources) can quickly get out of hand.
207
207
 
208
208
  Use this class structure to keep things organized:
209
- ```ruby
209
+ ```Ruby
210
210
  # projects/project_a/base.rb
211
211
  module ProjectA
212
212
  class Base < Kennel::Models::Project
@@ -217,7 +217,7 @@ module ProjectA
217
217
  # projects/project_a/monitors/foo_alert.rb
218
218
  module ProjectA
219
219
  module Monitors
220
- class FooAlert < Kennel::Modesl::Monitor
220
+ class FooAlert < Kennel::Models::Monitor
221
221
  ...
222
222
  ```
223
223
 
@@ -214,27 +214,47 @@ module Kennel
214
214
  end
215
215
 
216
216
  if ["query alert", "service check"].include?(type) # TODO: most likely more types need this
217
- # verify is_match/is_exact_match uses available variables
218
- message = data.fetch(:message)
219
- used = message.scan(/{{\s*([#^]is(?:_exact)?_match)\s*([^\s}]+)/)
220
- if used.any?
221
- allowed = data.fetch(:query)[/by\s*[({]([^})]+)[})]/, 1]
222
- .to_s.gsub(/["']/, "").split(/\s*,\s*/)
223
- .map! { |w| %("#{w}.name") }
224
- used.uniq.each do |match, group|
225
- next if allowed.include?(group)
226
- invalid!(
227
- "#{match} used with #{group}, but can only be used with #{allowed.join(", ")}. " \
228
- "Group the query by #{group.sub(".name", "").tr('"', "")} or change the #{match}"
229
- )
230
- end
231
- end
217
+ validate_message_variables(data)
232
218
  end
233
219
 
234
220
  unless ALLOWED_PRIORITY_CLASSES.include?(priority.class)
235
221
  invalid! "priority needs to be an Integer"
236
222
  end
237
223
  end
224
+
225
+ # verify is_match/is_exact_match and {{foo.name}} uses available variables
226
+ def validate_message_variables(data)
227
+ message = data.fetch(:message)
228
+
229
+ used =
230
+ message.scan(/{{\s*(?:[#^]is(?:_exact)?_match)\s*"([^\s}]+)"/) + # {{#is_match "environment.name" "production"}}
231
+ message.scan(/{{\s*([^}]+\.name)\s*}}/) # Pod {{pod.name}} failed
232
+ return if used.empty?
233
+ used.flatten!(1)
234
+ used.uniq!
235
+
236
+ # TODO
237
+ # - also match without by
238
+ # - separate parsers for query and service
239
+ # - service must always allow `host`, maybe others
240
+ return unless match = data.fetch(:query).match(/(?:{([^}]*)}\s*)?by\s*[({]([^})]+)[})]/)
241
+
242
+ allowed =
243
+ match[1].to_s.split(/\s*,\s*/).map { |k| k.split(":", 2)[-2] } + # {a:b} -> a TODO: does not work for service check
244
+ match[2].to_s.gsub(/["']/, "").split(/\s*,\s*/) # by {a} -> a
245
+
246
+ allowed.compact!
247
+ allowed.uniq!
248
+ allowed.map! { |w| "#{w.tr('"', "")}.name" }
249
+
250
+ forbidden = used - allowed
251
+ return if forbidden.empty?
252
+
253
+ invalid! <<~MSG.rstrip
254
+ Used #{forbidden.join(", ")} in the message, but can only be used with #{allowed.join(", ")}.
255
+ Group or filter the query by #{forbidden.map { |f| f.sub(".name", "") }.join(", ")} to use it.
256
+ MSG
257
+ end
238
258
  end
239
259
  end
240
260
  end
@@ -26,7 +26,7 @@ module Kennel
26
26
  type: type,
27
27
  subtype: subtype,
28
28
  options: options,
29
- name: name,
29
+ name: "#{name}#{LOCK}",
30
30
  locations: locations == :all ? LOCATIONS : locations
31
31
  }
32
32
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.98.2"
3
+ VERSION = "1.99.0"
4
4
  end
data/template/Readme.md CHANGED
@@ -189,7 +189,7 @@ removing the `id` will cause kennel to create a new resource in datadog.
189
189
  Having many projects (and their sub-resources) can quickly get out of hand.
190
190
 
191
191
  Use this class structure to keep things organized:
192
- ```ruby
192
+ ```Ruby
193
193
  # projects/project_a/base.rb
194
194
  module ProjectA
195
195
  class Base < Kennel::Models::Project
@@ -200,7 +200,7 @@ module ProjectA
200
200
  # projects/project_a/monitors/foo_alert.rb
201
201
  module ProjectA
202
202
  module Monitors
203
- class FooAlert < Kennel::Modesl::Monitor
203
+ class FooAlert < Kennel::Models::Monitor
204
204
  ...
205
205
  ```
206
206
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.98.2
4
+ version: 1.99.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-29 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday