Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ spec/fixtures
test/tmp
test/version_tmp
tmp
.rbenv*
5 changes: 3 additions & 2 deletions lib/woodchuck/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

class Woodchuck::Agent

attr_accessor :logger, :watcher, :watcher_thread, :paths, :output
attr_accessor :logger, :watcher, :watcher_thread, :paths, :output, :type

def initialize(options={})
@paths = options[:paths]
@logger = Woodchuck::Logger.new(::STDOUT)
@mutex = Mutex.new
@type = options[:type] || 'file'
@output = case options[:output]
when :stdout
Woodchuck::Output::STDOUT.new
Expand All @@ -22,7 +23,7 @@ def initialize(options={})
else
Woodchuck::Output::STDOUT.new
end
@watcher = Woodchuck::Watcher.new(self, @paths)
@watcher = Woodchuck::Watcher.new(self, @paths, @type)
end

def start(blocking=false)
Expand Down
7 changes: 4 additions & 3 deletions lib/woodchuck/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class Woodchuck::Event

attr_accessor :path, :line, :host, :timestamp, :source, :message, :fields, :tags
attr_accessor :path, :line, :host, :timestamp, :source, :message, :fields, :tags, :type

def initialize(path, line)
def initialize(path, line, type)
@path = path
@line = line
@host = Socket.gethostname
Expand All @@ -13,6 +13,7 @@ def initialize(path, line)
@message = line.strip
@fields = {}
@tags = []
@type = type
end

def method_missing(symbol, *args, &block)
Expand All @@ -26,7 +27,7 @@ def method_missing(symbol, *args, &block)
def to_hash
{
'@source' => source.to_s,
'@type' => source.scheme,
'@type' => type,
'@tags' => tags,
'@fields' => fields,
'@timestamp' => timestamp,
Expand Down
5 changes: 3 additions & 2 deletions lib/woodchuck/output/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
require 'redis/namespace'

class Woodchuck::Output::Redis < Woodchuck::Output
attr_accessor :url, :host, :port, :db, :namespace
attr_accessor :url, :host, :port, :db, :namespace, :key

def initialize
super
@type = :redis
@url = Addressable::URI.parse(ENV['REDIS_URL'] || 'redis://localhost:6379/9')
@namespace = ENV['REDIS_NAMESPACE'] || 'logstash:woodchuck'
@key = ENV['REDIS_KEY'] || 'events'
end

def redis
Expand All @@ -17,7 +18,7 @@ def redis
end

def handle(event)
redis.lpush("events", event.to_json)
redis.lpush(key, event.to_json)
@logger.info "Logging event to Redis", event.to_hash
end
end
3 changes: 3 additions & 0 deletions lib/woodchuck/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def read(args=ARGV)
opts.on('-p', '--paths [PATHS]', Array, 'A list of file paths to watch') do |paths|
options[:paths] = paths
end
opts.on('-t', '--type [TYPE]', 'set logstash type') do |type|
options[:type] = type
end
end
optparse.parse!(args)
options
Expand Down
2 changes: 1 addition & 1 deletion lib/woodchuck/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Woodchuck
VERSION = "0.0.1"
VERSION = "0.0.2"
end
7 changes: 4 additions & 3 deletions lib/woodchuck/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@
class Woodchuck::Watcher
extend Forwardable

attr_accessor :tailer, :paths, :logger, :events, :agent
attr_accessor :tailer, :paths, :logger, :events, :agent, :type
def_delegator :@agent, :output, :output

def initialize(agent, *paths)
def initialize(agent, *paths, type)
@agent = agent
@logger = Woodchuck::Logger.new(::STDOUT)
@tailer = FileWatch::Tail.new
@paths = paths.flatten
@type = type
end

def start
paths.each do |path|
tailer.tail(path)
end
tailer.subscribe do |path, line|
event = Woodchuck::Event.new(path, line)
event = Woodchuck::Event.new(path, line, type)
output.handle(event)
end
end
Expand Down