Class: OkComputer::ActionMailerCheck

Inherits:
PingCheck show all
Defined in:
lib/ok_computer/built_in_checks/action_mailer_check.rb

Overview

Verifies if the mail server configured for ActionMailer is responding.

Constant Summary

Constants inherited from PingCheck

PingCheck::ConnectionFailed

Constants inherited from Check

Check::CheckNotDefined

Instance Attribute Summary collapse

Attributes inherited from PingCheck

#request_timeout

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #skip_all, #time

Instance Method Summary collapse

Methods inherited from Check

#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking

Constructor Details

#initialize(klass = ActionMailer::Base, timeout = 5) ⇒ ActionMailerCheck

Returns a new instance of ActionMailerCheck.



7
8
9
10
11
12
13
# File 'lib/ok_computer/built_in_checks/action_mailer_check.rb', line 7

def initialize(klass = ActionMailer::Base, timeout = 5)
  self.klass = klass
  self.timeout = timeout
  host = klass.smtp_settings[:address]
  port = klass.smtp_settings[:port] || 25
  super(host, port, timeout)
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/ok_computer/built_in_checks/action_mailer_check.rb', line 5

def host
  @host
end

#klassObject

Returns the value of attribute klass.



5
6
7
# File 'lib/ok_computer/built_in_checks/action_mailer_check.rb', line 5

def klass
  @klass
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/ok_computer/built_in_checks/action_mailer_check.rb', line 5

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



5
6
7
# File 'lib/ok_computer/built_in_checks/action_mailer_check.rb', line 5

def timeout
  @timeout
end

Instance Method Details

#checkObject

Public: Return the status of the check



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
41
42
43
44
45
# File 'lib/ok_computer/built_in_checks/action_mailer_check.rb', line 16

def check
  case klass.delivery_method
  when :smtp
    begin
      tcp_socket_request
      mark_message "#{klass} check to #{host}:#{port} successful"
    rescue => e
      mark_message "#{klass} at #{host}:#{port} is not accepting connections: '#{e}'"
      mark_failure
    end
  when :sendmail
    begin
      location = klass.sendmail_settings[:location]
      if File.executable?(location)
        mark_message "#{klass} sendmail executable #{location} can be executed"
      else
        mark_message "#{klass} sendmail executable #{location} is not executable"
        mark_failure
      end
    rescue => e
      mark_message "#{klass} error checking sendmail executable: '#{e}'"
      mark_failure
    end
  when :test
    mark_message "#{klass} is in test mode"
  else
    mark_message "unknown delivery method #{klass.delivery_method}"
    mark_failure
  end
end