kennel 1.119.0 → 1.121.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: 67b43081a187354fb146269d929da674d533263b44b3f2cee00b2baa7cc8bc57
4
- data.tar.gz: c14b369716513a92791496a92c29c7648499d0a06f05e34d36c628f4a9bb9305
3
+ metadata.gz: bb8230c7d3bd7abc24f4c0a1b18de96b7ef892d2f54bdc2ccc010d9ba10a80c6
4
+ data.tar.gz: b2793e6ac6a79cdb809f77f749b5210501e48bfefb5baa38c2f16ed7043c75ed
5
5
  SHA512:
6
- metadata.gz: b0eb58d97d4be73227f791379f623a188ab45256749cd4b11a969444a8598d8b30f70490c12dbad12ff0a46d42f2ff1820998304b7167cc11a9876e8aaef06cc
7
- data.tar.gz: cb38270a791164a92a06522921234838fe4e944e54ebd53a54c00939d531861847de0d4b6cef8d3605a9b2692874e9ac5715ce4fa4df07550f26094e810be845
6
+ metadata.gz: 24d20844e2b74bee9f13c2daf5a80d4a366e7251b826b61e1dd4d5172918cf5fc5b5d694bc7604c7f64d3543150a2f1a8d1884c5c6f462e48b52b74a51267c5f
7
+ data.tar.gz: 1c52708d519c711b55aa62cb9016ec7124b52634526343ee4140422223e90da351aadd466238bff5e07031dac8b14312cafecde3917e7308193d2c3af9119aeb
data/lib/kennel/filter.rb CHANGED
@@ -2,35 +2,48 @@
2
2
 
3
3
  module Kennel
4
4
  class Filter
5
+ attr_reader :project_filter, :tracking_id_filter
6
+
5
7
  def initialize
6
- project_filter
7
- tracking_id_filter
8
+ # build early so we fail fast on invalid user input
9
+ @tracking_id_filter = build_tracking_id_filter
10
+ @project_filter = build_project_filter
11
+ end
12
+
13
+ def filter_projects(projects)
14
+ filter_resources(projects, :kennel_id, project_filter, "projects", "PROJECT")
8
15
  end
9
16
 
10
- def project_filter
11
- projects = ENV["PROJECT"]&.split(",")&.sort&.uniq
12
- tracking_projects = tracking_id_filter&.map { |id| id.split(":", 2).first }&.sort&.uniq
13
- if projects && tracking_projects && projects != tracking_projects
17
+ def filter_parts(parts)
18
+ filter_resources(parts, :tracking_id, tracking_id_filter, "resources", "TRACKING_ID")
19
+ end
20
+
21
+ private
22
+
23
+ def build_project_filter
24
+ project_names = ENV["PROJECT"]&.split(",")&.sort&.uniq
25
+ tracking_project_names = tracking_id_filter&.map { |id| id.split(":", 2).first }&.sort&.uniq
26
+ if project_names && tracking_project_names && project_names != tracking_project_names
14
27
  raise "do not set PROJECT= when using TRACKING_ID="
15
28
  end
16
- (projects || tracking_projects)
29
+ (project_names || tracking_project_names)
17
30
  end
18
31
 
19
- def tracking_id_filter
32
+ def build_tracking_id_filter
20
33
  (tracking_id = ENV["TRACKING_ID"]) && tracking_id.split(",").sort.uniq
21
34
  end
22
35
 
23
- def self.filter_resources!(resources, by, against, name, env)
24
- return unless against
36
+ def filter_resources(resources, by, expected, name, env)
37
+ return resources unless expected
25
38
 
26
- against = against.uniq
39
+ expected = expected.uniq
27
40
  before = resources.dup
28
- resources.select! { |p| against.include?(p.send(by)) }
41
+ resources = resources.select { |p| expected.include?(p.send(by)) }
29
42
  keeping = resources.uniq(&by).size
30
- return if keeping == against.size
43
+ return resources if keeping == expected.size
31
44
 
32
45
  raise <<~MSG.rstrip
33
- #{env}=#{against.join(",")} matched #{keeping} #{name}, try any of these:
46
+ #{env}=#{expected.join(",")} matched #{keeping} #{name}, try any of these:
34
47
  #{before.map(&by).sort.uniq.join("\n")}
35
48
  MSG
36
49
  end
@@ -27,11 +27,12 @@ module Kennel
27
27
  }.freeze
28
28
  DEFAULT_ESCALATION_MESSAGE = ["", nil].freeze
29
29
  ALLOWED_PRIORITY_CLASSES = [NilClass, Integer].freeze
30
+ ALLOWED_UNLINKED = [] # rubocop:disable Style/MutableConstant placeholder for custom overrides
30
31
 
31
32
  settings(
32
33
  :query, :name, :message, :escalation_message, :critical, :type, :renotify_interval, :warning, :timeout_h, :evaluation_delay,
33
34
  :ok, :no_data_timeframe, :notify_no_data, :notify_audit, :tags, :critical_recovery, :warning_recovery, :require_full_window,
34
- :threshold_windows, :new_host_delay, :new_group_delay, :priority
35
+ :threshold_windows, :new_host_delay, :new_group_delay, :priority, :validate_using_links
35
36
  )
36
37
 
37
38
  defaults(
@@ -238,6 +239,8 @@ module Kennel
238
239
  validate_message_variables(data)
239
240
  end
240
241
 
242
+ validate_using_links(data)
243
+
241
244
  if type == "service check" && !data[:query].to_s.include?(".by(")
242
245
  invalid! "query must include a .by() at least .by(\"*\")"
243
246
  end
@@ -261,6 +264,7 @@ module Kennel
261
264
  return if used.empty?
262
265
  used.flatten!(1)
263
266
  used.uniq!
267
+ used.map! { |w| w.tr("[]", "") }
264
268
 
265
269
  # TODO
266
270
  # - also match without by
@@ -286,6 +290,21 @@ module Kennel
286
290
  Group or filter the query by #{forbidden.map { |f| f.sub(".name", "") }.join(", ")} to use it.
287
291
  MSG
288
292
  end
293
+
294
+ def validate_using_links(data)
295
+ case data[:type]
296
+ when "composite" # TODO: add slo to mirror resolve_linked_tracking_ids! logic
297
+ ids = data[:query].tr("-", "_").scan(/\b\d+\b/)
298
+ ids.reject! { |id| ALLOWED_UNLINKED.include?([tracking_id, id]) }
299
+ if ids.any?
300
+ invalid! <<~MSG.rstrip
301
+ Used #{ids} in the query, but should only use links in the form of %{<project id>:<monitor id>}
302
+ If that is not possible, add `validate_using_links: ->(*){} # linked monitors are not in kennel
303
+ MSG
304
+ end
305
+ else # do nothing
306
+ end
307
+ end
289
308
  end
290
309
  end
291
310
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.119.0"
3
+ VERSION = "1.121.0"
4
4
  end
data/lib/kennel.rb CHANGED
@@ -101,10 +101,10 @@ module Kennel
101
101
  @generated ||= begin
102
102
  Progress.progress "Generating" do
103
103
  projects = projects_provider.projects
104
- Kennel::Filter.filter_resources!(projects, :kennel_id, filter.project_filter, "projects", "PROJECT")
104
+ projects = filter.filter_projects projects
105
105
 
106
106
  parts = Utils.parallel(projects, &:validated_parts).flatten(1)
107
- Kennel::Filter.filter_resources!(parts, :tracking_id, filter.tracking_id_filter, "resources", "TRACKING_ID")
107
+ parts = filter.filter_parts parts
108
108
 
109
109
  parts.group_by(&:tracking_id).each do |tracking_id, same|
110
110
  next if same.size == 1
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.119.0
4
+ version: 1.121.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: 2022-09-29 00:00:00.000000000 Z
11
+ date: 2022-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs