New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rackspace Cloud Files input. #772
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'fog' | ||
require 'stringio' | ||
require 'zlib' | ||
require 'logstash/inputs/base' | ||
require 'logstash/namespace' | ||
|
||
class LogStash::Inputs::CloudFiles < LogStash::Inputs::Base | ||
milestone 1 | ||
config_name 'cloud_files' | ||
|
||
default :codec, 'line' | ||
|
||
config :username, :validate => :string, :required => true | ||
config :api_key, :validate => :string, :required => true | ||
config :region, :validate => :string, :required => true | ||
config :container, :validate => :string, :required => true | ||
config :interval, :validate => :number, :default => 60 | ||
config :sincedb_path, :validate => :string, :required => true | ||
|
||
def register | ||
@api = Fog::Storage.new(:provider => 'Rackspace', :rackspace_username => @username, :rackspace_api_key => @api_key, :rackspace_region => @region) | ||
end | ||
|
||
def run(queue) | ||
loop do | ||
process_log_files(queue) | ||
sleep(@interval) | ||
end | ||
|
||
finished | ||
end | ||
|
||
private | ||
|
||
def process_log_files(queue) | ||
last_read = sincedb_read | ||
|
||
container = @api.directories.get(@container) | ||
container.files.each do |file| | ||
process_file(queue, file) if file.last_modified > last_read | ||
end | ||
end | ||
|
||
def process_file(queue, file) | ||
log_stream = StringIO.new(file.body) | ||
reader = Zlib::GzipReader.new(log_stream) | ||
|
||
@codec.decode(reader.read) do |event| | ||
decorate(event) | ||
queue << event | ||
end | ||
|
||
sincedb_write(file.last_modified) | ||
end | ||
|
||
def sincedb_read | ||
if File.exists?(@sincedb_path) | ||
since = Time.parse(File.read(@sincedb_path)) | ||
else | ||
since = Time.new(0) | ||
end | ||
|
||
since | ||
end | ||
|
||
def sincedb_write(since) | ||
File.open(@sincedb_path, 'w') { |f| f.write(since.to_s) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines codec will already split a byte stream up into events.
I also think it might be a good idea to omit the gzip assumptions here. This should be a codec as well so all can benefit regardless of if its compressed or not.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickethier Sorry for taking so long to get back to you. I'm about to push a change that uses the line codec to read the inflated GZip stream rather than defaulting to the plain codec.
I had planned to extract the GZip assumption to a codec but couldn't find much documentation on codecs. My first attempt was simply a wrapper around the line codec that inflated the GZip stream and passed it off the line codec. However, I wasn't quite sure what the implementation of the encode method should look like. Any suggestions?