kennel 1.1.3 → 1.2.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: cb3b5644eb3dc14c44111022b8f694542b8e53b4cc6cabb515d63d5b5a9686e5
4
- data.tar.gz: 2fc9459aab2a5b1a696149f60b760e825372b9cac6cc257a6240ec93df7f4bb1
3
+ metadata.gz: a7a5c47325d6b67585b8fe87c91aca09e5bfc1f1733bb947a807cc55a1b69eb0
4
+ data.tar.gz: a11927863dcf10f84d28f35a074f1dcc0744493bf2861d8905dea2edd6e12866
5
5
  SHA512:
6
- metadata.gz: 524ace140e342c6e95f7ed19b05ca3a10fe7bec772b1c8ad446c5f5e02a16ca14dfbc0719a63874581ffd23b467c1ca0e4b7e95b700297c503cd9655538e8241
7
- data.tar.gz: ba247aceff3bb82ef062ef5ce3af06476561d0733255030a07192571501229c811985fe28b6bae9d330ea143d15e37e3938b76a9d33a19943b6152b1893b2400
6
+ metadata.gz: 8d7b51f07ac1dc137b2197761891bd64c4b7752240977bfe2617cb12fef42204409e1fc80bc2072bd43f289b07468879a6e2e20f9e399f1df4127e0924ab1038
7
+ data.tar.gz: 80bd9891d18cf951bc10a94af66345f9b6ebc3af0b3fbebc090fc504198f654f2d1b075fe06b1e0d9ed1e31dd420279ce9f79995d05493511cacb80104821293
@@ -54,10 +54,19 @@ module Kennel
54
54
  self.class.validate_setting_exists name
55
55
  define_singleton_method name, &block
56
56
  end
57
+
58
+ @invocation_location = caller.detect { |l| l.start_with?(Dir.pwd) }
57
59
  end
58
60
 
59
61
  def kennel_id
60
- @kennel_id ||= Utils.snake_case self.class.name
62
+ name = self.class.name
63
+ if name.start_with?("Kennel::")
64
+ message = +"Set :kennel_id"
65
+ message << " for project #{project.kennel_id}" if defined?(project)
66
+ message << " on #{@invocation_location}" if @invocation_location
67
+ raise ArgumentError, message
68
+ end
69
+ @kennel_id ||= Utils.snake_case name
61
70
  end
62
71
 
63
72
  def name
@@ -7,6 +7,7 @@ module Kennel
7
7
  API_LIST_INCOMPLETE = false
8
8
  RENOTIFY_INTERVALS = [0, 10, 20, 30, 40, 50, 60, 90, 120, 180, 240, 300, 360, 720, 1440].freeze # minutes
9
9
  QUERY_INTERVALS = ["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "24h"].freeze
10
+ OPTIONAL_SERVICE_CHECK_THRESHOLDS = [:ok, :warning].freeze
10
11
 
11
12
  settings(
12
13
  :query, :name, :message, :escalation_message, :critical, :kennel_id, :type, :renotify_interval, :warning,
@@ -35,13 +36,6 @@ module Kennel
35
36
  super(*args)
36
37
  end
37
38
 
38
- def kennel_id
39
- if self.class == Kennel::Models::Monitor
40
- raise "Need to set :kennel_id when defining monitors from Kennel::Models::Monitor"
41
- end
42
- super
43
- end
44
-
45
39
  def as_json
46
40
  return @as_json if @as_json
47
41
  data = {
@@ -85,8 +79,12 @@ module Kennel
85
79
  end
86
80
  end
87
81
 
88
- # metric and query values are stored as float by datadog
89
- if data.fetch(:type) == "query alert"
82
+ case data.fetch(:type)
83
+ when "service check"
84
+ # avoid diff for default values of 1
85
+ OPTIONAL_SERVICE_CHECK_THRESHOLDS.each { |t| thresholds[t] ||= 1 }
86
+ when "query alert"
87
+ # metric and query values are stored as float by datadog
90
88
  thresholds.each { |k, v| thresholds[k] = Float(v) }
91
89
  end
92
90
 
@@ -114,16 +112,16 @@ module Kennel
114
112
  options[:require_full_window] = true unless options.key?(:require_full_window)
115
113
  end
116
114
 
117
- # setting 0 results in thresholds not getting returned from the api
118
- if actual[:type] == "event alert"
115
+ case actual[:type]
116
+ when "event alert"
117
+ # setting 0 results in thresholds not getting returned from the api
119
118
  options[:thresholds] ||= { critical: 0 }
120
- end
121
119
 
122
- # fields are not returned when set to true
123
- if actual[:type] == "service check"
124
- options[:thresholds][:critical] ||= 1
125
- options[:thresholds][:warning] ||= 1
126
- options[:thresholds][:ok] ||= 1
120
+ when "service check"
121
+ # fields are not returned when created with default values via UI
122
+ OPTIONAL_SERVICE_CHECK_THRESHOLDS.each do |t|
123
+ options[:thresholds][t] ||= 1
124
+ end
127
125
  end
128
126
 
129
127
  # nil or "" are not returned from the api
@@ -3,7 +3,7 @@ module Kennel
3
3
  module Models
4
4
  class Team < Base
5
5
  # TODO: validate slack has no leading #
6
- settings :slack, :email, :tags
6
+ settings :slack, :email, :tags, :kennel_id
7
7
  defaults(
8
8
  tags: -> { ["team:#{kennel_id.sub(/^teams_/, "")}"] }
9
9
  )
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.1.3"
3
+ VERSION = "1.2.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.1.3
4
+ version: 1.2.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: 2018-05-14 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday