Class: Kennel::Models::Monitor
- Defined in:
- lib/kennel/models/monitor.rb
Constant Summary collapse
- RENOTIFY_INTERVALS =
minutes
[0, 10, 20, 30, 40, 50, 60, 90, 120, 180, 240, 300, 360, 720, 1440].freeze
- QUERY_INTERVALS =
["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "24h"].freeze
- METRIC_TYPES =
["query alert", "metric alert"].freeze
Constants inherited from Base
Base::LOCK, Base::READONLY_ATTRIBUTES
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #diff(actual) ⇒ Object
-
#initialize(project, *args) ⇒ Monitor
constructor
A new instance of Monitor.
- #kennel_id ⇒ Object
- #url(id) ⇒ Object
Methods inherited from Base
defaults, inherited, #name, settings, #tracking_id, validate_setting_exists
Methods included from SubclassTracking
#recursive_subclasses, #subclasses
Constructor Details
#initialize(project, *args) ⇒ Monitor
Returns a new instance of Monitor.
29 30 31 32 |
# File 'lib/kennel/models/monitor.rb', line 29 def initialize(project, *args) @project = project super(*args) end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
27 28 29 |
# File 'lib/kennel/models/monitor.rb', line 27 def project @project end |
Class Method Details
.api_resource ⇒ Object
91 92 93 |
# File 'lib/kennel/models/monitor.rb', line 91 def self.api_resource "monitor" end |
Instance Method Details
#as_json ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/kennel/models/monitor.rb', line 41 def as_json return @as_json if @as_json data = { name: "#{name}#{LOCK}", type: type, query: query, message: " \#{message}\n\n @slack-\#{project.team.slack}\n TEXT\n tags: @project.tags + tags,\n multi: multi,\n options: {\n timeout_h: 0,\n notify_no_data: notify_no_data,\n no_data_timeframe: no_data_timeframe,\n notify_audit: true,\n require_full_window: true,\n new_host_delay: 300,\n include_tags: true,\n escalation_message: Utils.presence(escalation_message.strip),\n evaluation_delay: nil,\n locked: false, # setting this to true prevents any edit and breaks updates when using replace workflow\n renotify_interval: renotify_interval || 0,\n thresholds: {\n critical: critical\n }\n }\n }\n\n options = data[:options]\n thresholds = options[:thresholds]\n\n data[:id] = id if id\n\n # warning and ok are optional\n thresholds[:warning] = warning if warning\n thresholds[:ok] = ok if ok\n\n # metric and query values are stored as float by datadog\n if [\"metric alert\", \"query alert\"].include? data.fetch(:type)\n thresholds.each { |k, v| thresholds[k] = Float(v) }\n end\n\n validate_json(data)\n\n @as_json = data\nend\n".strip, |
#diff(actual) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kennel/models/monitor.rb', line 99 def diff(actual) = actual.fetch(:options) .delete(:silenced) # we do not manage silenced, so ignore it when diffing [:escalation_message] ||= nil # unset field is not returned and would break the diff # fields are not returned when set to true if ["service check", "event alert"].include?(actual[:type]) [:include_tags] = true unless .key?(:include_tags) [:require_full_window] = true unless .key?(:require_full_window) end # setting 0 results in thresholds not getting returned from the api if actual[:type] == "event alert" [:thresholds] ||= { critical: 0 } end # fields are not returned when set to true if actual[:type] == "service check" [:thresholds][:critical] ||= 1 [:thresholds][:warning] ||= 1 [:thresholds][:ok] ||= 1 end # nil or "" are not returned from the api [:evaluation_delay] ||= nil # datadog uses these types randomly actual[:type] = type if METRIC_TYPES.include?(actual[:type]) super end |
#kennel_id ⇒ Object
34 35 36 37 38 39 |
# File 'lib/kennel/models/monitor.rb', line 34 def kennel_id if self.class == Kennel::Models::Monitor raise "Need to set :kennel_id when defining monitors from Kennel::Models::Monitor" end super end |
#url(id) ⇒ Object
95 96 97 |
# File 'lib/kennel/models/monitor.rb', line 95 def url(id) Utils.path_to_url "/monitors##{id}/edit" end |