fluent-plugin-forward-aws 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -42
- data/fluent-plugin-forward-aws.gemspec +1 -1
- data/lib/fluent/plugin/in_forward_aws.rb +32 -13
- data/lib/fluent/plugin/out_forward_aws.rb +2 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -37,47 +37,32 @@ Create SQS Queue, subscribe to SNS, and memorize following parameters
|
|
37
37
|
+ aws_sqs_endpoint
|
38
38
|
+ aws_sqs_queue_url
|
39
39
|
|
40
|
-
|
40
|
+
### How to configure SQS as SNS subscriber
|
41
41
|
In short, change SQS's access policy to accept "SendMessage" from your SNS ARN, And add SQS ARN to SNS subscribers.
|
42
42
|
You can do the above step in one shot from SQS Management Console.
|
43
43
|
For more detail, check [amazon official document](http://docs.aws.amazon.com/sns/latest/gsg/SendMessageToSQS.html)
|
44
44
|
|
45
45
|
## Common Configuration
|
46
46
|
### Parameters
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
AWS Secket Access Key
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
+ **aws_s3_skiptest** (optional, default = false)
|
60
|
-
Skip S3 Related test at startup
|
61
|
-
|
62
|
-
+ **add_tag_prefix** (optional)
|
63
|
-
Add specified prefix to tag before processing log
|
64
|
-
|
65
|
-
+ **remove_tag_prefix** (optional)
|
66
|
-
Remove specified prefix from tag before processing log
|
67
|
-
|
68
|
-
+ **channel** (optional, default = "default")
|
69
|
-
Tag that Forward-AWS plugin uses for grouping logs.
|
47
|
+
name | type | description
|
48
|
+
----------------------|---------------------------------|---------------------------
|
49
|
+
type | string (required) | type of plugin should be **forward_aws**
|
50
|
+
aws_access_key_id | string (required) | AWS Acccess Key ID
|
51
|
+
aws_secret_access_key | string (required) | AWS Secket Access Key
|
52
|
+
aws_s3_endpoint | string (required) | [s3 Endpoint](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) for your bucket
|
53
|
+
aws_s3_bucketname | string (required) | S3 Bucketname
|
54
|
+
aws_s3_skiptest | bool (default = false) | Skip S3 Related test at startup
|
55
|
+
add_tag_prefix | string (default = nil) | Add specified prefix to tag before processing log
|
56
|
+
remove_tag_prefix | string (default = nil) | Remove specified prefix from tag before processing log
|
57
|
+
channel | string (default = "default") | Tag that Forward-AWS plugin uses for grouping logs.
|
70
58
|
|
71
59
|
## Out Plugin Configuration
|
72
60
|
### Parameters
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
SNS
|
78
|
-
|
79
|
-
+ **aws_sns_skiptest** (optional, default = false)
|
80
|
-
Skip SNS Related test at startup
|
61
|
+
name | type | description
|
62
|
+
----------------------|---------------------------------|---------------------------
|
63
|
+
aws_sns_endpoint | string (required) | [SNS Endpoint](http://docs.aws.amazon.com/general/latest/gr/rande.html#sns_region) for your topic
|
64
|
+
aws_sns_topic_arn | string (required) | SNS Topic ARN
|
65
|
+
aws_sns_skiptest | bool (default = false) | Skip SNS Related test at startup
|
81
66
|
|
82
67
|
###Required AWS permission
|
83
68
|
+ s3:PutObject
|
@@ -135,17 +120,14 @@ Use tag as forward-AWS channel
|
|
135
120
|
|
136
121
|
## In Plugin Configuration
|
137
122
|
### Parameters
|
138
|
-
+ **aws_sqs_endpoint** (required)
|
139
|
-
[SQS Endpoint](http://docs.aws.amazon.com/general/latest/gr/rande.html#sqs_region) for your topic
|
140
|
-
|
141
|
-
+ **aws_sqs_queue_url** (required)
|
142
|
-
SQS Queue URL (not ARN)
|
143
|
-
|
144
|
-
+ **aws_sqs_skiptest** (optional, default = false)
|
145
|
-
Skip SQS Related test at startup
|
146
123
|
|
147
|
-
|
148
|
-
|
124
|
+
name | type | description
|
125
|
+
----------------------|---------------------------------|---------------------------
|
126
|
+
aws_sqs_endpoint | string (required) | [SQS Endpoint](http://docs.aws.amazon.com/general/latest/gr/rande.html#sqs_region) for your topic
|
127
|
+
aws_sqs_queue_url | string (required) | SQS Queue URL (not ARN)
|
128
|
+
aws_sqs_skiptest | bool (default = false) | Skip SQS Related test at startup
|
129
|
+
channelEnableRegEx | bool (default = false) | Enabled Regular Expression when checking channel
|
130
|
+
dry_run | bool (default = false) | Do not delete notification after processing
|
149
131
|
|
150
132
|
###Required AWS permission
|
151
133
|
+ s3:GetObject
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "fluent-plugin-forward-aws"
|
7
|
-
gem.version = "0.1.
|
7
|
+
gem.version = "0.1.4"
|
8
8
|
gem.authors = ["Tomohisa Ota"]
|
9
9
|
gem.email = ["tomohisa.ota+github@gmail.com"]
|
10
10
|
gem.description = "Fluentd In/Out plugin to forward log through AWS(S3/SNS/SQS)"
|
@@ -30,6 +30,8 @@ class Fluent::ForwardAWSInput < Fluent::Input
|
|
30
30
|
config_param :add_tag_prefix, :string, :default => nil
|
31
31
|
config_param :remove_tag_prefix, :string, :default => nil
|
32
32
|
|
33
|
+
config_param :dry_run, :bool, :default => false
|
34
|
+
|
33
35
|
# Not documented parameters. Subject to change in future release
|
34
36
|
config_param :aws_sqs_process_interval, :integer, :default => 1
|
35
37
|
config_param :aws_sqs_monitor_interval, :integer, :default => 10
|
@@ -70,7 +72,7 @@ class Fluent::ForwardAWSInput < Fluent::Input
|
|
70
72
|
unless(@aws_sqs_skiptest)
|
71
73
|
init_aws_sqs_queue()
|
72
74
|
begin
|
73
|
-
@queue.receive_message() do |
|
75
|
+
@queue.receive_message() do |notification|
|
74
76
|
end
|
75
77
|
rescue => e
|
76
78
|
raise Fluent::ConfigError.new("Cannot fetch queue from SQS. Need sqs:ReceiveMessage sqs:DeleteMessage permission for resource " + @aws_sqs_queue_url)
|
@@ -90,10 +92,20 @@ class Fluent::ForwardAWSInput < Fluent::Input
|
|
90
92
|
def run
|
91
93
|
@running = true
|
92
94
|
while true
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
95
|
+
$log.debug "Polling SQS"
|
96
|
+
notificationRaw = @queue.receive_message()
|
97
|
+
if notificationRaw
|
98
|
+
notification = JSON.parse(notificationRaw.as_sns_message.body)
|
99
|
+
$log.debug "Received Notification#{notification}"
|
100
|
+
if(process(notification))
|
101
|
+
if dry_run
|
102
|
+
$log.info "Notification processed in dry-run mode #{notification}"
|
103
|
+
else
|
104
|
+
notificationRaw.delete()
|
105
|
+
$log.debug "Deleted processed notification #{notification}"
|
106
|
+
end
|
107
|
+
else
|
108
|
+
$log.error "Could not process notification, pending... #{notification}"
|
97
109
|
end
|
98
110
|
sleep @aws_sqs_process_interval
|
99
111
|
@locker.synchronize do
|
@@ -110,26 +122,33 @@ class Fluent::ForwardAWSInput < Fluent::Input
|
|
110
122
|
puts e
|
111
123
|
end
|
112
124
|
|
113
|
-
def process(
|
114
|
-
if
|
125
|
+
def process(notification)
|
126
|
+
if notification["type"] == "ping"
|
115
127
|
# Ignore ping message
|
116
128
|
return true
|
117
129
|
end
|
118
|
-
if
|
130
|
+
if notification["type"] == "out"
|
119
131
|
# Silently ignore non matching logs
|
120
|
-
if
|
132
|
+
if notification["bucketname"] != @aws_s3_bucketname
|
133
|
+
$log.debug "Bucketname does not match. Ignoring"
|
121
134
|
return true
|
122
135
|
end
|
123
136
|
if(@channelEnableRegEx)
|
124
|
-
|
137
|
+
unless Regexp.new(@channel).match(notification["channel"])
|
138
|
+
$log.debug "Channel RegEx does not match. Ignoring"
|
139
|
+
return true
|
140
|
+
end
|
125
141
|
else
|
126
|
-
|
142
|
+
unless @channel == notification["channel"]
|
143
|
+
$log.debug "Channel does not match. Ignoring"
|
144
|
+
return true
|
145
|
+
end
|
127
146
|
end
|
128
|
-
|
129
147
|
tmpFile = Tempfile.new("forward-aws-")
|
130
148
|
begin
|
131
149
|
#Download log file to temporary file
|
132
|
-
@
|
150
|
+
$log.debug "Download log object from S3 bucket #{@aws_s3_bucketname} path #{notification["path"]}"
|
151
|
+
@bucket.objects[notification["path"]].read do |chunk|
|
133
152
|
tmpFile.write(chunk)
|
134
153
|
end
|
135
154
|
tmpFile.close()
|
@@ -108,6 +108,7 @@ class Fluent::ForwardAWSOutput < Fluent::TimeSlicedOutput
|
|
108
108
|
begin
|
109
109
|
chunk.write_to(writer)
|
110
110
|
writer.close
|
111
|
+
$log.debug "Upload log object to S3 bucket #{@aws_s3_bucketname} path #{s3path}"
|
111
112
|
@bucket.objects[s3path].write(Pathname.new(tmpFile.path), :content_type => 'application/x-gzip')
|
112
113
|
notification = {
|
113
114
|
"type" => "out",
|
@@ -118,6 +119,7 @@ class Fluent::ForwardAWSOutput < Fluent::TimeSlicedOutput
|
|
118
119
|
"compression" => compression
|
119
120
|
}
|
120
121
|
topic = @sns.topics[@aws_sns_topic_arn]
|
122
|
+
$log.debug "Posting notification #{notification}"
|
121
123
|
topic.publish(JSON.pretty_generate(notification), :subject => @aws_sns_emailsubject)
|
122
124
|
ensure
|
123
125
|
writer.close rescue nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-forward-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|