embulk-input-splunk 0.1.1
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 +40 -0
- data/Rakefile +3 -0
- data/embulk-input-splunk.gemspec +20 -0
- data/lib/embulk/input/splunk.rb +95 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 97cceb8fac1ece34ef872c15aa8861d735d9307c89450ac8ce343a440c855062
|
4
|
+
data.tar.gz: 896b3b1543169a45aeb94494817b9136064cdb566c72449caf41dca28473a38b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb553e46a762d8fd09b5655bd1c0621c1d5bf28396c00059cd1a1809cf768d6b70f2dc3bbaf47785899bea94807c73b069bf542bd6b5b47e9ff7494c60a301c0
|
7
|
+
data.tar.gz: '085667e45da0411d52b783def58e0c5187d337113e6913b37651f9159843fea76d44a573f1be69283d04375d9e54ba25a78656e4d25b45f4eba270a9a9ecb558'
|
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,40 @@
|
|
1
|
+
# Splunk input plugin for Embulk
|
2
|
+
|
3
|
+
A simple plug-in to run a once-off Splunk query and emit the results.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* **Plugin type**: input
|
8
|
+
* **Resume supported**: no
|
9
|
+
* **Cleanup supported**: no
|
10
|
+
* **Guess supported**: no
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
|
14
|
+
- **type**: splunk
|
15
|
+
- **host**: host of your splunk server (string, required)
|
16
|
+
- **username**: splunk username (string, required)
|
17
|
+
- **password**: splunk password (string, required)
|
18
|
+
- **port**: splunk API port (integer, default: 8089)
|
19
|
+
- **query**: the query you wish to run. It should be prefixed with "search" (string required)
|
20
|
+
|
21
|
+
## Example
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
in:
|
25
|
+
type: splunk
|
26
|
+
host: splunk.example.com
|
27
|
+
username: splunk_user
|
28
|
+
password: abc123
|
29
|
+
port: 8089
|
30
|
+
query: "search index="main" | head 10"
|
31
|
+
out:
|
32
|
+
type: stdout
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
## Build
|
37
|
+
|
38
|
+
```
|
39
|
+
$ rake
|
40
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-input-splunk"
|
4
|
+
spec.version = "0.1.1"
|
5
|
+
spec.authors = ["Scott Arbeitman"]
|
6
|
+
spec.summary = "Splunk input plugin for Embulk"
|
7
|
+
spec.description = "Loads records from a Splunk query."
|
8
|
+
spec.email = ["scott.arbeitman+gem@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
|
11
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
12
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
13
|
+
spec.require_paths = ["lib"]
|
14
|
+
|
15
|
+
spec.add_dependency 'splunk-sdk-ruby'
|
16
|
+
spec.add_dependency 'activesupport'
|
17
|
+
spec.add_development_dependency 'embulk', ['>= 0.8.39']
|
18
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
19
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
20
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'splunk-sdk-ruby'
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'digest'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Embulk
|
7
|
+
module Input
|
8
|
+
|
9
|
+
class Splunk < InputPlugin
|
10
|
+
Plugin.register_input("splunk", self)
|
11
|
+
|
12
|
+
# Zero means unlimited results. Splunk's default is 100.
|
13
|
+
SPLUNK_UNLIMITED_RESULTS = 0
|
14
|
+
SPLUNK_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%L%:z"
|
15
|
+
|
16
|
+
def self.transaction(config, &control)
|
17
|
+
# configuration code:
|
18
|
+
task = {
|
19
|
+
"host" => config.param("host", :string),
|
20
|
+
"port" => config.param("port", :integer, default: 8089),
|
21
|
+
"username" => config.param("username", :string),
|
22
|
+
"password" => config.param("password", :string),
|
23
|
+
"query" => config.param("query", :string),
|
24
|
+
"incremental" => config.param("incremental", :bool, default: false),
|
25
|
+
"time_format" => config.param("time_format", :string, default: SPLUNK_TIME_FORMAT),
|
26
|
+
|
27
|
+
"earliest_time" => config.param(:earliest_time, :string, default: "2010-01-01T00:00:00.000"),
|
28
|
+
}
|
29
|
+
|
30
|
+
columns = [
|
31
|
+
Column.new(0, "time", :timestamp),
|
32
|
+
Column.new(1, "result", :json),
|
33
|
+
]
|
34
|
+
|
35
|
+
resume(task, columns, 1, &control)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.resume(task, columns, count, &control)
|
39
|
+
task_reports = yield(task, columns, count)
|
40
|
+
|
41
|
+
next_config_diff = {}
|
42
|
+
|
43
|
+
if task["incremental"]
|
44
|
+
next_config_diff[:earliest_time] = Time.parse( task_reports.first[:latest_time_in_results] ).strftime(SPLUNK_TIME_FORMAT)
|
45
|
+
end
|
46
|
+
|
47
|
+
return next_config_diff
|
48
|
+
end
|
49
|
+
|
50
|
+
def init
|
51
|
+
# initialization code:
|
52
|
+
splunk_config = {
|
53
|
+
:scheme => :https,
|
54
|
+
:host => task[:host],
|
55
|
+
:port => task[:port],
|
56
|
+
:username => task[:username],
|
57
|
+
:password => task[:password]
|
58
|
+
}
|
59
|
+
|
60
|
+
@service = ::Splunk::connect(splunk_config)
|
61
|
+
@query = task["query"]
|
62
|
+
@earliest_time = task[:earliest_time]
|
63
|
+
end
|
64
|
+
|
65
|
+
def run
|
66
|
+
stream = @service.create_oneshot(@query,
|
67
|
+
count: SPLUNK_UNLIMITED_RESULTS,
|
68
|
+
earliest_time: @earliest_time)
|
69
|
+
|
70
|
+
reader = ::Splunk::ResultsReader.new(stream)
|
71
|
+
|
72
|
+
latest_time_in_results = Time.at(0)
|
73
|
+
|
74
|
+
reader.each do |result|
|
75
|
+
event_time = Time.strptime( result["_time"], task[:time_format] )
|
76
|
+
latest_time_in_results = [latest_time_in_results, event_time].max
|
77
|
+
|
78
|
+
page_builder.add( [
|
79
|
+
event_time,
|
80
|
+
result.to_json
|
81
|
+
] )
|
82
|
+
end
|
83
|
+
|
84
|
+
page_builder.finish
|
85
|
+
|
86
|
+
task_result = {
|
87
|
+
latest_time_in_results: latest_time_in_results
|
88
|
+
}
|
89
|
+
|
90
|
+
return task_result
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-input-splunk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Arbeitman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: splunk-sdk-ruby
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: activesupport
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.39
|
47
|
+
name: embulk
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.39
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.10.6
|
61
|
+
name: bundler
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.10.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
name: rake
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Loads records from a Splunk query.
|
84
|
+
email:
|
85
|
+
- scott.arbeitman+gem@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- embulk-input-splunk.gemspec
|
96
|
+
- lib/embulk/input/splunk.rb
|
97
|
+
homepage:
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.6.13
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Splunk input plugin for Embulk
|
121
|
+
test_files: []
|