logstash-output-logentries 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3071f23479728c44aebb9426d301150f352f183
4
- data.tar.gz: 57fea8cda18e056dbfad29cecfbbbf99d230710a
3
+ metadata.gz: 435b907a2cf1a2a84b6c7144cde39dfc80834f89
4
+ data.tar.gz: 789d602830227fa6c89678e9606961f68b0fc8ed
5
5
  SHA512:
6
- metadata.gz: 498b97cffe5f047666707a1a44c4e7d35483e509465dfda8684d0114a99bd510277167de3748342816388abe6203ad7f2b2b80e9b01551005ee7896bf7efea7d
7
- data.tar.gz: 4f1e3bafb4ef7979a5c6bb5997825fecc6f9d9182b8e5c6e5f393a60419076d49f582f5f840daf8508678fc29eecb62a912d1778c2ccb4d5ac16830339b7dd3a
6
+ metadata.gz: 7f5836961c3ea81444f43f058a65cd05e995fc44b50c5d63168f8e0821a2a0b9f8268d60028435842c854056e47dfd7c73427f4350fd65fda83793d90d95c1c7
7
+ data.tar.gz: 49281deaf12cbaa0ac5402819081cdd58cbc93c394ab39dbd08a676136a8a1fa8395f878c45d65dbb580037a94e9f22ed8cfd6bb6c71f5139cfa63fa5bf167ea
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
2
+ gemspec
3
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
4
+
data/README.md CHANGED
@@ -5,13 +5,21 @@ This is a plugin for [Logentries](https://www.logentries.com) and Logstash.
5
5
  # Send logs using token
6
6
  You can forward logs from Logstash to Logentries using unique token. To do this you have to configure the output sectin of your .conf file in your logstash main folder.
7
7
 
8
- output {
8
+ ```
9
+ output{
9
10
  logentries{
10
11
  token => "LOGENTRIES_TOKEN"
11
- }
12
- }
12
+ reconnect_interval => 10
13
+ ssl_enable => true
14
+ host => "data.logentries.com"
15
+ port => 443
16
+ }
17
+ }
18
+ ```
13
19
 
14
- Please refer to this [blog](link here) for more information and instruction on how to set up your .config file.
20
+ Only `token => "LOGENTRIES_TOKEN"` is a required variable, the rest are optional. If you set `ssl_enable` to `false`, you must set the port to `80` or `514`
21
+
22
+ Please refer to Logstash documentation for more information and instruction on how to set up your .config file.
15
23
 
16
24
  # Logentries Token
17
25
 
@@ -1,74 +1,88 @@
1
+ # encoding: utf-8
1
2
  require "logstash/outputs/base"
2
3
  require "logstash/namespace"
3
- require "uri"
4
- require "net/http"
5
- require "net/https"
6
-
4
+ require "logstash/codecs/plain"
5
+ require "socket"
7
6
 
7
+ # www.logentries.com
8
+ #
9
+ # Write events over TCP socket. Each event json is separated by a newline.
10
+ #
11
+ # You will read this token from your config file. Just put the following lines to your .config file:
12
+ #
13
+ # output{
14
+ # logentries{
15
+ # token => "LOGENTRIES_TOKEN"
16
+ # reconnect_interval => 10
17
+ # ssl_enable => true
18
+ # host => "data.logentries.com"
19
+ # port => 443
20
+ # }
21
+ # }
8
22
 
9
23
  class LogStash::Outputs::Logentries < LogStash::Outputs::Base
10
- config_name "logentries"
11
- milestone 2
12
-
13
- # www.logentries.com
14
- #
15
- # You will read this token from your config file. Just put the following lines to your .config file:
16
- #
17
- # output {
18
- # logentries{
19
- # token => "LOGENTRIES_TOKEN"
20
- # }
21
- # }
22
-
23
- config :token, :validate => :string, :required => true
24
-
25
- public
26
- def register
24
+ config_name "logentries"
25
+
26
+ config :token, :validate => :string, :required => true
27
+
28
+ config :reconnect_interval, :validate => :number, :default => 10
29
+ config :ssl_enable, :validate => :boolean, :default => true
30
+
31
+ config :host, :validate => :string, :default => "data.logentries.com"
32
+ config :port, :validate => :number, :default => 443
33
+
34
+ def register
35
+ @client_socket = nil
36
+
37
+ if ssl?
38
+ @ssl_context = setup_ssl
39
+ end
40
+ end
41
+
42
+ def receive(event)
43
+ message = event.to_json
44
+
45
+ begin
46
+ @client_socket ||= connect
47
+ @client_socket.puts("#{@token}" + message)
48
+ rescue => e
49
+ @logger.warn("Socket output exception: closing and resending event", :host => @host, :port => @port, :exception => e, :backtrace => e.backtrace, :event => event)
50
+ @client_socket.close rescue nil
51
+ @client_socket = nil
52
+ sleep(@reconnect_interval)
53
+ retry
27
54
  end
28
-
29
- def receive(event)
30
- return unless output?(event)
31
-
32
- if event == LogStash::SHUTDOWN
33
- finished
34
- return
35
- end
36
-
37
- # Send the event using token
38
- url = URI.parse("https://js.logentries.com/v1/logs/#{event.sprintf(@token)}")
39
-
40
- # Debug the URL here
41
- @logger.info("Sending using #{event.sprintf(@token)} Logentries Token")
42
-
43
- # Open HTTP connection
44
- http = Net::HTTP.new(url.host, url.port)
45
-
46
- # Use secure SSL
47
- if url.scheme == 'https'
48
- http.use_ssl = true
49
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
- end
51
-
52
- request = Net::HTTP::Post.new(url.path)
53
-
54
- #Prepend the message body with "event" to allow the js.logentries to pick it up
55
- request.body = "{\"event\":" + event.to_json + "}"
56
- begin
57
- response = http.request(request)
58
- if response.is_a?(Net::HTTPSuccess)
59
- @logger.info("Event Sent!")
60
- else
61
- @logger.warn("HTTP error", :error => response.error!)
62
- end
63
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
64
- @logger.warn("Error", e)
65
- end
66
-
67
- if response.is_a?(Net::HTTPSuccess)
68
- @logger.info("Event Sent!")
69
- else
70
- @logger.warn("HTTP error", :error => response.error!)
71
- end
72
-
73
- end # receive
55
+ end
56
+
57
+ private
58
+
59
+ def ssl?
60
+ @ssl_enable == true
61
+ end
62
+
63
+ def connect
64
+ socket = nil
65
+ socket = TCPSocket.new(@host, @port)
66
+ if ssl?
67
+ socket = OpenSSL::SSL::SSLSocket.new(socket, @ssl_context)
68
+ begin
69
+ socket.connect
70
+ rescue OpenSSL::SSL::SSLError => ssle
71
+ @logger.error("SSL Error", :exception => ssle, :backtrace => ssle.backtrace)
72
+ sleep(5)
73
+ raise
74
+ end
75
+ end
76
+ socket
77
+ end
78
+
79
+ def setup_ssl
80
+ require "openssl"
81
+ cert_store = OpenSSL::X509::Store.new
82
+ cert_store.set_default_paths
83
+ ssl_context = OpenSSL::SSL::SSLContext.new()
84
+ ssl_context.cert_store = cert_store
85
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
86
+ ssl_context
87
+ end
74
88
  end #LogStash::Outputs::Logentries
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-logentries'
4
- s.version = '0.1.2'
4
+ s.version = '1.0.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "You can forward logs from Logstash to Logentries using unique token."
7
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"
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
21
21
 
22
22
  # Gem dependencies
23
- s.add_runtime_dependency "logstash-core"
24
23
 
25
24
  s.add_development_dependency 'logstash-devutils'
26
25
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-logentries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logentries - Bart Siniarski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: logstash-core
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: logstash-devutils
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
64
  version: '0'
79
65
  requirements: []
80
66
  rubyforge_project:
81
- rubygems_version: 2.4.6
67
+ rubygems_version: 2.5.1
82
68
  signing_key:
83
69
  specification_version: 4
84
70
  summary: You can forward logs from Logstash to Logentries using unique token.