Skip to content

Commit

Permalink
add timestamp type field, use_basename
Browse files Browse the repository at this point in the history
Signed-off-by: enukane <enukane@glenda9.org>
  • Loading branch information
enukane committed Dec 20, 2015
1 parent a818417 commit 2922769
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Obsoletes enukane/embulk-plugin-input-pcapng-files
|:---|:---|:--------|:------|:----------|
| paths | array | required | [] | paths where pcapng files exist (no recursive searching|
| convertdot | string | optional | nil | convert "." in field name (for outputing into DB who doesn't accept "dot" in schema)|
| use\_basename | bool | optional | false | use basename (w/o ext) as "path" value |
| schema| array of field hash | required | nil | list of field to extract from pcapng file |
|field hash| hash ({name, type}) | required | nil | "name" matches field name for tshakr (-e), "type" should be "long", "double", "string" |
|field hash| hash ({name, type}) | required | nil | "name" matches field name for tshakr (-e), "type" should be "long", "double", "string", "timestamp" |

## Example

Expand All @@ -31,7 +32,7 @@ in:
threads: 2
schema:
- { name: frame.number, type: long }
- { name: frame.time_epoch, type: double }
- { name: frame.time_epoch, type: timestamp }
- { name: frame.len, type: long }
- { name: wlan_mgt.ssid, type: string }
```
Expand Down
2 changes: 1 addition & 1 deletion embulk-input-pcapng-files.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Gem::Specification.new do |spec|
spec.name = "embulk-input-pcapng-files"
spec.version = "0.1.4"
spec.version = "0.1.5"
spec.authors = ["enukane"]
spec.summary = "Pcapng Files input plugin for Embulk"
spec.description = "Pcapng Files input plugin for Embulk"
Expand Down
8 changes: 7 additions & 1 deletion lib/embulk/input/pcapng_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Embulk
module Plugin
require "csv"
require "time"

class InputPcapngFiles < InputPlugin
Plugin.register_input("pcapng_files", self)
Expand All @@ -11,6 +12,7 @@ def self.transaction(config, &control)
'paths' => [],
'done' => config.param('done', :array, default: []),
'convertdot' => config.param('convertdot', :string, default: nil),
'use_basename' => config.param('use_basename', :bool, default: false),
}

task['paths'] = config.param('paths', :array, default: []).map {|path|
Expand Down Expand Up @@ -53,7 +55,9 @@ def initialize(task, schema, index, page_builder)
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|
entry = []
entry << (task['use_basename'] ? File.basename(path, File.extname(path)) : path)
entry += schema[1..-1].map {|c|
convert(hash[c.name], c.type)
}
@page_builder.add(entry)
Expand All @@ -77,6 +81,8 @@ def convert val, type
end
when :double
v = v.to_f
when :timestamp
v = Time.at(v.to_f)
end
return v
end
Expand Down

0 comments on commit 2922769

Please sign in to comment.