Class: DeadmanCheck::SwitchMonitor
- Inherits:
-
Object
- Object
- DeadmanCheck::SwitchMonitor
- Defined in:
- lib/deadman_check_switch.rb
Overview
Switch class
Instance Attribute Summary collapse
-
#alert_to_slack ⇒ Object
Returns the value of attribute alert_to_slack.
-
#alert_to_sns ⇒ Object
Returns the value of attribute alert_to_sns.
-
#alert_to_sns_region ⇒ Object
Returns the value of attribute alert_to_sns_region.
-
#daemon_sleep ⇒ Object
Returns the value of attribute daemon_sleep.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#recurse ⇒ Object
Returns the value of attribute recurse.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(host, port, target, alert_to_slack, alert_to_sns, alert_to_sns_region, recurse, daemon_sleep) ⇒ SwitchMonitor
constructor
A new instance of SwitchMonitor.
- #run_check_daemon ⇒ Object
- #run_check_once ⇒ Object
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_slack ⇒ Object
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_sns ⇒ Object
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_region ⇒ Object
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_sleep ⇒ Object
Returns the value of attribute daemon_sleep.
11 12 13 |
# File 'lib/deadman_check_switch.rb', line 11 def daemon_sleep @daemon_sleep end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/deadman_check_switch.rb', line 11 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
11 12 13 |
# File 'lib/deadman_check_switch.rb', line 11 def port @port end |
#recurse ⇒ Object
Returns the value of attribute recurse.
11 12 13 |
# File 'lib/deadman_check_switch.rb', line 11 def recurse @recurse end |
#target ⇒ Object
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_daemon ⇒ Object
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_once ⇒ Object
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 |