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_slack, alert_to_sns, alert_to_sns_region, recurse, daemon_sleep) ⇒ SwitchMonitor

Returns a new instance of SwitchMonitor.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/deadman_check_switch.rb', line 14

def initialize(host, port, target, alert_to_slack, alert_to_sns,
              alert_to_sns_region, recurse, daemon_sleep)
  @host = host
  @port = port
  @target = target
  @alert_to_slack = alert_to_slack
  @alert_to_sns = alert_to_sns
  @alert_to_sns_region = alert_to_sns_region
  @recurse = recurse
  @daemon_sleep = daemon_sleep.to_i

  unless @alert_to_slack.nil?
    Slack.configure do |config|
      config.token = ENV['SLACK_API_TOKEN']
    end
  end

  unless @alert_to_sns.nil?
    @sns = Aws::SNS::Client.new(
      region: @alert_to_sns_region
      )
  end
end

Instance Attribute Details

#alert_to_slackObject

Returns the value of attribute alert_to_slack.



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

def alert_to_slack
  @alert_to_slack
end

#alert_to_snsObject

Returns the value of attribute alert_to_sns.



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

def alert_to_sns
  @alert_to_sns
end

#alert_to_sns_regionObject

Returns the value of attribute alert_to_sns_region.



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

def alert_to_sns_region
  @alert_to_sns_region
end

#daemon_sleepObject

Returns the value of attribute daemon_sleep.



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

def daemon_sleep
  @daemon_sleep
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#recurseObject

Returns the value of attribute recurse.



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

def recurse
  @recurse
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

Instance Method Details

#run_check_daemonObject



49
50
51
52
53
54
# File 'lib/deadman_check_switch.rb', line 49

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

#run_check_onceObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/deadman_check_switch.rb', line 38

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