Class: LogMonitor::EmailAlerter

Inherits:
Alerter
  • Object
show all
Defined in:
lib/log_monitor/alerter.rb

Instance Method Summary collapse

Methods inherited from Alerter

#check_words, #clear_alert, #initialize, #monitor, #set_in, #set_words

Constructor Details

This class inherits a constructor from LogMonitor::Alerter

Instance Method Details

#alertObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/log_monitor/alerter.rb', line 112

def alert
  begin
    mail = Mail.new
    mail[:from] = @config['from']
    mail[:to] = @config['to']
    mail.subject = @config['subject']
    smtpserver = Net::SMTP.new(@smtp_settings[:address], @smtp_settings[:port])
    smtpserver.enable_tls(OpenSSL::SSL::VERIFY_NONE)
    smtpserver.start(@smtp_settings[:domain], @smtp_settings[:user_name], @smtp_settings[:password], :login) do |smtp|
      mail.body = @alert_body
      smtp.send_message(mail.encoded, mail.from, mail.to)
    end
  rescue => e
    $stderr.puts "LogMonitor error"
    $stderr.puts e.message
    2.times $stderr.puts
  end
  clear_alert
end

#set_email(config) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/log_monitor/alerter.rb', line 99

def set_email(config)
  @config = config
  @smtp_settings = {
    address: config['address'],
    port: config['port'],
    user_name: config['user_name'],
    password: config['password'],
    domain: config['domain'],
    authentication: config['authentication'].nil? ? :plain : config['authentication'],
    enable_starttls_auto: true
  }
end