embulk-input-pcapng-files 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +4 -0
- data/embulk-input-pcapng-files.gemspec +19 -0
- data/lib/embulk/input/pcapng_files.rb +100 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69e97377eb1f448aff29a146b9ca094890679c3d
|
4
|
+
data.tar.gz: 8a1676181c8ade5d7f4aa00aa1faf6cb2118a32d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc11de0cd8f250eec3ff9cf1255f8fb6e19f0dc67d647c70b1b970ccdf0daadba3d782eb6036151308c2df391aa768eb8c7b257dc8db1998d86724e07feab02a
|
7
|
+
data.tar.gz: b647a945a5f65f4fee7ec95405a4716a1458cc97ae10fb6c2aac6980321dc6d9fb0e1d22c19c9b2a368d3b4c03e973fd4b1563d9e59e16b9534d7f050c92363f
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Pcapng Files input plugin for Embulk
|
2
|
+
|
3
|
+
embulk plugin for pcapng files input.
|
4
|
+
|
5
|
+
Obsoletes enukane/embulk-plugin-input-pcapng-files
|
6
|
+
|
7
|
+
## Overview
|
8
|
+
|
9
|
+
* **Plugin type**: input
|
10
|
+
* **Load all or nothing**: yes
|
11
|
+
* **Resume supported**: no
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
- **paths**: Paths to search pcapng (not recursive)
|
16
|
+
- **schema**: List of fields to extract
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
in:
|
22
|
+
type: pcapng_files
|
23
|
+
paths: [ /Users/enukane/Desktop/emtestpcap/ ]
|
24
|
+
threads: 2
|
25
|
+
schema:
|
26
|
+
- { name: frame.number, type: long }
|
27
|
+
- { name: frame.time_epoch, type: long }
|
28
|
+
- { name: frame.len, type: long }
|
29
|
+
```
|
30
|
+
|
31
|
+
## Build
|
32
|
+
|
33
|
+
```
|
34
|
+
$ rake
|
35
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-input-pcapng-files"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["enukane"]
|
6
|
+
spec.summary = "Pcapng Files input plugin for Embulk"
|
7
|
+
spec.description = "Pcapng Files input plugin for Embulk"
|
8
|
+
spec.email = ["enukane@glenda9.org"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/enukane/embulk-input-pcapng-files"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
#spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
|
17
|
+
spec.add_development_dependency 'bundler', ['~> 1.0']
|
18
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
19
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
|
2
|
+
module Embulk
|
3
|
+
module Plugin
|
4
|
+
require "csv"
|
5
|
+
|
6
|
+
class InputPcapngFiles < InputPlugin
|
7
|
+
Plugin.register_input("pcapng_files", self)
|
8
|
+
|
9
|
+
def self.transaction(config, &control)
|
10
|
+
task = {
|
11
|
+
'paths' => [],
|
12
|
+
'done' => config.param('done', :array, default: []),
|
13
|
+
}
|
14
|
+
|
15
|
+
task['paths'] = config.param('paths', :array, default: []).map {|path|
|
16
|
+
next [] unless Dir.exists?(path)
|
17
|
+
Dir.entries(path).sort.select {|entry| entry.match(/^.+\.pcapng$/)}.map {|entry|
|
18
|
+
path + "/" + entry
|
19
|
+
}
|
20
|
+
}.flatten
|
21
|
+
task['paths'] = task['paths'] - task['done']
|
22
|
+
|
23
|
+
if task['paths'].empty?
|
24
|
+
raise "no valid pcapng file found"
|
25
|
+
end
|
26
|
+
|
27
|
+
schema = config.param('schema', :array, default: [])
|
28
|
+
columns = []
|
29
|
+
columns << Column.new(0, "path", :string)
|
30
|
+
idx = 0
|
31
|
+
columns.concat schema.map{|c|
|
32
|
+
idx += 1
|
33
|
+
Column.new(idx, "#{c['name']}", c['type'].to_sym)
|
34
|
+
}
|
35
|
+
|
36
|
+
commit_reports = yield(task, columns, task['paths'].length)
|
37
|
+
done = commit_reports.map{|hash| hash["done"]}.flatten.compact
|
38
|
+
|
39
|
+
return {"done" => done}
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize(task, schema, index, page_builder)
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_reader :task
|
47
|
+
attr_reader :schema
|
48
|
+
attr_reader :page_builder
|
49
|
+
|
50
|
+
def run
|
51
|
+
path = task['paths'][@index]
|
52
|
+
each_packet(path, schema[1..-1].map{|elm| elm.name}) do |hash|
|
53
|
+
entry = [ path ] + schema[1..-1].map {|c|
|
54
|
+
convert(hash[c.name], c.type)
|
55
|
+
}
|
56
|
+
@page_builder.add(entry)
|
57
|
+
end
|
58
|
+
@page_builder.finish # must call finish they say
|
59
|
+
|
60
|
+
return {"done" => path}
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def convert val, type
|
66
|
+
v = val
|
67
|
+
v = "" if val == nil
|
68
|
+
v = v.to_i if type == :long
|
69
|
+
return v
|
70
|
+
end
|
71
|
+
|
72
|
+
def build_options(fields)
|
73
|
+
options = ""
|
74
|
+
fields.each do |field|
|
75
|
+
options += "-e '#{field}' "
|
76
|
+
end
|
77
|
+
return options
|
78
|
+
end
|
79
|
+
|
80
|
+
def each_packet(path, fields, &block)
|
81
|
+
options = build_options(fields)
|
82
|
+
io = IO.popen("tshark -E separator=, #{options} -T fields -r #{path}")
|
83
|
+
while line = io.gets
|
84
|
+
array = [fields, CSV.parse(line).flatten].transpose
|
85
|
+
yield(Hash[*array.flatten])
|
86
|
+
end
|
87
|
+
io.close
|
88
|
+
end
|
89
|
+
|
90
|
+
def fetch_from_pcap(path, fields)
|
91
|
+
options = build_options(fields)
|
92
|
+
io = IO.popen("tshark -E separator=, #{options} -T fields -r #{path}")
|
93
|
+
data = io.read
|
94
|
+
io.close
|
95
|
+
return data
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-input-pcapng-files
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- enukane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Pcapng Files input plugin for Embulk
|
42
|
+
email:
|
43
|
+
- enukane@glenda9.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- embulk-input-pcapng-files.gemspec
|
54
|
+
- lib/embulk/input/pcapng_files.rb
|
55
|
+
homepage: https://github.com/enukane/embulk-input-pcapng-files
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.2.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Pcapng Files input plugin for Embulk
|
79
|
+
test_files: []
|