kennel 1.78.0 → 1.79.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d1a7ffddfc55955603d8ac9826ab2f46af2f223cb92f829ac1be0f2dc29af4c
4
- data.tar.gz: fe2a7fa8bdf812bb7e4cf79a3e14ab8923225f8464ac352723ab18e54be9fc3f
3
+ metadata.gz: e2a8b643d03deb142461d127a97ae6ad45144cffffb3bae2925cc60cf6a1d683
4
+ data.tar.gz: 1baaa314a376a99317163a871e5ec6df10dcd33a2cdd3cbc36d2bed9283fe288
5
5
  SHA512:
6
- metadata.gz: af3734bc932520ec215baa7cbf31f40553d50b48f0c61d80835a030cb728af8cb139c4e7296ad82792a54b699971a6892da227674b1b50f659bd787cbe743a0c
7
- data.tar.gz: 9f01dd98d5467bf60cdfa2943925fa0edece4d74970ba2e17888b5dcce51f6f59a15cd70c6d6208e1e83c5ebd65339e7a2e7f5c52f490ece1cffce0ad170f8b3
6
+ metadata.gz: e4a2266131f58c1d833172e95e3b87b80b49f120675b27baf5e70bd0c5cf191a1dafeb0374b407ff983b5d5e793479d79fdfd548921f161e2644df1dbb86abb8
7
+ data.tar.gz: d791193329518eb1c277a24543abe1c3d4b62621af0046bd58a3347cdab3faa74da06dcc639dcd8c4d12ac0c76536652d91ada35db63b3d2fb71c7d618afa6b8
data/Readme.md CHANGED
@@ -83,7 +83,7 @@ end
83
83
  - `gem install bundler && bundle install`
84
84
  - `cp .env.example .env`
85
85
  - open [Datadog API Settings](https://app.datadoghq.com/account/settings#api)
86
- - copy any `API Key` and add it to `.env` as `DATADOG_API_KEY`
86
+ - create a `API Key` or get an existing one from an admin, then add it to `.env` as `DATADOG_API_KEY`
87
87
  - find or create (check last page) your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=`
88
88
  - change the `DATADOG_SUBDOMAIN=app` in `.env` to your companies subdomain if you have one
89
89
  - verify it works by running `rake plan`, it might show some diff, but should not crash
@@ -198,6 +198,15 @@ end
198
198
  end
199
199
  ```
200
200
 
201
+ ### Updating existing resources with id
202
+
203
+ Setting `id` makes kennel take over a manually created datadog resource.
204
+ When manually creating to import, it is best to remove the `id` and delete the manually created resource.
205
+
206
+ When an `id` is set and the original resource is deleted, kennel will fail to update,
207
+ removing the `id` will cause kennel to create a new resource in datadog.
208
+
209
+
201
210
  ### Skipping validations
202
211
 
203
212
  Some validations might be too strict for your usecase or just wrong, please [open an issue](https://github.com/grosser/kennel/issues) and
@@ -287,5 +296,5 @@ Author
287
296
  [Michael Grosser](http://grosser.it)<br/>
288
297
  michael@grosser.it<br/>
289
298
  License: MIT<br/>
290
- [![Build Status](https://travis-ci.org/grosser/kennel.png)](https://travis-ci.org/grosser/kennel)
299
+ ![CI](https://github.com/grosser/kennel/workflows/CI/badge.svg)
291
300
  <!-- NOT IN -->
@@ -105,7 +105,7 @@ module Kennel
105
105
 
106
106
  def as_json
107
107
  return @json if @json
108
- all_widgets = render_definitions + widgets
108
+ all_widgets = render_definitions(definitions) + widgets
109
109
  expand_q all_widgets
110
110
 
111
111
  @json = {
@@ -178,14 +178,14 @@ module Kennel
178
178
  def validate_json(data)
179
179
  super
180
180
 
181
- validate_template_variables data, :widgets
181
+ validate_template_variables data
182
182
 
183
183
  # Avoid diff from datadog presets sorting.
184
184
  presets = data[:template_variable_presets]
185
185
  invalid! "template_variable_presets must be sorted by name" if presets && presets != presets.sort_by { |p| p[:name] }
186
186
  end
187
187
 
188
- def render_definitions
188
+ def render_definitions(definitions)
189
189
  definitions.map do |title, type, display_type, queries, options = {}, ignored = nil|
190
190
  # validate inputs
191
191
  if ignored || (!title || !type || !queries || !options.is_a?(Hash))
@@ -12,6 +12,10 @@ module Kennel
12
12
  :multi, :matching_downtimes, :overall_state_modified, :overall_state, :restricted_roles
13
13
  ]
14
14
 
15
+ MONITOR_DEFAULTS = {
16
+ priority: nil
17
+ }.freeze
18
+
15
19
  # defaults that datadog uses when options are not sent, so safe to leave out if our values match their defaults
16
20
  MONITOR_OPTION_DEFAULTS = {
17
21
  evaluation_delay: nil,
@@ -27,7 +31,7 @@ module Kennel
27
31
  settings(
28
32
  :query, :name, :message, :escalation_message, :critical, :type, :renotify_interval, :warning, :timeout_h, :evaluation_delay,
29
33
  :ok, :no_data_timeframe, :notify_no_data, :notify_audit, :tags, :critical_recovery, :warning_recovery, :require_full_window,
30
- :threshold_windows, :new_host_delay
34
+ :threshold_windows, :new_host_delay, :priority
31
35
  )
32
36
 
33
37
  defaults(
@@ -46,7 +50,8 @@ module Kennel
46
50
  evaluation_delay: -> { MONITOR_OPTION_DEFAULTS.fetch(:evaluation_delay) },
47
51
  critical_recovery: -> { nil },
48
52
  warning_recovery: -> { nil },
49
- threshold_windows: -> { nil }
53
+ threshold_windows: -> { nil },
54
+ priority: -> { MONITOR_DEFAULTS.fetch(:priority) }
50
55
  )
51
56
 
52
57
  def as_json
@@ -57,6 +62,7 @@ module Kennel
57
62
  query: query.strip,
58
63
  message: message.strip,
59
64
  tags: tags.uniq,
65
+ priority: priority,
60
66
  options: {
61
67
  timeout_h: timeout_h,
62
68
  notify_no_data: notify_no_data,
@@ -129,6 +135,9 @@ module Kennel
129
135
 
130
136
  def self.normalize(expected, actual)
131
137
  super
138
+
139
+ ignore_default(expected, actual, MONITOR_DEFAULTS)
140
+
132
141
  options = actual.fetch(:options)
133
142
  options.delete(:silenced) # we do not manage silenced, so ignore it when diffing
134
143
 
@@ -209,7 +218,10 @@ module Kennel
209
218
  .map! { |w| %("#{w}.name") }
210
219
  used.uniq.each do |match, group|
211
220
  next if allowed.include?(group)
212
- invalid! "#{match} used with #{group}, but can only be used with #{allowed.join(", ")}. Add more groupings or fix the #{match}"
221
+ invalid!(
222
+ "#{match} used with #{group}, but can only be used with #{allowed.join(", ")}. " \
223
+ "Group the query by #{group.sub(".name", "").tr('"', "")} or change the #{match}"
224
+ )
213
225
  end
214
226
  end
215
227
  end
@@ -139,7 +139,8 @@ module Kennel
139
139
  def ensure_all_ids_found
140
140
  @expected.each do |e|
141
141
  next unless id = e.id
142
- raise "Unable to find existing #{e.class.api_resource} with id #{id}"
142
+ resource = e.class.api_resource
143
+ raise "Unable to find existing #{resource} with id #{id}\nIf the #{resource} was deleted, remove the `id: -> { #{e.id} }` line."
143
144
  end
144
145
  end
145
146
 
@@ -16,18 +16,22 @@ module Kennel
16
16
 
17
17
  # check for queries that do not use the variables and would be misleading
18
18
  # TODO: do the same check for apm_query and their group_by
19
- def validate_template_variables(data, key)
19
+ def validate_template_variables(data)
20
20
  variables = (data[:template_variables] || []).map { |v| "$#{v.fetch(:name)}" }
21
- queries = data[key].flat_map do |widget|
21
+ return if variables.empty?
22
+
23
+ queries = data[:widgets].flat_map do |widget|
22
24
  ([widget] + (widget.dig(:definition, :widgets) || [])).flat_map { |w| widget_queries(w) }
23
25
  end.compact
24
- bad = queries.grep_v(/(#{variables.map { |v| Regexp.escape(v) }.join("|")})\b/)
25
- if bad.any?
26
- invalid!(
27
- "queries #{bad.join(", ")} must use the template variables #{variables.join(", ")}\n" \
28
- "If that is not possible, add `validate: -> { false } # query foo in bar does not have baz tag`"
29
- )
30
- end
26
+
27
+ matches = variables.map { |v| Regexp.new "#{Regexp.escape(v)}\\b" }
28
+ queries.reject! { |q| matches.all? { |m| q.match? m } }
29
+ return if queries.empty?
30
+
31
+ invalid!(
32
+ "queries #{queries.join(", ")} must use the template variables #{variables.join(", ")}\n" \
33
+ "If that is not possible, add `validate: -> { false } # query foo in bar does not have baz tag`"
34
+ )
31
35
  end
32
36
 
33
37
  def widget_queries(widget)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.78.0"
3
+ VERSION = "1.79.0"
4
4
  end
@@ -66,7 +66,7 @@ end
66
66
  - `gem install bundler && bundle install`
67
67
  - `cp .env.example .env`
68
68
  - open [Datadog API Settings](https://app.datadoghq.com/account/settings#api)
69
- - copy any `API Key` and add it to `.env` as `DATADOG_API_KEY`
69
+ - create a `API Key` or get an existing one from an admin, then add it to `.env` as `DATADOG_API_KEY`
70
70
  - find or create (check last page) your personal "Application Key" and add it to `.env` as `DATADOG_APP_KEY=`
71
71
  - change the `DATADOG_SUBDOMAIN=app` in `.env` to your companies subdomain if you have one
72
72
  - verify it works by running `rake plan`, it might show some diff, but should not crash
@@ -180,6 +180,15 @@ end
180
180
  end
181
181
  ```
182
182
 
183
+ ### Updating existing resources with id
184
+
185
+ Setting `id` makes kennel take over a manually created datadog resource.
186
+ When manually creating to import, it is best to remove the `id` and delete the manually created resource.
187
+
188
+ When an `id` is set and the original resource is deleted, kennel will fail to update,
189
+ removing the `id` will cause kennel to create a new resource in datadog.
190
+
191
+
183
192
  ### Skipping validations
184
193
 
185
194
  Some validations might be too strict for your usecase or just wrong, please [open an issue](https://github.com/grosser/kennel/issues) and
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.78.0
4
+ version: 1.79.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: 2020-10-19 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday