fluent-plugin-cloudtrail 0.0.2
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 +7 -0
- data/LICENSE.txt +21 -0
- data/lib/fluent/plugin/in_cloudtrail.rb +148 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c05ee14755f1d40a3b69861617604e852f7fbf6c
|
4
|
+
data.tar.gz: c5d6dc68799c5cb2d714515a06edf2b788a05faa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd5fd648bb46d8b36b6878d32a0b6d4ad50455860684ff2de5304a3e25ec45570919c15351decc9eb6529d7e6bf753d3473d498a8e8c94d66a4f5751a55f9d67
|
7
|
+
data.tar.gz: 97eb583ae6103f70ed133d483dc92fbe91d1e95f69677c78df1bd0e0b88b9d5eb47c2f3f9b390d4bdf89fbec5a5f477c71848ccea80ad45af44097f9230187e9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Blend Labs, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'stringio'
|
3
|
+
require 'zlib'
|
4
|
+
require 'aws-sdk'
|
5
|
+
|
6
|
+
module Fluent
|
7
|
+
|
8
|
+
class CloudtrailInput < Input
|
9
|
+
USER_AGENT_NAME = 'fluent-plugin-cloudtrail-in'
|
10
|
+
PLUGIN_VERSION = '0.0.1'
|
11
|
+
|
12
|
+
Plugin.register_input('cloudtrail', self)
|
13
|
+
|
14
|
+
define_method('log') { $log } unless method_defined?(:log)
|
15
|
+
define_method('router') { Engine } unless method_defined?(:router)
|
16
|
+
|
17
|
+
config_param :aws_key_id, :string, :default => nil, :secret => true
|
18
|
+
config_param :aws_sec_key, :string, :default => nil, :secret => true
|
19
|
+
# The 'region' parameter is optional because
|
20
|
+
# it may be set as an environment variable.
|
21
|
+
config_param :region, :string, :default => nil
|
22
|
+
|
23
|
+
config_param :profile, :string, :default => nil
|
24
|
+
config_param :credentials_path, :string, :default => nil
|
25
|
+
config_param :role_arn, :string, :default => nil
|
26
|
+
config_param :external_id, :string, :default => nil
|
27
|
+
|
28
|
+
config_param :sqs_url, :string
|
29
|
+
config_param :receive_interval, :time, :default => 0.1
|
30
|
+
config_param :max_number_of_messages, :integer, :default => 10
|
31
|
+
config_param :wait_time_seconds, :integer, :default => 10
|
32
|
+
|
33
|
+
config_param :http_proxy, :string, :default => nil
|
34
|
+
config_param :debug, :bool, :default => false
|
35
|
+
|
36
|
+
config_param :tag, :string
|
37
|
+
|
38
|
+
def configure(conf)
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def start
|
47
|
+
super
|
48
|
+
load_clients
|
49
|
+
@finished = false
|
50
|
+
@thread = Thread.new(&method(:run_periodic))
|
51
|
+
end
|
52
|
+
|
53
|
+
def shutdown
|
54
|
+
super
|
55
|
+
@finished = true
|
56
|
+
@thread.join
|
57
|
+
end
|
58
|
+
|
59
|
+
def load_clients
|
60
|
+
user_agent_suffix = "#{USER_AGENT_NAME}/#{PLUGIN_VERSION}"
|
61
|
+
options = {
|
62
|
+
user_agent_suffix: user_agent_suffix
|
63
|
+
}
|
64
|
+
if @region
|
65
|
+
options[:region] = @region
|
66
|
+
end
|
67
|
+
|
68
|
+
if @aws_key_id && @aws_sec_key
|
69
|
+
options.update(
|
70
|
+
access_key_id: @aws_key_id,
|
71
|
+
secret_access_key: @aws_sec_key,
|
72
|
+
)
|
73
|
+
elsif @profile
|
74
|
+
credentials_opts = {:profile_name => @profile}
|
75
|
+
credentials_opts[:path] = @credentials_path if @credentials_path
|
76
|
+
credentials = Aws::SharedCredentials.new(credentials_opts)
|
77
|
+
options[:credentials] = credentials
|
78
|
+
elsif @role_arn
|
79
|
+
credentials = Aws::AssumeRoleCredentials.new(
|
80
|
+
client: Aws::STS::Client.new(options),
|
81
|
+
role_arn: @role_arn,
|
82
|
+
role_session_name: "fluent-plugin-cloudtrail",
|
83
|
+
external_id: @external_id,
|
84
|
+
duration_seconds: 60 * 60,
|
85
|
+
)
|
86
|
+
options[:credentials] = credentials
|
87
|
+
end
|
88
|
+
|
89
|
+
if @debug
|
90
|
+
options.update(
|
91
|
+
logger: Logger.new(log.out),
|
92
|
+
log_level: :debug
|
93
|
+
)
|
94
|
+
# XXX: Add the following options, if necessary
|
95
|
+
# :http_wire_trace => true
|
96
|
+
end
|
97
|
+
|
98
|
+
if @http_proxy
|
99
|
+
options[:http_proxy] = @http_proxy
|
100
|
+
end
|
101
|
+
|
102
|
+
@s3_client = Aws::S3::Client.new(options)
|
103
|
+
@sqs_client = Aws::SQS::Client.new(options)
|
104
|
+
end
|
105
|
+
|
106
|
+
def run_periodic
|
107
|
+
until @finished
|
108
|
+
begin
|
109
|
+
sleep @receive_interval
|
110
|
+
sqs_resp = @sqs_client.receive_message(
|
111
|
+
queue_url: @sqs_url,
|
112
|
+
max_number_of_messages: @max_number_of_messages,
|
113
|
+
wait_time_seconds: @wait_time_seconds
|
114
|
+
)
|
115
|
+
for message in sqs_resp.messages
|
116
|
+
body_obj = JSON.parse(message.body)
|
117
|
+
message_obj = JSON.parse(body_obj['Message'])
|
118
|
+
s3_bucket = message_obj['s3Bucket']
|
119
|
+
for s3_object_key in message_obj['s3ObjectKey']
|
120
|
+
s3_resp = @s3_client.get_object(
|
121
|
+
:bucket => s3_bucket,
|
122
|
+
:key => s3_object_key
|
123
|
+
)
|
124
|
+
io = StringIO.new
|
125
|
+
io.write s3_resp.body.read
|
126
|
+
io.rewind
|
127
|
+
gz = Zlib::GzipReader.new(io)
|
128
|
+
cloudtrail_data = gz.read
|
129
|
+
gz.close
|
130
|
+
cloudtrail_records = JSON.parse(cloudtrail_data)['Records']
|
131
|
+
for record in cloudtrail_records
|
132
|
+
router.emit(@tag, Time.now.to_i, record)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
@sqs_client.delete_message(
|
137
|
+
queue_url: @sqs_url,
|
138
|
+
receipt_handle: message.receipt_handle
|
139
|
+
)
|
140
|
+
end
|
141
|
+
rescue
|
142
|
+
log.error "failed to emit", :error => $!.to_s, :error_class => $!.class.to_s
|
143
|
+
log.warn_backtrace $!.backtrace
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-cloudtrail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Craig Buchanan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.58
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.58
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: aws-sdk
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2'
|
47
|
+
description:
|
48
|
+
email: craig+rubygems@blendlabs.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- LICENSE.txt
|
54
|
+
- lib/fluent/plugin/in_cloudtrail.rb
|
55
|
+
homepage: https://github.com/blend/fluent-plugin-cloudtrail
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.6.8
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Fluentd input plugin that inputs logs from AWS CloudTrail.
|
79
|
+
test_files: []
|