fluent-plugin-splunkhec 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +74 -0
- data/Rakefile +11 -0
- data/fluent-plugin-splunkhec.gemspec +24 -0
- data/lib/fluent/plugin/out_splunkhec.rb +122 -0
- data/test/helper.rb +31 -0
- data/test/plugin/test_out_splunkhec.rb +28 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: '0988078609653d3278e1ef55802b037f10ed324b'
|
4
|
+
data.tar.gz: 972ec8325c5b39922faa4a216e7b04a43053f7c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a352c9a7087d95048050d81ba319e43f3e13038277568f5649c52f35baec9a40f8c48a4d7092a07c3b5dce009cf6e2c0e1146f60dc8bfb9fe2aa8d39abecd209
|
7
|
+
data.tar.gz: 90ca57989e7b435a6971f24ec3b5f2acfb370762956f3271a7189d3401acc03c6520ea0d72c33bba0051d6766e5928d5836bae6421f79d0ea91a753f9cddd23f
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017 Coen Meerbeek
|
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,74 @@
|
|
1
|
+
# fluent-plugin-splunkhec, a plugin for [Fluentd](http://fluentd.org)
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
***Splunk HTTP Event Collector*** output plugin.
|
6
|
+
|
7
|
+
Output data from any Fluent input plugin to the Splunk HTTP Event Collector (Splunk HEC).
|
8
|
+
|
9
|
+
The Splunk HEC is running on a Heavy Forwarder or single instance. More info about the Splunk HEC architecture in a distributed environment can be found in the Splunk [Docs](http://dev.splunk.com/view/event-collector/SP-CAAAE73)
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
```config
|
14
|
+
<match splunkhec>
|
15
|
+
@type splunkhec
|
16
|
+
host splunk.bluefactory.nl
|
17
|
+
protocol https #optional
|
18
|
+
port 8080 #optional
|
19
|
+
token BAB747F3-744E-41BA
|
20
|
+
index main #optional
|
21
|
+
event_host fluentdhost #optional
|
22
|
+
source fluentd #optional
|
23
|
+
sourcetype data:type #optional
|
24
|
+
</source>
|
25
|
+
```
|
26
|
+
|
27
|
+
## config: host
|
28
|
+
|
29
|
+
The host where the Splunk HEC is listening (Heavy Forwarder or Single Instance).
|
30
|
+
|
31
|
+
## config: protocol
|
32
|
+
|
33
|
+
The protocol on which the Splunk HEC is listening. If you are going to use HTTPS make sure you use a signed certificate. Weak certificates are a work in progress.
|
34
|
+
|
35
|
+
## config: port
|
36
|
+
|
37
|
+
The port on which the Splunk HEC is listening.
|
38
|
+
|
39
|
+
## config: token
|
40
|
+
|
41
|
+
Every Splunk HEC requires a token to recieve data. You must configure this insite Splunk [Splunk HEC docs](http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector).
|
42
|
+
Put the token here.
|
43
|
+
|
44
|
+
## config: index
|
45
|
+
|
46
|
+
The index on the Splunk side to store the data in. Please be aware that the Splunk HTTP Event Collector you've created has the permissions to write to this index. If you don't specify this the plug-in will use "main".
|
47
|
+
|
48
|
+
## config: event_host
|
49
|
+
|
50
|
+
Specify the host-field for the event data in Splunk. If you don't specify this the plug-in will try to read the hostname running FluentD.
|
51
|
+
|
52
|
+
## config: source
|
53
|
+
|
54
|
+
Specify the source-field for the event data in Splunk. If you don't specify this the plug-in will use "fluentd".
|
55
|
+
|
56
|
+
## config: sourcetype
|
57
|
+
|
58
|
+
Specify the sourcetype-field for the event data in Splunk. If you don't specify this the plug-in will use the tag from the FluentD input plug-in.
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
67
|
+
|
68
|
+
## TODO
|
69
|
+
|
70
|
+
* Add support for SSL verification.
|
71
|
+
|
72
|
+
## Copyright
|
73
|
+
|
74
|
+
Copyright (c) 2017 Coen Meerbeek. See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: 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 |gem|
|
6
|
+
gem.name = "fluent-plugin-splunkhec"
|
7
|
+
gem.version = "1.0.0"
|
8
|
+
gem.authors = "Coen Meerbeek"
|
9
|
+
gem.email = "cmeerbeek@gmail.com"
|
10
|
+
gem.description = %q{Output plugin for the Splunk HTTP Event Collector.}
|
11
|
+
gem.homepage = "https://github.com/cmeerbeek/fluent-plugin-splunkhec"
|
12
|
+
gem.summary = %q{This plugin allows you to sent events to the Splunk HTTP Event Collector.}
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency "fluentd", [">= 0.10.58", "< 2"]
|
20
|
+
gem.add_dependency "json", '~> 2.0', '>= 2.0.2'
|
21
|
+
gem.add_development_dependency "rake", '~> 0.9', '>= 0.9.2'
|
22
|
+
gem.add_development_dependency "test-unit", '~> 3.1', '>= 3.1.0'
|
23
|
+
gem.license = 'MIT'
|
24
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'fluent/output'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Fluent
|
6
|
+
class SplunkHECOutput < BufferedOutput
|
7
|
+
Fluent::Plugin.register_output('splunkhec', self)
|
8
|
+
|
9
|
+
# Primary Splunk HEC configuration parameters
|
10
|
+
config_param :host, :string, :default => 'localhost', :required => true
|
11
|
+
config_param :protocol, :string, :default => 'http', :required => true
|
12
|
+
config_param :port, :string, :default => '8088', :required => true
|
13
|
+
config_param :token, :string, :default => nil, :required => true
|
14
|
+
|
15
|
+
# Splunk event parameters
|
16
|
+
config_param :index, :string, :default => "main"
|
17
|
+
config_param :event_host, :string, :default => nil
|
18
|
+
config_param :source, :string, :default => "fluentd"
|
19
|
+
config_param :sourcetype, :string, :default => nil
|
20
|
+
|
21
|
+
# This method is called before starting.
|
22
|
+
# Here we construct the Splunk HEC URL to POST data to
|
23
|
+
# If the configuration is invalid, raise Fluent::ConfigError.
|
24
|
+
def configure(conf)
|
25
|
+
super
|
26
|
+
|
27
|
+
@protocol = conf['protocol']
|
28
|
+
|
29
|
+
@splunk_url = @protocol + '://' + conf['host'] + ':' + conf['port'] + '/services/collector/event'
|
30
|
+
log.debug 'splunkhec: sent data to ' + @splunk_url
|
31
|
+
if conf['token'] != nil
|
32
|
+
@token = conf['token']
|
33
|
+
else
|
34
|
+
raise 'splunkhec: token is empty, please provide a token for this plugin to work'
|
35
|
+
end
|
36
|
+
|
37
|
+
if conf['event_host'] == nil
|
38
|
+
@event_host = `hostname`
|
39
|
+
@event_host = @event_host.delete!("\n")
|
40
|
+
else
|
41
|
+
@event_host = conf['event_host']
|
42
|
+
end
|
43
|
+
|
44
|
+
if conf['sourcetype'] == nil
|
45
|
+
@event_sourcetype = 'tag'
|
46
|
+
else
|
47
|
+
@event_sourcetype = conf['sourcetype']
|
48
|
+
end
|
49
|
+
|
50
|
+
@event_index = @index
|
51
|
+
@event_source = @source
|
52
|
+
end
|
53
|
+
|
54
|
+
def start
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
58
|
+
def shutdown
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
# This method is called when an event reaches to Fluentd.
|
63
|
+
# Use msgpack to serialize the object.
|
64
|
+
def format(tag, time, record)
|
65
|
+
[tag, time, record].to_msgpack
|
66
|
+
end
|
67
|
+
|
68
|
+
# Loop through all records and sent them to Splunk
|
69
|
+
def write(chunk)
|
70
|
+
begin
|
71
|
+
chunk.msgpack_each {|(tag,time,record)|
|
72
|
+
# Parse record to Splunk event format
|
73
|
+
case record
|
74
|
+
when Fixnum
|
75
|
+
event = record.to_s
|
76
|
+
when Hash
|
77
|
+
event = record.to_json.gsub("\"", %q(\\\"))
|
78
|
+
else
|
79
|
+
event = record
|
80
|
+
end
|
81
|
+
|
82
|
+
if @event_sourcetype == 'tag'
|
83
|
+
@event_sourcetype = tag
|
84
|
+
end
|
85
|
+
|
86
|
+
# Build body for the POST request
|
87
|
+
body = '{"time" :' + time.to_s + ', "event" :"' + event + '", "sourcetype" :"' + @event_sourcetype + '", "source" :"' + @event_source + '", "index" :"' + @event_index + '", "host" : "' + @event_host + '"}'
|
88
|
+
log.debug "splunkhec: " + body + "\n"
|
89
|
+
|
90
|
+
uri = URI(@splunk_url)
|
91
|
+
|
92
|
+
# Create client
|
93
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
94
|
+
|
95
|
+
# Create Request
|
96
|
+
req = Net::HTTP::Post.new(uri)
|
97
|
+
# Add headers
|
98
|
+
req.add_field "Authorization", "Splunk #{@token}"
|
99
|
+
# Add headers
|
100
|
+
req.add_field "Content-Type", "application/json; charset=utf-8"
|
101
|
+
# Set body
|
102
|
+
req.body = body
|
103
|
+
# Handle SSL
|
104
|
+
if @protocol == 'https'
|
105
|
+
http.use_ssl = true
|
106
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
107
|
+
end
|
108
|
+
|
109
|
+
# Fetch Request
|
110
|
+
res = http.request(req)
|
111
|
+
log.debug "splunkhec: response HTTP Status Code is #{res.code}"
|
112
|
+
if res.code.to_i != 200
|
113
|
+
log.debug "splunkhec: response body is #{res.body}"
|
114
|
+
end
|
115
|
+
}
|
116
|
+
rescue => err
|
117
|
+
log.fatal("splunkhec: caught exception; exiting")
|
118
|
+
log.fatal(err)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'fluent/input'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require "test/unit"
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
require "fluent/test"
|
17
|
+
unless ENV.has_key?("VERBOSE")
|
18
|
+
nulllogger = Object.new
|
19
|
+
nulllogger.instance_eval {|obj|
|
20
|
+
def method_missing(method, *args)
|
21
|
+
#pass
|
22
|
+
end
|
23
|
+
}
|
24
|
+
$log = nulllogger
|
25
|
+
end
|
26
|
+
|
27
|
+
require "fluent/plugin/in_splunkhec"
|
28
|
+
|
29
|
+
class Test::Unit::TestCase
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class SplunkHECOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
### for Splunk HEC
|
9
|
+
CONFIG_SPLUNKHEC = %[
|
10
|
+
host splunk.bluefactory.nl
|
11
|
+
protocol https
|
12
|
+
port 8443
|
13
|
+
token BAB747F3-744E-41BA
|
14
|
+
]
|
15
|
+
|
16
|
+
def create_driver_ga(conf = CONFIG_SPLUNKHEC)
|
17
|
+
Fluent::Test::InputTestDriver.new(Fluent::SplunkHECOutput).configure(conf)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_configure_splunkhec
|
21
|
+
d = create_driver_splunkhec
|
22
|
+
assert_equal 'splunk.bluefactory.nl', d.instance.host
|
23
|
+
assert_equal 'https' , d.instance.protocol
|
24
|
+
assert_equal '8443' , d.instance.port
|
25
|
+
assert_equal 'BAB747F3-744E-41BA', d.instance.token
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-splunkhec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Coen Meerbeek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-09 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.58
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.58
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.0.2
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.0.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rake
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.9'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.9.2
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.9'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.9.2
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: test-unit
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '3.1'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.0
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.1'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 3.1.0
|
93
|
+
description: Output plugin for the Splunk HTTP Event Collector.
|
94
|
+
email: cmeerbeek@gmail.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- CHANGELOG.md
|
100
|
+
- Gemfile
|
101
|
+
- LICENSE
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- fluent-plugin-splunkhec.gemspec
|
105
|
+
- lib/fluent/plugin/out_splunkhec.rb
|
106
|
+
- test/helper.rb
|
107
|
+
- test/plugin/test_out_splunkhec.rb
|
108
|
+
homepage: https://github.com/cmeerbeek/fluent-plugin-splunkhec
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.6.8
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: This plugin allows you to sent events to the Splunk HTTP Event Collector.
|
132
|
+
test_files:
|
133
|
+
- test/helper.rb
|
134
|
+
- test/plugin/test_out_splunkhec.rb
|