Class: Embulk::InputPcapngFiles

Inherits:
InputPlugin
  • Object
show all
Defined in:
lib/embulk/input_pcapng_files.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, schema, index, page_builder) ⇒ InputPcapngFiles

Returns a new instance of InputPcapngFiles.



41
42
43
# File 'lib/embulk/input_pcapng_files.rb', line 41

def initialize(task, schema, index, page_builder)
  super
end

Instance Attribute Details

#page_builderObject (readonly)

Returns the value of attribute page_builder.



47
48
49
# File 'lib/embulk/input_pcapng_files.rb', line 47

def page_builder
  @page_builder
end

#schemaObject (readonly)

Returns the value of attribute schema.



46
47
48
# File 'lib/embulk/input_pcapng_files.rb', line 46

def schema
  @schema
end

#taskObject (readonly)

Returns the value of attribute task.



45
46
47
# File 'lib/embulk/input_pcapng_files.rb', line 45

def task
  @task
end

Class Method Details

.transaction(config, &control) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/embulk/input_pcapng_files.rb', line 8

def self.transaction(config, &control)
  task = {
    'paths' => [],
    'done' => config.param('done', :array, default: []),
  }

  task['paths'] = config.param('paths', :array, default: []).map {|path|
    next [] unless Dir.exists?(path)
    Dir.entries(path).sort.select {|entry| entry.match(/^.+\.pcapng$/)}.map {|entry|
      path + "/" + entry
    }
  }.flatten
  task['paths'] = task['paths'] - task['done']

  if task['paths'].empty?
    raise "no valid pcapng file found"
  end

  schema = config.param('schema', :array, default: [])
  columns = []
  columns << Column.new(0, "path", :string)
  idx = 0
  columns.concat schema.map{|c|
    idx += 1
    Column.new(idx, "#{c['name']}", c['type'].to_sym)
  }

  commit_reports = yield(task, columns, task['paths'].length)
  done = commit_reports.map{|hash| hash["done"]}.flatten.compact

  return {"done" => done}
end

Instance Method Details

#runObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/embulk/input_pcapng_files.rb', line 49

def run
  path = task['paths'][@index]
  each_packet(path, schema[1..-1].map{|elm| elm.name}) do |hash|
    entry = [ path ] + schema[1..-1].map {|c|
      convert(hash[c.name], c.type)
    }
    @page_builder.add(entry)
  end
  @page_builder.finish # must call finish they say

  return {"done" => path}
end