Class: Nines::CheckGroup
- Inherits:
-
Object
- Object
- Nines::CheckGroup
- Defined in:
- lib/nines/check_group.rb
Instance Attribute Summary collapse
-
#checks ⇒ Object
Returns the value of attribute checks.
-
#contacts ⇒ Object
Returns the value of attribute contacts.
Instance Method Summary collapse
-
#contacts_to_notify(cycles, times_notified) ⇒ Object
times_notified must be a hash with contact names as keys.
-
#initialize(options = {}) ⇒ CheckGroup
constructor
A new instance of CheckGroup.
Constructor Details
#initialize(options = {}) ⇒ CheckGroup
Returns a new instance of CheckGroup.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nines/check_group.rb', line 5 def initialize( = {}) .stringify_keys! @name = ['name'] @description = ['description'] parameters = ['parameters'] || {} parameters.stringify_keys! @check_type = parameters.delete('type') @contacts = [] notify = ['notify'] || [] notify.each do |contact| contact.stringify_keys! @contacts << { 'name' => contact['contact'], 'after' => contact['after'] || 2, 'every' => contact['every'] || 5, 'upto' => contact['upto'] || 5 } end @checks = [] checks = ['checks'] || [] checks.each do |check| check = { hostname: check } unless check.is_a?(Hash) check.stringify_keys! case @check_type when 'http' @checks << HttpCheck.new(self, parameters.merge(check)) when 'ping' @checks << PingCheck.new(self, parameters.merge(check)) else raise Exception.new("Unknown check type: #{@check_type} (supported values: http, ping)") end end end |
Instance Attribute Details
#checks ⇒ Object
Returns the value of attribute checks.
3 4 5 |
# File 'lib/nines/check_group.rb', line 3 def checks @checks end |
#contacts ⇒ Object
Returns the value of attribute contacts.
3 4 5 |
# File 'lib/nines/check_group.rb', line 3 def contacts @contacts end |
Instance Method Details
#contacts_to_notify(cycles, times_notified) ⇒ Object
times_notified must be a hash with contact names as keys
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nines/check_group.rb', line 43 def contacts_to_notify(cycles, times_notified) # cycles starts at 0, but user generally expects first down event to be cycle 1 to_notify = [] @contacts.each do |contact| next if times_notified[contact['name']].to_i >= contact['upto'] next if (cycles+1) < contact['after'] next if (cycles+1 - contact['after']) % contact['every'] != 0 to_notify << contact['name'] end to_notify end |