fluent-plugin-sns 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +32 -10
- data/VERSION +1 -1
- data/lib/fluent/plugin/out_sns.rb +87 -61
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9de55cad0620884c09c3af8585702b223f34539f
|
4
|
+
data.tar.gz: 0bc74974c8e6c782f34975693da51fa8a37c4094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
==
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
55
|
-
- Other Notification Protcol (HTTP/HTTPS,SQS,SMS)
|
77
|
+
$ echo '{"from":'Alice',"to":"Bob" }' | fluent-cat sns.example
|
56
78
|
|
57
|
-
|
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
|
1
|
+
2.1.0
|
@@ -1,64 +1,90 @@
|
|
1
1
|
module Fluent
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|