Class: Nines::Check
- Inherits:
-
Object
- Object
- Nines::Check
- Defined in:
- lib/nines/check.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#cycles ⇒ Object
Returns the value of attribute cycles.
-
#group ⇒ Object
Returns the value of attribute group.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
-
#notifier ⇒ Object
Returns the value of attribute notifier.
-
#port ⇒ Object
Returns the value of attribute port.
-
#since ⇒ Object
Returns the value of attribute since.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#up ⇒ Object
Returns the value of attribute up.
Instance Method Summary collapse
-
#initialize(group, options) ⇒ Check
constructor
A new instance of Check.
- #log_status(up, description) ⇒ Object
Constructor Details
#initialize(group, options) ⇒ Check
Returns a new instance of Check.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nines/check.rb', line 5 def initialize(group, ) @group = group @hostname = ['hostname'] @name = ['name'] || @hostname @timeout = ['timeout_sec'] || 10 @port = ['port'] @interval = ['interval_sec'] || 60 @logger = Nines::App.logger || STDOUT @notifier = Nines::App.notifier @times_notified = {} @up = true @since = Time.now.utc @cycles = 0 end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def address @address end |
#cycles ⇒ Object
Returns the value of attribute cycles.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def cycles @cycles end |
#group ⇒ Object
Returns the value of attribute group.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def group @group end |
#hostname ⇒ Object
Returns the value of attribute hostname.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def hostname @hostname end |
#interval ⇒ Object
Returns the value of attribute interval.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def interval @interval end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def name @name end |
#notifier ⇒ Object
Returns the value of attribute notifier.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def notifier @notifier end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def port @port end |
#since ⇒ Object
Returns the value of attribute since.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def since @since end |
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def timeout @timeout end |
#up ⇒ Object
Returns the value of attribute up.
3 4 5 |
# File 'lib/nines/check.rb', line 3 def up @up end |
Instance Method Details
#log_status(up, description) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nines/check.rb', line 22 def log_status(up, description) if up logger.puts "[#{Time.now}] - #{name} - Check passed: #{description}" case @up when true @cycles += 1 when false @up = true @since = Time.now.utc @cycles = 0 # back up notification if notifier @times_notified.keys.each do |contact_name| logger.puts "[#{Time.now}] - #{name} - UP again, notifying contact '#{contact_name}'" notifier.notify!(contact_name, self) end @times_notified = {} end end else logger.puts "[#{Time.now}] - #{name} - Check FAILED: #{description}" case @up when false @cycles += 1 when true @up = false @since = Time.now.utc @cycles = 0 end if notifier && to_notify = group.contacts_to_notify(@cycles, @times_notified) to_notify.each do |contact_name| logger.puts "[#{Time.now}] - #{name} - Notifying contact '#{contact_name}'" notifier.notify!(contact_name, self) @times_notified[contact_name] ||= 0 @times_notified[contact_name] += 1 end end end end |