kennel 1.98.2 → 1.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +2 -2
- data/lib/kennel/models/monitor.rb +35 -15
- data/lib/kennel/models/synthetic_test.rb +1 -1
- data/lib/kennel/version.rb +1 -1
- data/template/Readme.md +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0363ce2c85e194b4c6eca7e657a614d3eb0e27d7c0a5f4a55871bf39fc90f5f9
|
4
|
+
data.tar.gz: 075f01f5fa4f153f1a8c07ec000b7abf246e3c0dd9082d5709661240191b07f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
```
|
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::
|
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
|
-
|
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
|
data/lib/kennel/version.rb
CHANGED
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
|
-
```
|
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::
|
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.
|
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-
|
11
|
+
date: 2021-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|