Class: Fluent::SNSOutput

Inherits:
Output
  • Object
show all
Includes:
SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_sns.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



28
29
30
# File 'lib/fluent/plugin/out_sns.rb', line 28

def configure(conf)
  super
end

#emit(tag, es, chain) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/fluent/plugin/out_sns.rb', line 65

def emit(tag, es, chain)
  chain.next
  es.each {|time,record|
    record['time'] = Time.at(time).localtime
    body = get_body(record).to_s.force_encoding('UTF-8')
    subject = get_subject(record).to_s.force_encoding('UTF-8').gsub(/(\r\n|\r|\n)/, '')
    @topic.publish( body, :subject => subject )
  }
end

#get_body(record) ⇒ Object



82
83
84
85
86
87
# File 'lib/fluent/plugin/out_sns.rb', line 82

def get_body(record)
  unless @body_template.nil?
    return @body_template.result(binding)
  end
  record[@sns_body_key] || @sns_body || record.to_json
end

#get_subject(record) ⇒ Object



75
76
77
78
79
80
# File 'lib/fluent/plugin/out_sns.rb', line 75

def get_subject(record)
  unless @subject_template.nil?
    return @subject_template.result(binding)
  end
  subject = record[@sns_subject_key] || @sns_subject || 'Fluentd-Notification'
end

#shutdownObject



61
62
63
# File 'lib/fluent/plugin/out_sns.rb', line 61

def shutdown
  super
end

#startObject



32
33
34
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
# File 'lib/fluent/plugin/out_sns.rb', line 32

def start
  super
  options = {}
  options[:sns_endpoint] = @sns_endpoint
  options[:proxy_uri] = @proxy
  if @aws_key_id && @aws_sec_key
    options[:access_key_id] = @aws_key_id
    options[:secret_access_key] = @aws_sec_key
  end
  AWS.config(options)

  @sns = AWS::SNS.new
  @topic = @sns.topics.find{|topic| @sns_topic_name == topic.name}

  @subject_template = nil
  unless @sns_subject_template.nil?
    template_file = open(@sns_subject_template)
    @subject_template = ERB.new(template_file.read)
    template_file.close
  end

  @body_template = nil
  unless @sns_body_template.nil?
    template_file = open(@sns_body_template)
    @body_template = ERB.new(template_file.read)
    template_file.close
  end
end