class Fluent::WinEvtLog
Attributes
chs[R]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_winevtlog.rb, line 32 def initialize super @chs = [] @keynames = [] @tails = {} end
Public Instance Methods
close_watcher(wlw)
click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 103 def close_watcher(wlw) wlw.close # flush_buffer(wlw) end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_winevtlog.rb, line 39 def configure(conf) super @chs = @channel.split(',').map {|ch| ch.strip.downcase }.uniq if @chs.empty? raise ConfigError, "winevtlog: 'channel' parameter is required on winevtlog input" end @keynames = @key.split(',').map {|k| k.strip }.uniq if @keynames.empty? @keynames = @@KEY_MAP.keys end @tag = tag @stop = false end
receive_lines(ch, lines, pe)
click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 115 def receive_lines(ch, lines, pe) return if lines.empty? begin for r in lines h = {"channel" => ch} @keynames.each {|k| h[k]=r.send(@@KEY_MAP[k]).to_s} #h = Hash[@keynames.map {|k| [k, r.send(@@KEY_MAP[k]).to_s]}] router.emit(@tag, Engine.now, h) pe[1] +=1 end rescue $log.error "unexpected error", :error=>$!.to_s $log.error_backtrace end end
run()
click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 108 def run @loop.run rescue $log.error "unexpected error", :error=>$!.to_s $log.error_backtrace end
setup_wacther(ch, pe)
click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 72 def setup_wacther(ch, pe) wlw = WindowsLogWatcher.new(@read_interval, ch, pe, &method(:receive_lines)) wlw.attach(@loop) wlw end
shutdown()
click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 65 def shutdown stop_watchers(@tails.keys, true) @loop.stop rescue nil @thread.join @pf_file.close if @pf_file end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_winevtlog.rb, line 53 def start super if @pos_file @pf_file = File.open(@pos_file, File::RDWR|File::CREAT|File::BINARY) @pf_file.sync = true @pf = PositionFile.parse(@pf_file) end @loop = Coolio::Loop.new start_watchers(@chs) @thread = Thread.new(&method(:run)) end
start_watchers(chs)
click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 78 def start_watchers(chs) chs.each { |ch| pe = nil if @pf pe = @pf[ch] if @read_from_head && pe.read_num.zero? el = EventLog.open(ch) pe.update(el.oldest_record_number-1,1) el.close end end @tails[ch] = setup_wacther(ch, pe) } end
stop_watchers(chs, unwatched = false)
click to toggle source
# File lib/fluent/plugin/in_winevtlog.rb, line 93 def stop_watchers(chs, unwatched = false) chs.each { |ch| wlw = @tails.delete(ch) if wlw wlw.unwatched = unwatched close_watcher(wlw) end } end