11 Commits
v1.4 ... v1.5

Author SHA1 Message Date
Karl
b26ac4e141 Update README.md 2016-06-16 16:30:40 +01:00
Karl Southern
aea343fcd9 README update 2015-10-30 17:46:25 +00:00
Karl
470e6309b5 Update README.md 2015-09-04 08:46:50 +01:00
Karl
a7dde52b7b Merge pull request #12 from jMonsinjon/master
Added information for connecting to a MySql Database
2015-09-04 08:44:54 +01:00
Jeremie MONSINJON
53c0f5761d Added information for connecting to a MySql Database 2015-09-03 17:37:51 +02:00
Karl Southern
4287c01037 Small style fix up for patch 2015-07-22 16:30:37 +01:00
Karl
4f93fa7224 Merge pull request #11 from kushtrimjunuzi/master
Handling null values and added boolean data type.
2015-07-22 16:28:06 +01:00
kushtrim junuzi
b52a7358ff Handling null values and added boolean data type.\n Handling jdbc inner exceptions. 2015-07-22 08:06:57 -04:00
Karl Southern
beb8f72560 Fixes up README 2015-06-26 12:57:45 +01:00
Karl Southern
6b6973d6ee Fixes up 1.5+ compatibility 2015-06-26 12:45:45 +01:00
Karl Southern
c790a645f2 Initial commit of 1.5. Untested. Lunchtime is over 2015-06-10 12:31:31 +01:00
6 changed files with 86 additions and 11 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
*.gem
Gemfile.lock
Gemfile.bak
.bundle
vendor

2
Gemfile Normal file
View File

@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gemspec

View File

@@ -1,14 +1,23 @@
# logstash-jdbc
JDBC output plugin for Logstash.
# logstash-output-jdbc
**This is an old version of the plugin, for Logstash v1.5 only. It is no longer receiving backports of fixes and contains several flaws which have been addressed in the Logstash v2 compatible versions, and above. Please upgrade/see the other branches in the source repository.**
This plugin is provided as an external plugin and is not part of the Logstash project.
Currently untested with logstash 1.5+. Support is planned.
This plugin allows you to output to SQL databases, using JDBC adapters.
See below for tested adapters, and example configurations.
## Warning
This has not yet been extensively tested with all JDBC drivers and may not yet work for you.
This plugin does not bundle any JDBC jar files, and does expect them to be in a
particular location. Please ensure you read the 4 installation lines below.
## Versions
- See v1.5 branch for logstash v1.5
- See v1.4 branch for logstash 1.4
## Installation
- Copy lib directory contents into your logstash installation.
- Run `bin/plugin install logstash-output-jdbc` in your logstash installation directory
- Create the directory vendor/jar/jdbc in your logstash installation (`mkdir -p vendor/jar/jdbc/`)
- Add JDBC jar files to vendor/jar/jdbc in your logstash installation
- Configure
@@ -92,4 +101,20 @@ output {
}
```
/* vim: set ts=4 sw=4 tw=0 :*/
### Mysql
With thanks to [@jMonsinjon](https://github.com/jMonsinjon)
* Tested with Version 14.14 Distrib 5.5.43, for debian-linux-gnu (x86_64)
* Tested using http://dev.mysql.com/downloads/file.php?id=457911 (mysql-connector-java-5.1.36-bin.jar)
```
input
{
stdin { }
}
output {
jdbc {
driver_class => "com.mysql.jdbc.Driver"
connection_string => "jdbc:mysql://HOSTNAME/DATABASE?user=USER&password=PASSWORD"
statement => [ "INSERT INTO log (host, timestamp, message) VALUES(?, CAST (? AS timestamp), ?)", "host", "@timestamp", "message" ]
}
}
```

1
Rakefile Normal file
View File

@@ -0,0 +1 @@
require "logstash/devutils/rake"

View File

@@ -9,7 +9,6 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
include Stud::Buffer
config_name "jdbc"
milestone 1
# Driver class
config :driver_class, :validate => :string
@@ -50,11 +49,21 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
public
def register
@logger.info("JDBC - Starting up")
jarpath = File.join(File.dirname(__FILE__), "../../../vendor/jar/jdbc/*.jar")
@logger.info(jarpath)
Dir[jarpath].each do |jar|
if ENV['LOGSTASH_HOME']
jarpath = File.join(ENV['LOGSTASH_HOME'], "/vendor/jar/jdbc/*.jar")
else
jarpath = File.join(File.dirname(__FILE__), "../../../vendor/jar/jdbc/*.jar")
end
@logger.debug("JDBC - jarpath", path: jarpath)
jars = Dir[jarpath]
raise Exception.new("JDBC - No jars found in jarpath. Have you read the README?") if jars.empty?
jars.each do |jar|
@logger.debug("JDBC - Loaded jar", :jar => jar)
require jar
end
@@ -99,7 +108,7 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
@statement[1..-1].each_with_index do |i, idx|
case event[i]
when Time
when Time, LogStash::Timestamp
# Most reliable solution, cross JDBC driver
statement.setString(idx + 1, event[i].iso8601())
when Fixnum, Integer
@@ -108,6 +117,12 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
statement.setFloat(idx + 1, event[i])
when String
statement.setString(idx + 1, event[i])
when true
statement.setBoolean(idx + 1, true)
when false
statement.setBoolean(idx + 1, false)
when nil
statement.setString(idx + 1, nil)
else
statement.setString(idx + 1, event.sprintf(i))
end
@@ -124,6 +139,9 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
# Since the exceutebatch failed this should mean any events failed to be
# inserted will be re-run. We're going to log it for the lols anyway.
@logger.warn("JDBC - Exception. Will automatically retry", :exception => e)
if e.getNextException() != nil
@logger.warn("JDBC - Exception. Will automatically retry", :exception => e.getNextException())
end
end
statement.close()

View File

@@ -0,0 +1,24 @@
Gem::Specification.new do |s|
s.name = 'logstash-output-jdbc'
s.version = "0.1.1"
s.licenses = [ "Apache License (2.0)" ]
s.summary = "This plugin allows you to output to SQL, via JDBC"
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"
s.authors = ["the_angry_angel"]
s.email = "karl+github@theangryangel.co.uk"
s.homepage = "https://github.com/theangryangel/logstash-output-jdbc"
s.require_paths = [ "lib" ]
# Files
s.files = `git ls-files`.split($\)
# Tests
s.test_files = s.files.grep(%r{^(test|spec|features)/})
# Special flag to let us know this is actually a logstash plugin
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
# Gem dependencies
s.add_runtime_dependency "logstash-core", ">= 1.4.0", "< 2.0.0"
s.add_runtime_dependency "logstash-codec-plain"
s.add_development_dependency "logstash-devutils"
end