logstash-output-mongodb 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 +4 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/Rakefile +7 -0
- data/lib/logstash/outputs/mongodb.rb +82 -0
- data/logstash-output-mongodb.gemspec +29 -0
- data/spec/outputs/mongodb_spec.rb +1 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f28406293865e2c1f78c4b9e9089c34a140b83c1
|
4
|
+
data.tar.gz: 5928ffb667b9327e99607daf555f0aa0facd83ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b012550a084244ceeb28f358a511a5a8b14c6f0d0c1347de61ce279d297b810135ec08b6b13022073142202780cdbd06f9271c59b5b8ccd3fc40b7fad2772886
|
7
|
+
data.tar.gz: 397d84997bc388dff5c3e88b6cde19f7f5d7195bfe0744efd36dece83bc75b623cd9e407b71e3700cc1b8e50367a9f061e3d5713dc96b05b8073f0135d2fcee5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012-2014 Elasticsearch <http://www.elasticsearch.org>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/outputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
|
6
|
+
class LogStash::Outputs::Mongodb < LogStash::Outputs::Base
|
7
|
+
|
8
|
+
config_name "mongodb"
|
9
|
+
milestone 2
|
10
|
+
|
11
|
+
# a MongoDB URI to connect to
|
12
|
+
# See http://docs.mongodb.org/manual/reference/connection-string/
|
13
|
+
config :uri, :validate => :string, :required => true
|
14
|
+
|
15
|
+
# The database to use
|
16
|
+
config :database, :validate => :string, :required => true
|
17
|
+
|
18
|
+
# The collection to use. This value can use `%{foo}` values to dynamically
|
19
|
+
# select a collection based on data in the event.
|
20
|
+
config :collection, :validate => :string, :required => true
|
21
|
+
|
22
|
+
# If true, store the @timestamp field in mongodb as an ISODate type instead
|
23
|
+
# of an ISO8601 string. For more information about this, see
|
24
|
+
# http://www.mongodb.org/display/DOCS/Dates
|
25
|
+
config :isodate, :validate => :boolean, :default => false
|
26
|
+
|
27
|
+
# Number of seconds to wait after failure before retrying
|
28
|
+
config :retry_delay, :validate => :number, :default => 3, :required => false
|
29
|
+
|
30
|
+
# If true, an "_id" field will be added to the document before insertion.
|
31
|
+
# The "_id" field will use the timestamp of the event and overwrite an existing
|
32
|
+
# "_id" field in the event.
|
33
|
+
config :generateId, :validate => :boolean, :default => false
|
34
|
+
|
35
|
+
public
|
36
|
+
def register
|
37
|
+
require "mongo"
|
38
|
+
uriParsed=Mongo::URIParser.new(@uri)
|
39
|
+
conn = uriParsed.connection({})
|
40
|
+
if uriParsed.auths.length > 0
|
41
|
+
uriParsed.auths.each do |auth|
|
42
|
+
if !auth['db_name'].nil?
|
43
|
+
conn.add_auth(auth['db_name'], auth['username'], auth['password'], nil)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
conn.apply_saved_authentication()
|
47
|
+
end
|
48
|
+
@db = conn.db(@database)
|
49
|
+
end # def register
|
50
|
+
|
51
|
+
public
|
52
|
+
def receive(event)
|
53
|
+
return unless output?(event)
|
54
|
+
|
55
|
+
begin
|
56
|
+
if @isodate
|
57
|
+
# the mongodb driver wants time values as a ruby Time object.
|
58
|
+
# set the @timestamp value of the document to a ruby Time object, then.
|
59
|
+
document = event.to_hash
|
60
|
+
else
|
61
|
+
document = event.to_hash.merge("@timestamp" => event["@timestamp"].to_json)
|
62
|
+
end
|
63
|
+
if @generateId
|
64
|
+
document['_id'] = BSON::ObjectId.new(nil, event["@timestamp"])
|
65
|
+
end
|
66
|
+
@db.collection(event.sprintf(@collection)).insert(document)
|
67
|
+
rescue => e
|
68
|
+
@logger.warn("Failed to send event to MongoDB", :event => event, :exception => e,
|
69
|
+
:backtrace => e.backtrace)
|
70
|
+
if e.error_code == 11000
|
71
|
+
# On a duplicate key error, skip the insert.
|
72
|
+
# We could check if the duplicate key err is the _id key
|
73
|
+
# and generate a new primary key.
|
74
|
+
# If the duplicate key error is on another field, we have no way
|
75
|
+
# to fix the issue.
|
76
|
+
else
|
77
|
+
sleep @retry_delay
|
78
|
+
retry
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end # def receive
|
82
|
+
end # class LogStash::Outputs::Mongodb
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-output-mongodb'
|
4
|
+
s.version = '0.1.1'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "Store events into MongoDB"
|
7
|
+
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"
|
8
|
+
s.authors = ["Elasticsearch"]
|
9
|
+
s.email = 'info@elasticsearch.com'
|
10
|
+
s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
|
15
|
+
|
16
|
+
# Tests
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
|
19
|
+
# Special flag to let us know this is actually a logstash plugin
|
20
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
|
21
|
+
|
22
|
+
# Gem dependencies
|
23
|
+
s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'
|
24
|
+
|
25
|
+
s.add_runtime_dependency 'mongo'
|
26
|
+
|
27
|
+
s.add_development_dependency 'logstash-devutils'
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-output-mongodb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elasticsearch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-19 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: 1.4.0
|
19
|
+
- - <
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
name: logstash
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.4.0
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
name: mongo
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
name: logstash-devutils
|
54
|
+
prerelease: false
|
55
|
+
type: :development
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
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
|
62
|
+
email: info@elasticsearch.com
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- .gitignore
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- Rakefile
|
71
|
+
- lib/logstash/outputs/mongodb.rb
|
72
|
+
- logstash-output-mongodb.gemspec
|
73
|
+
- spec/outputs/mongodb_spec.rb
|
74
|
+
homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
|
75
|
+
licenses:
|
76
|
+
- Apache License (2.0)
|
77
|
+
metadata:
|
78
|
+
logstash_plugin: 'true'
|
79
|
+
logstash_group: output
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.1.9
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Store events into MongoDB
|
100
|
+
test_files:
|
101
|
+
- spec/outputs/mongodb_spec.rb
|