Class: LogStash::Outputs::Ses

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/ses.rb

Overview

An example output that does nothing.

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/logstash/outputs/ses.rb', line 71

def receive(event)
  @logger.debug? and @logger.debug("Creating AWS SES mail with these settings : ", :message => event,:options => @options, :from => @from, :to => @to_addresses, :cc => @cc_addresses, :subject => @subject,:innerTarget => event.sprintf("%{mailTo}"))
  
  innerTarget = @destination.dup
  if event.include?('mailTo')
    innerTarget[:to_addresses] = event.sprintf("%{mailTo}").split ','      
    @logger.debug? and @logger.debug("new mailTo address found in event,overriding target addresses", :parsed => innerTarget[:to_addresses] )
  end
  
  subject = event.sprintf(@subject)
  body = event.sprintf(@body)
  htmlbody = event.sprintf(@htmlbody)
  message = { :subject => {:data => subject},
               :body => {
                :html => {:data => htmlbody },
                :text => {:data => body }
               }
             }

  begin 
    @logger.debug? and @logger.debug("Sending mail with these values : ", :from => @from, :to => innerTarget, :subject => @subject, :body => @body)
    @ses.send_email(
             :source => @from,
             :destination => innerTarget,               
             :message => message
    )
  rescue => e      
    logger.error("Something happen while delivering an SES email", :msg => e.message)
    @logger.debug? && @logger.debug("Processed event: ", :event => event)
  end    
end

#registerObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/logstash/outputs/ses.rb', line 35

def register    
  require "aws-sdk-resources"
  options = {}
  if @aws_key_id && @aws_sec_key
    options[:access_key_id]     = @aws_key_id
    options[:secret_access_key] = @aws_sec_key
  end

  if @region_name
    options[:region] = @region_name
  end


  @ses = Aws::SES::Client.new(options)

  @to_addresses  = @to.split ","
  if @to_addresses.empty?
    logger.error("To can not nil.",:to => @to)      
    raise "SES 'To' area can not nil."
  end

  @cc_addresses  = @cc.split ","
  @bcc_addresses = @bcc.split ","

  @destination = {:to_addresses => @to_addresses }
    unless @cc_addresses.empty?
      @destination[:cc_addresses] = @cc_addresses
    end
    unless @bcc_addresses.empty?
      @destination[:bcc_addresses] = @bcc_addresses
    end

  @logger.debug("Aws SES Registered!", :config => options)
end