fluent-plugin-osquery 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rspec +4 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/fluent-plugin-osquery.gemspec +26 -0
- data/lib/fluent/plugin/in_osquery.rb +70 -0
- data/spec/fluent/plugin/in_osquery_spec.rb +61 -0
- data/spec/spec_helper.rb +2 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a35243f92b59c17f93ae42d4075b496bf08c2758
|
4
|
+
data.tar.gz: 42fae7a7a65e9fc67f91353892ab541220a94561
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34668a58e03e1d4fa56ca87e9fa71ab2a6b1a9d5dea6287f57fcd983445551ae66fd2b779e1acf99f18f2679344d5261e684508cbe00affb9da157b3d059463d
|
7
|
+
data.tar.gz: b785dd36deb24bcd5a5a5489dfd9076841381669ae7b2fbe43c76127f87b901a825f55be0f70fe5eb162766a5bb43192164d2b98381304bd813926bd10d094ad
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Hidenori Suzuki
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
## fluent-plugin-osquery
|
2
|
+
|
3
|
+
[osquery](https://osquery.io/) input plugin
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fluent-plugin-osquery'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fluent-plugin-osquery
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
### Example
|
22
|
+
|
23
|
+
<source>
|
24
|
+
type osquery
|
25
|
+
tag osquery
|
26
|
+
interval 60
|
27
|
+
query select * from processes
|
28
|
+
</source>
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new [Pull Request](../../pull/new/master)
|
37
|
+
|
38
|
+
## Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2015 Hidenori Suzuki. See [LICENSE](LICENSE) for details.
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'fluent-plugin-osquery'
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ['Hidenori Suzuki']
|
9
|
+
spec.email = ['hidenori.suzuki@yahoo.com']
|
10
|
+
spec.summary = 'a fluent plugin'
|
11
|
+
spec.description = 'osquery input plugin'
|
12
|
+
spec.homepage = 'https://github.com/6pongi/fluent-plugin-osquery'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'fluentd', '~> 0.10.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'test-unit'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Fluent
|
3
|
+
class OsqueryInput < Fluent::Input
|
4
|
+
Fluent::Plugin.register_input('osquery', self)
|
5
|
+
config_param :tag, :string, default: 'osquery'
|
6
|
+
config_param :interval, :integer, default: 60
|
7
|
+
config_param :query, :string, default: 'select * from processes'
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
require 'json'
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(conf)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
@loop = Coolio::Loop.new
|
20
|
+
@tw = TimerWatcher.new(interval, true, log, &method(:execute))
|
21
|
+
@tw.attach(@loop)
|
22
|
+
@thread = Thread.new(&method(:run))
|
23
|
+
end
|
24
|
+
|
25
|
+
def shutdown
|
26
|
+
@tw.detach
|
27
|
+
@loop.stop
|
28
|
+
@thread.join
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
@loop.run
|
33
|
+
rescue => e
|
34
|
+
@log.error 'unexpected error', error: e.to_s
|
35
|
+
@log.error_backtrace
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def execute
|
41
|
+
@time = Engine.now
|
42
|
+
cmd = "osqueryi --json \"#{@query}\""
|
43
|
+
@log.debug(cmd)
|
44
|
+
record = `#{cmd}`
|
45
|
+
jsonrec = JSON.parse(record)
|
46
|
+
jsonrec.each do |line|
|
47
|
+
@log.debug(line)
|
48
|
+
Engine.emit(@tag, @time, line)
|
49
|
+
end
|
50
|
+
rescue => e
|
51
|
+
@log.error('faild to run', error: e.to_s, error_class: e.class.to_s)
|
52
|
+
@log.error_backtrace
|
53
|
+
end
|
54
|
+
|
55
|
+
class TimerWatcher < Coolio::TimerWatcher
|
56
|
+
def initialize(interval, repeat, log, &callback)
|
57
|
+
@log = log
|
58
|
+
@callback = callback
|
59
|
+
super(interval, repeat)
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_timer
|
63
|
+
@callback.call
|
64
|
+
rescue => e
|
65
|
+
@log.error e.to_s
|
66
|
+
@log.error_backtrace
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
BASE_CONFIG = %(
|
3
|
+
type osquery
|
4
|
+
tag hoge
|
5
|
+
)
|
6
|
+
|
7
|
+
CONFIG = BASE_CONFIG + %(
|
8
|
+
interval 1
|
9
|
+
)
|
10
|
+
|
11
|
+
describe Fluent::OsqueryInput do
|
12
|
+
before do
|
13
|
+
Fluent::Test.setup
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#configure' do
|
17
|
+
let(:d) do
|
18
|
+
Fluent::Test::InputTestDriver.new(Fluent::OsqueryInput)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'test of test' do
|
22
|
+
it 'getting config' do
|
23
|
+
instance = d.configure(CONFIG).instance
|
24
|
+
expect(instance.interval).to eq 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#run' do
|
31
|
+
let(:d) do
|
32
|
+
Fluent::Test::InputTestDriver.new(Fluent::OsqueryInput)
|
33
|
+
.configure(config)
|
34
|
+
end
|
35
|
+
|
36
|
+
before do
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'interval test' do
|
40
|
+
before do
|
41
|
+
end
|
42
|
+
context 'in case interval=1' do
|
43
|
+
let(:config) { BASE_CONFIG + 'interval 1' }
|
44
|
+
|
45
|
+
it '2 execute in 2 sec' do
|
46
|
+
expect(d.instance).to receive(:execute).exactly(2)
|
47
|
+
d.run { sleep 2.0 }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'in case interval=2' do
|
52
|
+
let(:config) { BASE_CONFIG + 'interval 2' }
|
53
|
+
it '1 execute in sec' do
|
54
|
+
expect(d.instance).to receive(:execute).exactly(1)
|
55
|
+
d.run { sleep 2.0 }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-osquery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hidenori Suzuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: osquery input plugin
|
84
|
+
email:
|
85
|
+
- hidenori.suzuki@yahoo.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- fluent-plugin-osquery.gemspec
|
97
|
+
- lib/fluent/plugin/in_osquery.rb
|
98
|
+
- spec/fluent/plugin/in_osquery_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: https://github.com/6pongi/fluent-plugin-osquery
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.4.5
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: a fluent plugin
|
124
|
+
test_files:
|
125
|
+
- spec/fluent/plugin/in_osquery_spec.rb
|
126
|
+
- spec/spec_helper.rb
|