Class: DeadmanCheck::SwitchMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/deadman_check_switch.rb

Overview

Switch class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, target, alert_to, recurse, daemon_sleep) ⇒ SwitchMonitor

Returns a new instance of SwitchMonitor.



12
13
14
15
16
17
18
19
# File 'lib/deadman_check_switch.rb', line 12

def initialize(host, port, target, alert_to, recurse, daemon_sleep)
  @host = host
  @port = port
  @target = target
  @alert_to = alert_to
  @recurse = recurse
  @daemon_sleep = daemon_sleep.to_i
end

Instance Attribute Details

#alert_toObject

Returns the value of attribute alert_to.



10
11
12
# File 'lib/deadman_check_switch.rb', line 10

def alert_to
  @alert_to
end

#daemon_sleepObject

Returns the value of attribute daemon_sleep.



10
11
12
# File 'lib/deadman_check_switch.rb', line 10

def daemon_sleep
  @daemon_sleep
end

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/deadman_check_switch.rb', line 10

def host
  @host
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/deadman_check_switch.rb', line 10

def port
  @port
end

#recurseObject

Returns the value of attribute recurse.



10
11
12
# File 'lib/deadman_check_switch.rb', line 10

def recurse
  @recurse
end

#targetObject

Returns the value of attribute target.



10
11
12
# File 'lib/deadman_check_switch.rb', line 10

def target
  @target
end

Instance Method Details

#run_check_daemonObject



36
37
38
39
40
41
# File 'lib/deadman_check_switch.rb', line 36

def run_check_daemon
  loop do
    run_check_once
    sleep(@daemon_sleep)
  end
end

#run_check_onceObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/deadman_check_switch.rb', line 25

def run_check_once
  recorded_epochs = get_recorded_epochs(@host, @port, @target, @recurse)
  current_epoch = DeadmanCheck::DeadmanCheckGlobal.new.get_epoch_time.to_i
  if @recurse
    check_recursive_recorded_epochs(recorded_epochs, current_epoch)
  else
    record = parse_recorded_epoch(recorded_epochs)
    check_recorded_epoch(record, current_epoch)
  end
end