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 +4 -4
- data/lib/kennel/importer.rb +30 -18
- data/lib/kennel/models/monitor.rb +20 -11
- data/lib/kennel/syncer.rb +1 -0
- data/lib/kennel/utils.rb +11 -1
- data/lib/kennel/version.rb +1 -1
- 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: 82e31f58b23229f5a5408eb59cf577f2ce23956dc5083a3e389bc35a3294a422
|
4
|
+
data.tar.gz: 8f5d346672553ad42bec0f19dd23bc2a39032f845d3e930d77698385c4abf8a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab0964256569162a0aaac2c3b6c65c289b85a4815c307134eec882aaf4b2251686b880572d8c72e2516616df88ce53b91945d1f14940cab1e44c9b2a7c7f23e7
|
7
|
+
data.tar.gz: 7c19c8896b1cdac2ee8dc3830af85cbc36e355ebcd1ac4df262ab20396644662b0bfc0204a2953776f174b7d19ef3ec7bb757abb9dba21e700e8fb2d8f38f2ec
|
data/lib/kennel/importer.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
module Kennel
|
4
4
|
class Importer
|
5
|
-
|
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] =
|
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
|
-
#{
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
13
|
-
escalation_message: nil,
|
12
|
+
MONITOR_OPTION_DEFAULTS = {
|
14
13
|
evaluation_delay: nil,
|
15
|
-
|
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: -> {
|
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: -> {
|
35
|
+
notify_no_data: -> { MONITOR_OPTION_DEFAULTS.fetch(:notify_no_data) },
|
31
36
|
no_data_timeframe: -> { notify_no_data ? 60 : nil },
|
32
|
-
notify_audit: -> {
|
37
|
+
notify_audit: -> { MONITOR_OPTION_DEFAULTS.fetch(:notify_audit) },
|
33
38
|
tags: -> { @project.tags },
|
34
|
-
timeout_h: -> {
|
35
|
-
evaluation_delay: -> {
|
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
|
-
|
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
|
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
|
data/lib/kennel/version.rb
CHANGED
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.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-
|
11
|
+
date: 2019-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|