Class: Fluent::WinEvtLog::PositionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_winevtlog.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, map, last_pos) ⇒ PositionFile



208
209
210
211
212
# File 'lib/fluent/plugin/in_winevtlog.rb', line 208

def initialize(file, map, last_pos)
  @file = file
  @map = map
  @last_pos = last_pos
end

Class Method Details

.parse(file) ⇒ Object

parsing file and rebuild mysself



228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/fluent/plugin/in_winevtlog.rb', line 228

def self.parse(file)
  map = {}
  file.pos = 0
  file.each_line {|line|
    # check and get a matched line as m

    m = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/.match(line)
    next unless m
    cat = m[1] 
    pos = m[2].to_i(16)
    seek = file.pos - line.bytesize + cat.bytesize + 1
    map[cat] = FilePositionEntry.new(file, seek)
  }
  new(file, map, file.pos)
end

Instance Method Details

#[](cat) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/fluent/plugin/in_winevtlog.rb', line 214

def [](cat)
  if m = @map[cat]
    return m
  end
  @file.pos = @last_pos
  @file.write cat
  @file.write "\t"
  seek = @file.pos
  @file.write "00000000\t00000000\n"
  @last_pos = @file.pos
  @map[cat] = FilePositionEntry.new(@file, seek)
end