embulk-parser-pcapng 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26c42e5ecca711a75978d4769cb38af825e261b4
4
+ data.tar.gz: ee755ea6067360ccd6aa6cf8b3223782a229cace
5
+ SHA512:
6
+ metadata.gz: 3d4004302b91128d40fa212c7907e34149eaf875618335a324cc1cb788b07318fbffdbcafc580c02a8d6bbf62417b307e04bede67367968b8ed063e868e27860
7
+ data.tar.gz: 7d0a56109fb766ab8eb8efcc5fcd6fba6e156f86645fb2fd40e8d070ecf991ec94a0b98ffe923d38283e6c9d68e44ab610e9a7e96419a82f00316dd385da210a
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
@@ -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.
@@ -0,0 +1,31 @@
1
+ # Pcapng parser plugin for Embulk
2
+
3
+ TODO: Write short description here
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: parser
8
+ * **Load all or nothing**: yes
9
+ * **Resume supported**: no
10
+
11
+ ## Configuration
12
+
13
+ - **property1**: description (string, required)
14
+ - **property2**: description (integer, default: default-value)
15
+
16
+ ## Example
17
+
18
+ ```yaml
19
+ in:
20
+ type: any file input plugin type
21
+ parser:
22
+ type: pcapng
23
+ property1: example1
24
+ property2: example2
25
+ ```
26
+
27
+ ## Build
28
+
29
+ ```
30
+ $ rake
31
+ ```
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ Bundler::GemHelper.install_tasks
3
+ task :default => [:build]
@@ -0,0 +1,19 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-parser-pcapng"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["enukane"]
6
+ spec.summary = "Pcapng parser plugin for Embulk"
7
+ spec.description = "Pcapng parser plugin is an Embulk plugin that parses Pcapng file format read by any file input plugins. Search the file input plugins by 'embulk-input file' keywords."
8
+ spec.email = ["enukane@glenda9.org"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/enukane/embulk-parser-pcapng"
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,83 @@
1
+ require "tempfile"
2
+ require "csv"
3
+
4
+ module Embulk
5
+ module Parser
6
+ class PcapngParserPlugin < ParserPlugin
7
+ Plugin.register_parser("pcapng", self)
8
+
9
+ def self.transaction(config, &control)
10
+ schema = config.param("schema", :array, default: [])
11
+ task = {
12
+ "schema" => schema
13
+ }
14
+
15
+ idx = -1
16
+ columns = schema.map{|s|
17
+ idx += 1
18
+ elm = Column.new(idx, "#{s['name']}", s['type'].to_sym)
19
+ }
20
+
21
+ yield(task, columns)
22
+ end
23
+
24
+ def init
25
+ @schema = @task["schema"]
26
+ end
27
+
28
+ def run(file_input)
29
+ while file = file_input.next_file
30
+ tmpf, tmppath = tmppcapng(file.read)
31
+ each_packet(tmppath, @schema.map{|elm| elm["name"]}) do |hash|
32
+ entry = @schema.map{|s| convert(hash[s["name"]], s["type"])}
33
+ page_builder.add(entry)
34
+ end
35
+ tmpf.close
36
+ end
37
+ page_builder.finish
38
+ end
39
+
40
+ private
41
+ def convert val, type
42
+ v = val
43
+ v = "" if val == nil
44
+ v = v.to_i if type == "long"
45
+ v = v.to_f if type == "float"
46
+ return v
47
+ end
48
+
49
+ def build_options(fields)
50
+ options = ""
51
+ fields.each do |field|
52
+ options += "-e '#{field}' "
53
+ end
54
+ return options
55
+ end
56
+
57
+ def tmppcapng(data)
58
+ tmpf = Tempfile.open("pcapng")
59
+ tmpf.write(data)
60
+ tmpf.flush()
61
+ return tmpf, tmpf.path
62
+ end
63
+
64
+ def each_packet(path, fields, &block)
65
+ options = build_options(fields)
66
+ io = IO.popen("tshark -E separator=, #{options} -T fields -r #{path}")
67
+ while line = io.gets
68
+ array = [fields, CSV.parse(line).flatten].transpose
69
+ yield(Hash[*array.flatten])
70
+ end
71
+ io.close
72
+ end
73
+
74
+ def fetch_from_pcap(path, fields)
75
+ options = build_options(fields)
76
+ io = IO.popen("tshark -E separator=, #{options} -T fields -r #{path}")
77
+ data = io.read
78
+ io.close
79
+ return data
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,12 @@
1
+ exec: {}
2
+ in:
3
+ type: file
4
+ path_prefix: "/where/ever/you/like/"
5
+ parser:
6
+ type: pcapng
7
+ schema:
8
+ - { name: frame.number, type: long }
9
+ - { name: frame.time_epoch, type: long }
10
+ - { name: frame.len, type: long }
11
+ out:
12
+ type: stdout
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-parser-pcapng
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-24 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 parser plugin is an Embulk plugin that parses Pcapng file format
42
+ read by any file input plugins. Search the file input plugins by 'embulk-input file'
43
+ keywords.
44
+ email:
45
+ - enukane@glenda9.org
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - embulk-parser-pcapng.gemspec
56
+ - lib/embulk/parser/pcapng.rb
57
+ - sample_config.yml
58
+ homepage: https://github.com/enukane/embulk-parser-pcapng
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Pcapng parser plugin for Embulk
82
+ test_files: []