fluent-plugin-sns 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f1aa27719f45448dc6f81ee814d8d7363475ef6
4
- data.tar.gz: 986e60b82fe3bf32fe2f3f98c7a092fad4ff5819
3
+ metadata.gz: 9de55cad0620884c09c3af8585702b223f34539f
4
+ data.tar.gz: 0bc74974c8e6c782f34975693da51fa8a37c4094
5
5
  SHA512:
6
- metadata.gz: c719f12ca0187b81550abe7503e2221018b19d7317a8d0adfcbac43d83a7835500ae4a55836dd439db2485761f759374612fd0e19d7a9ff0e1f24cb0fad4ed42
7
- data.tar.gz: d530dd4bce2607bbff2818c4df63161c6f4051189f10a6e024269ae36e235678bf0e480880cf0b65962fb8ff042f2dd21f037e3e38602087ffe1554f8280cb49
6
+ metadata.gz: 07f5b4c7d49354013e02b6617109995827cf1166c56bb16fd203304f5203b468d5dbe4054acbbbfbe5a9606243e2aca1788534c70aa3afe2dfea09c01de2e259
7
+ data.tar.gz: 25b9d3329b21e224fdeb55527726d1f3e4912fccd8b07a35b22590ec03c58450e0299b83ec53d12ef6e9f83ab454221626290bfac24593f1e13dcbc0296389c7
data/README.rdoc CHANGED
@@ -21,10 +21,10 @@ Send fluent-event as message to amazon SNS.
21
21
 
22
22
  sns_topic_name {sns_topic_name}
23
23
 
24
- # following attibutes are required if you don't use IAM Role
24
+ # following attibutes are required if you don't use IAM Role and you don't set environment variables
25
25
 
26
- aws_key_id {your_aws_key_id}
27
- aws_sec_key {your_aws_secret_key}
26
+ aws_key_id {your_aws_key_id} # Default: ENV['AWS_ACCESS_KEY_ID']
27
+ aws_sec_key {your_aws_secret_key} # Default: ENV['AWS_SECRET_ACCESS_KEY']
28
28
 
29
29
  # following attibutes are optional
30
30
 
@@ -39,22 +39,44 @@ Send fluent-event as message to amazon SNS.
39
39
  # EU-West (Ireland) : sns.eu-west-1.amazonaws.com
40
40
  # South America (São Paulo) : sns.sa-east-1.amazonaws.com
41
41
 
42
+ sns_subject_template {template_erb_file_path}
42
43
  sns_subject_key {sns_subject_key}
43
44
  sns_subject {sns_subject} #constant subject
44
45
 
46
+ sns_body_template {sns_body_template}
47
+ sns_body_key {sns_body_key}
48
+
45
49
  proxy http(s)://{url}:{port}
46
50
 
47
51
  </match>
48
52
 
49
- == TODO
50
- === More configuration
51
- - E-Mail formatter
52
- - buffer-output
53
+ == Example
54
+
55
+ === fluentd.conf
56
+
57
+ <match sns.**>
58
+
59
+ type sns
60
+
61
+ sns_topic_name example
62
+
63
+ sns_endpoint sns.ap-northeast-1.amazonaws.com
64
+
65
+ sns_subject_key from
66
+ sns_body_template /path/to/template/body_template.erb
67
+
68
+ </match>
69
+
70
+ === template
71
+
72
+ /path/to/template/body_template.erb
73
+ hello <%= record['to'] %>!
74
+
75
+ === sample input
53
76
 
54
- == Test
55
- - Other Notification Protcol (HTTP/HTTPS,SQS,SMS)
77
+ $ echo '{"from":'Alice',"to":"Bob" }' | fluent-cat sns.example
56
78
 
57
- == Tool
79
+ Then, the message is published. (subject -> 'Alice', body -> 'hello Bob!')
58
80
 
59
81
  == Copyright
60
82
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 2.1.0
@@ -1,64 +1,90 @@
1
1
  module Fluent
2
-
3
- require 'aws-sdk'
4
-
5
- class SNSOutput < Output
6
-
7
- Fluent::Plugin.register_output('sns', self)
8
-
9
- include SetTagKeyMixin
10
- config_set_default :include_tag_key, false
11
-
12
- include SetTimeKeyMixin
13
- config_set_default :include_time_key, true
14
-
15
- config_param :aws_key_id, :string, :default => nil
16
- config_param :aws_sec_key, :string, :default => nil
17
-
18
- config_param :sns_topic_name, :string
19
- config_param :sns_subject_key, :string, :default => nil
20
- config_param :sns_subject, :string, :default => nil
21
- config_param :sns_endpoint, :string, :default => 'sns.ap-northeast-1.amazonaws.com'
22
- config_param :proxy, :string, :default => ENV['HTTP_PROXY']
23
-
24
- def configure(conf)
25
- super
26
- end
27
-
28
- def start
29
- super
30
- options = {}
31
- options[:sns_endpoint] = @sns_endpoint
32
- options[:proxy_uri] = @proxy
33
- if @aws_key_id && @aws_sec_key
34
- options[:access_key_id] = @aws_key_id
35
- options[:secret_access_key] = @aws_sec_key
36
- end
37
- AWS.config(options)
38
-
39
- @sns = AWS::SNS.new
40
- @topic = get_topic
41
- end
42
-
43
- def shutdown
44
- super
45
- end
46
-
47
- def emit(tag, es, chain)
48
- chain.next
49
- es.each {|time,record|
50
- record["time"] = Time.at(time).localtime
51
- subject = record[@sns_subject_key] || @sns_subject || 'Fluent-Notification'
52
- @topic.publish(record.to_json, :subject => subject )
53
- }
54
- end
55
-
56
- def get_topic()
57
- @sns.topics.each do |topic|
58
- if @sns_topic_name == topic.name
59
- return topic
60
- end
61
- end
62
- end
2
+
3
+ require 'aws-sdk'
4
+
5
+ class SNSOutput < Output
6
+
7
+ Fluent::Plugin.register_output('sns', self)
8
+
9
+ include SetTagKeyMixin
10
+ config_set_default :include_tag_key, false
11
+
12
+ include SetTimeKeyMixin
13
+ config_set_default :include_time_key, true
14
+
15
+ config_param :aws_key_id, :string, :default => ENV['AWS_ACCESS_KEY_ID']
16
+ config_param :aws_sec_key, :string, :default => ENV['AWS_SECRET_ACCESS_KEY']
17
+
18
+ config_param :sns_topic_name, :string
19
+ config_param :sns_subject_template, :default => nil
20
+ config_param :sns_subject_key, :string, :default => nil
21
+ config_param :sns_subject, :string, :default => nil
22
+ config_param :sns_body_template, :default => nil
23
+ config_param :sns_body_key, :string, :default => nil
24
+ config_param :sns_body, :string, :default => nil
25
+ config_param :sns_endpoint, :string, :default => 'sns.ap-northeast-1.amazonaws.com'
26
+ config_param :proxy, :string, :default => ENV['HTTP_PROXY']
27
+
28
+ def configure(conf)
29
+ super
30
+ end
31
+
32
+ def start
33
+ super
34
+ options = {}
35
+ options[:sns_endpoint] = @sns_endpoint
36
+ options[:proxy_uri] = @proxy
37
+ if @aws_key_id && @aws_sec_key
38
+ options[:access_key_id] = @aws_key_id
39
+ options[:secret_access_key] = @aws_sec_key
40
+ end
41
+ AWS.config(options)
42
+
43
+ @sns = AWS::SNS.new
44
+ @topic = @sns.topics.find{|topic| @sns_topic_name == topic.name}
45
+
46
+ @subject_template = nil
47
+ unless @sns_body_template.nil?
48
+ template_file = open(@sns_subject_template)
49
+ @subject_template = ERB.new(template_file.read)
50
+ template_file.close
51
+ end
52
+
53
+ @body_template = nil
54
+ unless @sns_body_template.nil?
55
+ template_file = open(@sns_body_template)
56
+ @body_template = ERB.new(template_file.read)
57
+ template_file.close
58
+ end
59
+ end
60
+
61
+ def shutdown
62
+ super
63
+ end
64
+
65
+ def emit(tag, es, chain)
66
+ chain.next
67
+ es.each {|time,record|
68
+ record['time'] = Time.at(time).localtime
69
+ body = get_body(record).force_encoding('UTF-8')
70
+ subject = get_subject(record).force_encoding('UTF-8').gsub(/(\r\n|\r|\n)/, '')
71
+ puts "subject:#{subject}, body:#{body}"
72
+ @topic.publish( body, :subject => subject )
73
+ }
74
+ end
75
+
76
+ def get_subject(record)
77
+ unless @subject_template.nil?
78
+ return @subject_template.result(binding)
79
+ end
80
+ subject = record[@sns_subject_key].to_s || @sns_subject || 'Fluentd-Notification'
81
+ end
82
+
83
+ def get_body(record)
84
+ unless @body_template.nil?
85
+ return @body_template.result(binding)
86
+ end
87
+ record[@sns_body_key] || @sns_body || record.to_json
63
88
  end
89
+ end
64
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-sns
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Odagiri