logstash-output-solr_post 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/NOTICE.TXT +1 -0
- data/README.md +109 -0
- data/lib/logstash/outputs/solr_post.rb +71 -0
- data/logstash-output-solr_post.gemspec +31 -0
- data/spec/outputs/solr_post_spec.rb +1 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79da3dd21bdb0425816f168fce414d11a8763a16
|
4
|
+
data.tar.gz: 8d3aeb443b8f9521ff4f3288e25c59b406285c21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e31426fb6b39ff2da93ba760203fb46fb5988cbcf61527d5847c26a4cf7c87320f9278b4fb235b4025c57cfb6f721f94b07178ca21c70fc69855f7ed25628ac
|
7
|
+
data.tar.gz: cfd045529ea9d0e4a6b0b8cd1db448988eed3c5f7aae3059a8d09ceff8e12ec5cdc544ffc4b92abd185a7eb186f7d3db7528e4810ce77931481df54fdc485252
|
data/Gemfile
ADDED
data/NOTICE.TXT
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
|
4
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
5
|
+
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
10
|
+
|
11
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
12
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
13
|
+
|
14
|
+
## Why this plugin
|
15
|
+
|
16
|
+
When setting up logging stacks, we weren't able to use the [solr_http](https://rubygems.org/gems/logstash-output-solr_http) output plugin in logstash conf to talk to solr
|
17
|
+
On the other hand, we found SiLK 1.5 stack is shipping its own customized version of logstash, which is a java jar file.
|
18
|
+
Though the example provided with customized version of [SiLK logstash](https://docs.lucidworks.com/display/SiLK/Solr+Writer+for+Logstash+Initial+Setup) was able to pipe events to solr server, our needs were
|
19
|
+
|
20
|
+
1. We already had a logstash server running for a while and it had a great ecosystem of input, filter and output plugins
|
21
|
+
2. We would like to use this existing logstash server and NOT have to re-invent the wheel
|
22
|
+
3. We want multiple conf files to be loaded by logstash server, which the SiLK 1.5 solrWriter for logstash did not allow as per their documentation
|
23
|
+
|
24
|
+
Specifically, we want the same [logstash server](https://www.elastic.co/products/logstash) (that elastic search provides) to work with solr. It should be as simple as install a plugin, write the output conf and see the pipeline work, by viewing the events on the other side of solr
|
25
|
+
|
26
|
+
## Installing and using
|
27
|
+
|
28
|
+
1. git clone
|
29
|
+
2. JRUBY >=1.7 (We tried with MRI Ruby, however that did not go well. Guess because logstash is developed in JRUBY)
|
30
|
+
3. If you are on windows, use pik and switch to use jruby (pik use <identifier>). If on *nix, use rvm to switch to jruby
|
31
|
+
4. jgem build logstash-output-solr_post.gemspec (output should be a gem like logstash-output-solr_post-0.1.gem
|
32
|
+
5. Copy this gem to ~/logstash root folder
|
33
|
+
6. Install as output plugin to logstash using "./bin/plugin install logstash-output-solr_post-0.1.gem"
|
34
|
+
7. ./bin/plugin list to verify that the plugin installed successfully and registered as output plugin
|
35
|
+
8. See the next section on usage instructions
|
36
|
+
|
37
|
+
## How does this plugin do it
|
38
|
+
|
39
|
+
It is possible to do a simple http POST to solr end point and post documents. Hence, we wrote simple logic extending logstash output base class and POST the event to solr endpoint. Of course, since solr expects the http post payload to be in a certain format, we format the event and then directly do a POST. That is it!
|
40
|
+
|
41
|
+
## Working Example
|
42
|
+
|
43
|
+
### Solr
|
44
|
+
Version: 5.3.1
|
45
|
+
**Note:** We tried starting solr in schemaless mode (gettingstarted collection automatically created), however we did not have success posting events directly to http://localhost:8983/solr/update?commit=true&wt=json endpoint
|
46
|
+
|
47
|
+
### Logstash (2.0.0) conf
|
48
|
+
```
|
49
|
+
input {
|
50
|
+
tcp {
|
51
|
+
type => "eventlog"
|
52
|
+
port => 5544
|
53
|
+
codec=> "json"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
output {
|
57
|
+
solr_post{
|
58
|
+
solr_url => "http://localhost:8983/solr/mycollection/update?commit=true&wt=json"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
```
|
62
|
+
where 'mycollection' is the name of your collection. We require collection name in the url
|
63
|
+
|
64
|
+
### Windows nxlog (nxlog-ce-2.9.1347) conf
|
65
|
+
```
|
66
|
+
<Extension json>
|
67
|
+
Module xm_json
|
68
|
+
</Extension>
|
69
|
+
|
70
|
+
<Extension xml>
|
71
|
+
Module xm_xml
|
72
|
+
</Extension>
|
73
|
+
|
74
|
+
<Input in>
|
75
|
+
Module im_msvistalog
|
76
|
+
Exec $raw_event=to_json();
|
77
|
+
</Input>
|
78
|
+
|
79
|
+
<Output out>
|
80
|
+
Module om_tcp
|
81
|
+
Host 127.0.0.1
|
82
|
+
Port 5544
|
83
|
+
</Output>
|
84
|
+
|
85
|
+
<Route r>
|
86
|
+
Path in => out
|
87
|
+
</Route>
|
88
|
+
```
|
89
|
+
|
90
|
+
We have used the above conf and were able to use this plugin to pipe events through the pipeline. We were also able to view the events in Banana. Below is how it looked for us
|
91
|
+
|
92
|
+
![Banana Dashboard](https://github.com/machzqcq/logstash-output-solr_post/blob/master/images/banana_dashboard.JPG "Banana Dashboard")
|
93
|
+
|
94
|
+
## TODO
|
95
|
+
|
96
|
+
1. Use idle flush time, flush size & documents parameters (currently it is declared inside the code but not used)
|
97
|
+
2. Write rspec unit tests
|
98
|
+
3. Support for XML (depends on need for the community)
|
99
|
+
4. Register this plugin for logstash plugin binary
|
100
|
+
5. Miscellaneous
|
101
|
+
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
1. Fork it
|
106
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
107
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
108
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
109
|
+
5. Create new Pull Request
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/outputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "stud/buffer"
|
5
|
+
require "rubygems"
|
6
|
+
require "uuidtools"
|
7
|
+
require "net/http"
|
8
|
+
require "uri"
|
9
|
+
require "json"
|
10
|
+
|
11
|
+
# You can learn more at https://lucene.apache.org/solr/[the Solr home page]
|
12
|
+
|
13
|
+
class LogStash::Outputs::SolrPost < LogStash::Outputs::Base
|
14
|
+
include Stud::Buffer
|
15
|
+
|
16
|
+
config_name "solr_post"
|
17
|
+
|
18
|
+
|
19
|
+
# URL used to connect to Solr
|
20
|
+
config :solr_url, :validate => :string
|
21
|
+
|
22
|
+
# Number of events to queue up before writing to Solr
|
23
|
+
config :flush_size, :validate => :number, :default => 100
|
24
|
+
|
25
|
+
# Amount of time since the last flush before a flush is done even if
|
26
|
+
# the number of buffered events is smaller than flush_size
|
27
|
+
config :idle_flush_time, :validate => :number, :default => 1
|
28
|
+
|
29
|
+
# Solr document ID for events. You'd typically have a variable here, like
|
30
|
+
# '%{foo}' so you can assign your own IDs
|
31
|
+
config :document_id, :validate => :string, :default => nil
|
32
|
+
|
33
|
+
public
|
34
|
+
def register
|
35
|
+
buffer_initialize(
|
36
|
+
:max_items => @flush_size,
|
37
|
+
:max_interval => @idle_flush_time,
|
38
|
+
:logger => @logger
|
39
|
+
)
|
40
|
+
end #def register
|
41
|
+
|
42
|
+
public
|
43
|
+
def receive(event)
|
44
|
+
|
45
|
+
buffer_receive(event)
|
46
|
+
end #def receive
|
47
|
+
|
48
|
+
public
|
49
|
+
def flush(events, close=false)
|
50
|
+
# The documents array below is NOT being used currently, however the next version will utilize this.
|
51
|
+
documents = [] #this is the array of hashes that we push to Solr as documents
|
52
|
+
|
53
|
+
events.each do |event|
|
54
|
+
document = event.to_hash()
|
55
|
+
document["@timestamp"] = document["@timestamp"].iso8601 #make the timestamp ISO
|
56
|
+
if @document_id.nil?
|
57
|
+
document["id"] = UUIDTools::UUID.random_create #add a unique ID
|
58
|
+
else
|
59
|
+
document["id"] = event.sprintf(@document_id) #or use the one provided
|
60
|
+
end
|
61
|
+
url = URI.parse(@solr_url)
|
62
|
+
req = Net::HTTP::Post.new(@solr_url, initheader = {'Content-Type' =>'application/json'})
|
63
|
+
req.body = '{add:{ doc:' + JSON.generate(document) + ',boost:1.0,overwrite:true,commitWithin:1000}}'
|
64
|
+
res = Net::HTTP.start(url.host,url.port) do |http|
|
65
|
+
http.request(req)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
rescue Exception => e
|
69
|
+
@logger.warn("An error occurred while indexing: #{e.message}")
|
70
|
+
end #def flush
|
71
|
+
end #class LogStash::Outputs::SolrPost
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-output-solr_post'
|
4
|
+
s.version = '0.1'
|
5
|
+
s.licenses = ['MIT']
|
6
|
+
s.email = ['pradeep@seleniumframework.com']
|
7
|
+
s.licenses = ['MIT']
|
8
|
+
s.summary = "This output lets you index&store your logs in Solr."
|
9
|
+
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
10
|
+
s.authors = ["Pradeep K. Macharla","Venkatesh R. Peruvemba"]
|
11
|
+
s.homepage = "https://github.com/machzqcq/logstash-output-solr_post.git"
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
|
14
|
+
# Files
|
15
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
16
|
+
|
17
|
+
# Tests
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
|
20
|
+
# Special flag to let us know this is actually a logstash plugin
|
21
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
|
22
|
+
|
23
|
+
# Gem dependencies
|
24
|
+
s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
|
25
|
+
|
26
|
+
s.add_runtime_dependency 'stud'
|
27
|
+
s.add_runtime_dependency 'uuidtools'
|
28
|
+
|
29
|
+
s.add_development_dependency 'logstash-devutils'
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-output-solr_post
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pradeep K. Macharla
|
8
|
+
- Venkatesh R. Peruvemba
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-12-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0.beta2
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
name: logstash-core
|
24
|
+
prerelease: false
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.0.0.beta2
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
name: stud
|
41
|
+
prerelease: false
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
name: uuidtools
|
55
|
+
prerelease: false
|
56
|
+
type: :runtime
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
name: logstash-devutils
|
69
|
+
prerelease: false
|
70
|
+
type: :development
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
77
|
+
email:
|
78
|
+
- pradeep@seleniumframework.com
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- lib/logstash/outputs/solr_post.rb
|
84
|
+
- spec/outputs/solr_post_spec.rb
|
85
|
+
- logstash-output-solr_post.gemspec
|
86
|
+
- README.md
|
87
|
+
- Gemfile
|
88
|
+
- NOTICE.TXT
|
89
|
+
homepage: https://github.com/machzqcq/logstash-output-solr_post.git
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
logstash_plugin: 'true'
|
94
|
+
logstash_group: output
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.1.9
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: This output lets you index&store your logs in Solr.
|
115
|
+
test_files:
|
116
|
+
- spec/outputs/solr_post_spec.rb
|