kennel 1.30.0 → 1.31.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: 55d07417188bb69c72a8f7129b3ce9f511dd65194e2205abf72f5b0b83f10f84
4
- data.tar.gz: c45f228ccccd085fd93083c6cad65d6f6695c9f7ec4193ce14055fa05746c88d
3
+ metadata.gz: 82e31f58b23229f5a5408eb59cf577f2ce23956dc5083a3e389bc35a3294a422
4
+ data.tar.gz: 8f5d346672553ad42bec0f19dd23bc2a39032f845d3e930d77698385c4abf8a7
5
5
  SHA512:
6
- metadata.gz: f516120e702ea779bd61ed025fafbb5bcb22282f35ed4cc837622c73c5abe4e72ede39cf0a10cf536000a4d333be5cd6620f6fc47392c061c1f5ca61d27c8094
7
- data.tar.gz: 4480905ca7260a493ba626555a388299ca4f490b2078f936316443cc57a3e673a45792aa3108cf0bac8490f4239a10f625090d0bea22be9ef75bb00a5a5e92e8
6
+ metadata.gz: ab0964256569162a0aaac2c3b6c65c289b85a4815c307134eec882aaf4b2251686b880572d8c72e2516616df88ce53b91945d1f14940cab1e44c9b2a7c7f23e7
7
+ data.tar.gz: 7c19c8896b1cdac2ee8dc3830af85cbc36e355ebcd1ac4df262ab20396644662b0bfc0204a2953776f174b7d19ef3ec7bb757abb9dba21e700e8fb2d8f38f2ec
@@ -2,7 +2,8 @@
2
2
 
3
3
  module Kennel
4
4
  class Importer
5
- SORT_ORDER = [:title, :name, :board_title, :id, :kennel_id, :query, :message, :description, :template_variables].freeze
5
+ TITLES = [:name, :title, :board_title].freeze
6
+ SORT_ORDER = [*TITLES, :id, :kennel_id, :type, :tags, :query, :message, :description, :template_variables].freeze
6
7
 
7
8
  def initialize(api)
8
9
  @api = api
@@ -21,19 +22,27 @@ module Kennel
21
22
  id = data.fetch(:id) # store numerical id returned from the api
22
23
  model.normalize({}, data)
23
24
  data[:id] = id
24
- data[:kennel_id] = "pick_something_descriptive"
25
+ data[:kennel_id] = Kennel::Utils.parameterize(data.fetch(TITLES.detect { |t| data[t] }))
25
26
 
26
- # flatten monitor options so they are all on the base
27
27
  if resource == "monitor"
28
+ # flatten monitor options so they are all on the base
28
29
  data.merge!(data.delete(:options))
29
30
  data.merge!(data.delete(:thresholds) || {})
30
31
  data = data.slice(*model.instance_methods)
32
+
33
+ # make query use critical method if it matches
34
+ critical = data[:critical]
35
+ query = data[:query]
36
+ if query && critical
37
+ query.sub!(/([><=]) (#{Regexp.escape(critical.to_f.to_s)}|#{Regexp.escape(critical.to_i.to_s)})$/, "\\1 \#{critical}")
38
+ end
31
39
  end
32
40
 
41
+ pretty = pretty_print(data).lstrip.gsub("\\#", "#")
33
42
  <<~RUBY
34
43
  #{model.name}.new(
35
44
  self,
36
- #{pretty_print(data).lstrip}
45
+ #{pretty}
37
46
  )
38
47
  RUBY
39
48
  end
@@ -43,20 +52,23 @@ module Kennel
43
52
  def pretty_print(hash)
44
53
  list = hash.sort_by { |k, _| [SORT_ORDER.index(k) || 999, k] } # important to the front and rest deterministic
45
54
  list.map do |k, v|
46
- case v
47
- when Hash, Array
48
- # update answer here when changing https://stackoverflow.com/questions/8842546/best-way-to-pretty-print-a-hash
49
- # (exclude indent line)
50
- pretty = JSON.pretty_generate(v)
51
- .gsub(": null", ": nil")
52
- .gsub(/(^\s*)"([a-zA-Z][a-zA-Z\d_]*)":/, "\\1\\2:") # "foo": 1 -> foo: 1
53
- .gsub(/(^\s*)(".*?"):/, "\\1\\2 =>") # "123": 1 -> "123" => 1
54
- .gsub(/^/, " ") # indent
55
-
56
- " #{k}: -> {\n#{pretty}\n }"
57
- else
58
- " #{k}: -> { #{v.inspect} }"
59
- end
55
+ pretty_value =
56
+ if v.is_a?(Hash) || (v.is_a?(Array) && !v.all? { |e| e.is_a?(String) })
57
+ # update answer here when changing https://stackoverflow.com/questions/8842546/best-way-to-pretty-print-a-hash
58
+ # (exclude last indent gsub)
59
+ pretty = JSON.pretty_generate(v)
60
+ .gsub(": null", ": nil")
61
+ .gsub(/(^\s*)"([a-zA-Z][a-zA-Z\d_]*)":/, "\\1\\2:") # "foo": 1 -> foo: 1
62
+ .gsub(/(^\s*)(".*?"):/, "\\1\\2 =>") # "123": 1 -> "123" => 1
63
+ .gsub(/^/, " ") # indent
64
+
65
+ "\n#{pretty}\n "
66
+ elsif k == :message
67
+ "\n <<~TEXT\n#{v.each_line.map { |l| l.strip.empty? ? "\n" : " #{l}" }.join}\n TEXT\n "
68
+ else
69
+ " #{v.inspect} "
70
+ end
71
+ " #{k}: -> {#{pretty_value}}"
60
72
  end.join(",\n")
61
73
  end
62
74
  end
@@ -9,30 +9,35 @@ module Kennel
9
9
  QUERY_INTERVALS = ["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "1d"].freeze
10
10
  OPTIONAL_SERVICE_CHECK_THRESHOLDS = [:ok, :warning].freeze
11
11
  READONLY_ATTRIBUTES = Base::READONLY_ATTRIBUTES + [:multi]
12
- MONITOR_DEFAULTS = {
13
- escalation_message: nil,
12
+ MONITOR_OPTION_DEFAULTS = {
14
13
  evaluation_delay: nil,
15
- no_data_timeframe: nil
14
+ timeout_h: 0,
15
+ renotify_interval: 120,
16
+ notify_audit: true,
17
+ notify_no_data: true,
18
+ no_data_timeframe: nil # this works out ok since if notify_no_data is on, it would never be nil
16
19
  }.freeze
20
+ DEFAULT_ESCALATION_MESAGE = ["", nil].freeze
17
21
 
18
22
  settings(
19
23
  :query, :name, :message, :escalation_message, :critical, :kennel_id, :type, :renotify_interval, :warning, :timeout_h, :evaluation_delay,
20
24
  :ok, :id, :no_data_timeframe, :notify_no_data, :notify_audit, :tags, :critical_recovery, :warning_recovery, :require_full_window,
21
25
  :threshold_windows
22
26
  )
27
+
23
28
  defaults(
24
29
  message: -> { "\n\n@slack-#{project.slack}" },
25
- escalation_message: -> { "" },
26
- renotify_interval: -> { 120 },
30
+ escalation_message: -> { DEFAULT_ESCALATION_MESAGE.first },
31
+ renotify_interval: -> { MONITOR_OPTION_DEFAULTS.fetch(:renotify_interval) },
27
32
  warning: -> { nil },
28
33
  ok: -> { nil },
29
34
  id: -> { nil },
30
- notify_no_data: -> { true },
35
+ notify_no_data: -> { MONITOR_OPTION_DEFAULTS.fetch(:notify_no_data) },
31
36
  no_data_timeframe: -> { notify_no_data ? 60 : nil },
32
- notify_audit: -> { true },
37
+ notify_audit: -> { MONITOR_OPTION_DEFAULTS.fetch(:notify_audit) },
33
38
  tags: -> { @project.tags },
34
- timeout_h: -> { 0 },
35
- evaluation_delay: -> { nil },
39
+ timeout_h: -> { MONITOR_OPTION_DEFAULTS.fetch(:timeout_h) },
40
+ evaluation_delay: -> { MONITOR_OPTION_DEFAULTS.fetch(:evaluation_delay) },
36
41
  critical_recovery: -> { nil },
37
42
  warning_recovery: -> { nil },
38
43
  threshold_windows: -> { nil }
@@ -113,7 +118,6 @@ module Kennel
113
118
  super
114
119
  options = actual.fetch(:options)
115
120
  options.delete(:silenced) # we do not manage silenced, so ignore it when diffing
116
- options[:escalation_message] ||= nil # unset field is not returned and would break the diff
117
121
 
118
122
  # fields are not returned when set to true
119
123
  if ["service check", "event alert"].include?(actual[:type])
@@ -136,7 +140,12 @@ module Kennel
136
140
  # nil / "" / 0 are not returned from the api when set via the UI
137
141
  options[:evaluation_delay] ||= nil
138
142
 
139
- ignore_default(expected[:options] || {}, options, MONITOR_DEFAULTS)
143
+ expected_options = expected[:options] || {}
144
+ ignore_default(expected_options, options, MONITOR_OPTION_DEFAULTS)
145
+ if DEFAULT_ESCALATION_MESAGE.include?(options[:escalation_message])
146
+ options.delete(:escalation_message)
147
+ expected_options.delete(:escalation_message)
148
+ end
140
149
  end
141
150
 
142
151
  private
data/lib/kennel/syncer.rb CHANGED
@@ -208,6 +208,7 @@ module Kennel
208
208
  def add_tracking_id(e)
209
209
  json = e.as_json
210
210
  field = tracking_field(json)
211
+ raise "remove \"-- Managed by kennel\" line it from #{field} to copy a resource" if tracking_value(json[field])
211
212
  json[field] = "#{json[field]}\n-- Managed by kennel #{e.tracking_id} in #{e.project.class.file_location}, do not modify manually".lstrip
212
213
  end
213
214
 
data/lib/kennel/utils.rb CHANGED
@@ -15,12 +15,22 @@ module Kennel
15
15
 
16
16
  class << self
17
17
  def snake_case(string)
18
- string.gsub(/::/, "_") # Foo::Bar -> foo_bar
18
+ string
19
+ .gsub(/::/, "_") # Foo::Bar -> foo_bar
19
20
  .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') # FOOBar -> foo_bar
20
21
  .gsub(/([a-z\d])([A-Z])/, '\1_\2') # fooBar -> foo_bar
21
22
  .downcase
22
23
  end
23
24
 
25
+ # simplified version of https://apidock.com/rails/ActiveSupport/Inflector/parameterize
26
+ def parameterize(string)
27
+ string
28
+ .downcase
29
+ .gsub(/[^a-z0-9\-_]+/, "-") # remove unsupported
30
+ .gsub(/-{2,}/, "-") # remove duplicates
31
+ .gsub(/^-|-$/, "") # remove leading/trailing
32
+ end
33
+
24
34
  def presence(value)
25
35
  value.nil? || value.empty? ? nil : value
26
36
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.30.0"
3
+ VERSION = "1.31.0"
4
4
  end
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.30.0
4
+ version: 1.31.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: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2019-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday