logstash-output-logmatic 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f4c336a1aa8c1c96d35e9dfb0527bb3be5bbb1a
4
- data.tar.gz: 6c7963ab72043cda85de06d3ea34d8b2fa22b44d
3
+ metadata.gz: a61c28d9d73583df0f16c50fd0f02429e35270e9
4
+ data.tar.gz: b5d6bc8647be4c4b25eabb6ce073d6a5b6c7559b
5
5
  SHA512:
6
- metadata.gz: 388b0d88dfd686fc2c1f98887f863e31cb5e52831f5c45962f8e3db043abbd38ee660da1e0f963392a659336f203fea39defb62a88ab8cbb0098d6313b8c56e9
7
- data.tar.gz: b0168749fd2c202341e3c313da94da9e73420c4e55bef81a3d6d7375dc1ea64c603d39d6b9b09eab575fc69cdaaacfd253b8984ffc6b9fa5fa36c518ded7aa83
6
+ metadata.gz: a6d1ddd1a910ff2cd32e4e77c65bb80b9e83e3e60fed3d625683acb31f7160344a5bce52e6a9e2eb427e53359283d12f39f33ae2b226d41876c7c43b14a2a0ba
7
+ data.tar.gz: 3c0ec9702a3f2a0819564d1a13d33169e0403bf65e99f23006f5879a11d61ca825e9a576613648713e5a88243d1bee96c2f96adfa63c87777c8e019209b72080
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logstash Logmatic.io's Output Plugin
2
2
 
3
- TThis project is an output plugin to send logs to Logmatic.io from Logstash >v1.5.0.
3
+ This project is an output plugin to send logs to Logmatic.io from Logstash >v1.5.0.
4
4
 
5
5
  ## How to install it?
6
6
 
@@ -27,12 +27,6 @@ Then you just need to configure the output as follow:
27
27
  output {
28
28
  logmatic {
29
29
  key => "<your_api_key>"
30
- # In order to limit the amount of resources the output uses buffering
31
- # You can configure its behavior with:
32
- # The number of elements queued before flushing
33
- # queue_size => 10
34
- # The timeframe in seconds for buffering before flushing
35
- # timeframe => 10
36
30
  }
37
31
  }
38
32
 
@@ -1,65 +1,150 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/outputs/base"
3
3
  require "logstash/namespace"
4
- require "stud/buffer"
4
+ require "thread"
5
5
 
6
- # Ship log from logstash straight to Logmatic
6
+ # Write events over a TCP socket.
7
7
  #
8
- # To use this you will need a valid Logmatic API Key
9
- class LogStash::Outputs::LogmaticBatch < LogStash::Outputs::Base
10
- include Stud::Buffer
8
+ # Each event json is separated by a newline.
9
+ #
10
+ # Can either accept connections from clients or connect to a server,
11
+ # depending on `mode`.
12
+ class LogStash::Outputs::LogmaticTcp < LogStash::Outputs::Base
11
13
 
12
14
  config_name "logmatic"
13
- milestone 2
14
15
 
15
16
  default :codec, "json"
16
17
 
18
+ # When mode is `server`, the address to listen on.
19
+ # When mode is `client`, the address to connect to.
20
+ config :host, :validate => :string, :default => "api.logmatic.io"
21
+
22
+ # When mode is `server`, the port to listen on.
23
+ # When mode is `client`, the port to connect to.
24
+ config :port, :validate => :number, :default => 10514
25
+
17
26
  # The Logmatic api key
18
27
  # You can find it in the 'Account' section in the Logmatic interface.
19
28
  config :key, :validate => :string, :required => true
20
29
 
21
- # How many events to queue before flushing to Logmatic
22
- # prior to schedule set in @timeframe
23
- config :queue_size, :validate => :number, :default => 10
30
+ # When connect failed,retry interval in sec.
31
+ config :reconnect_interval, :validate => :number, :default => 10
24
32
 
25
- # How often (in seconds) to flush queued events to Logmatic
26
- config :timeframe, :validate => :number, :default => 10
33
+ # Mode to operate in. `server` listens for client connections,
34
+ # `client` connects to a server.
35
+ config :mode, :validate => ["server", "client"], :default => "client"
36
+
37
+ # The format to use when writing events to the file. This value
38
+ # supports any string and can include `%{name}` and other dynamic
39
+ # strings.
40
+ #
41
+ # If this setting is omitted, the full json representation of the
42
+ # event will be written as a single line.
43
+ config :message_format, :validate => :string, :deprecated => true
44
+
45
+ class Client
46
+ public
47
+ def initialize(socket, logger)
48
+ @socket = socket
49
+ @logger = logger
50
+ @queue = Queue.new
51
+ end
52
+
53
+ public
54
+ def run
55
+ loop do
56
+ begin
57
+ @socket.write(@queue.pop)
58
+ rescue => e
59
+ @logger.warn("tcp output exception", :socket => @socket,
60
+ :exception => e)
61
+ break
62
+ end
63
+ end
64
+ end # def run
65
+
66
+ public
67
+ def write(msg)
68
+ @queue.push(msg)
69
+ end # def write
70
+ end # class Client
27
71
 
28
72
  public
29
73
  def register
30
- require "net/https"
31
- require "uri"
32
- @url = "https://api.logmatic.io/v1/input/#{@key}"
33
- @uri = URI.parse(@url)
34
- @client = Net::HTTP.new(@uri.host, @uri.port)
35
- @client.use_ssl = true
36
- @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
- @logger.debug("Logmatic URL", :url => @url)
38
-
39
- buffer_initialize(
40
- :max_items => @queue_size,
41
- :max_interval => @timeframe,
42
- :logger => @logger
43
- )
44
- end
74
+ require "socket"
75
+ require "stud/try"
76
+ if server?
77
+ workers_not_supported
45
78
 
46
- public
47
- def receive(event)
48
- return unless output?(event)
49
- buffer_receive(event.to_json)
50
- end
79
+ @logger.info("Starting tcp output listener", :address => "#{@host}:#{@port}")
80
+ @server_socket = TCPServer.new(@host, @port)
81
+ @client_threads = []
51
82
 
52
- public
53
- def flush(events, final=false)
54
- # Send the event over http.
55
- request = Net::HTTP::Post.new(@uri.path)
56
- request.body = events.inspect
57
- request.add_field("Content-Type", 'application/json')
58
- response = @client.request(request)
59
- if response.is_a?(Net::HTTPSuccess)
60
- @logger.debug("Event sent to Logmatic OK!")
83
+ @accept_thread = Thread.new(@server_socket) do |server_socket|
84
+ loop do
85
+ client_thread = Thread.start(server_socket.accept) do |client_socket|
86
+ client = Client.new(client_socket, @logger)
87
+ Thread.current[:client] = client
88
+ client.run
89
+ end
90
+ @client_threads << client_thread
91
+ end
92
+ end
93
+
94
+ @codec.on_event do |event, payload|
95
+ @client_threads.each do |client_thread|
96
+ client_thread[:client].write(payload)
97
+ end
98
+ @client_threads.reject! {|t| !t.alive? }
99
+ end
61
100
  else
62
- @logger.warn("HTTP error", :error => response.error!)
101
+ client_socket = nil
102
+ @codec.on_event do |event, payload|
103
+ begin
104
+ client_socket = connect unless client_socket
105
+ r,w,e = IO.select([client_socket], [client_socket], [client_socket], nil)
106
+ # don't expect any reads, but a readable socket might
107
+ # mean the remote end closed, so read it and throw it away.
108
+ # we'll get an EOFError if it happens.
109
+ client_socket.sysread(16384) if r.any?
110
+
111
+ # Now send the payload
112
+ @logger.debug(@key);
113
+ client_socket.syswrite(@key + " " + payload+"\n") if w.any?
114
+ rescue => e
115
+ @logger.warn("tcp output exception", :host => @host, :port => @port,
116
+ :exception => e, :backtrace => e.backtrace)
117
+ client_socket.close rescue nil
118
+ client_socket = nil
119
+ sleep @reconnect_interval
120
+ retry
121
+ end
122
+ end
123
+ end
124
+ end # def register
125
+
126
+ private
127
+ def connect
128
+ Stud::try do
129
+ return TCPSocket.new(@host, @port)
63
130
  end
131
+ end # def connect
132
+
133
+ private
134
+ def server?
135
+ @mode == "server"
136
+ end # def server?
137
+
138
+ public
139
+ def receive(event)
140
+
141
+
142
+ #if @message_format
143
+ #output = event.sprintf(@message_format) + "\n"
144
+ #else
145
+ #output = event.to_hash.to_json + "\n"
146
+ #end
147
+
148
+ @codec.encode(event)
64
149
  end # def receive
65
- end # class LogStash::Outputs::LogmaticBatch
150
+ end # class LogStash::Outputs::Tcp
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require "stud/buffer"
5
+
6
+ # Ship log from logstash straight to Logmatic
7
+ #
8
+ # To use this you will need a valid Logmatic API Key
9
+ class LogStash::Outputs::LogmaticHttpBatch < LogStash::Outputs::Base
10
+ include Stud::Buffer
11
+
12
+ config_name "logmatic_http"
13
+ milestone 2
14
+
15
+ default :codec, "json"
16
+
17
+ # The Logmatic api key
18
+ # You can find it in the 'Account' section in the Logmatic interface.
19
+ config :key, :validate => :string, :required => true
20
+
21
+ # How many events to queue before flushing to Logmatic
22
+ # prior to schedule set in @timeframe
23
+ config :queue_size, :validate => :number, :default => 10
24
+
25
+ # How often (in seconds) to flush queued events to Logmatic
26
+ config :timeframe, :validate => :number, :default => 10
27
+
28
+ public
29
+ def register
30
+ require "net/https"
31
+ require "uri"
32
+ @url = "https://api.logmatic.io/v1/input/#{@key}"
33
+ @uri = URI.parse(@url)
34
+ @client = Net::HTTP.new(@uri.host, @uri.port)
35
+ @client.use_ssl = true
36
+ @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
+ @logger.debug("Logmatic URL", :url => @url)
38
+
39
+ buffer_initialize(
40
+ :max_items => @queue_size,
41
+ :max_interval => @timeframe,
42
+ :logger => @logger
43
+ )
44
+ end
45
+
46
+ public
47
+ def receive(event)
48
+ return unless output?(event)
49
+ buffer_receive(event.to_json)
50
+ end
51
+
52
+ public
53
+ def flush(events, final=false)
54
+ # Send the event over http.
55
+ request = Net::HTTP::Post.new(@uri.path)
56
+ request.body = events.inspect
57
+ request.add_field("Content-Type", 'application/json')
58
+ response = @client.request(request)
59
+ if response.is_a?(Net::HTTPSuccess)
60
+ @logger.debug("Event sent to Logmatic OK!")
61
+ else
62
+ @logger.warn("HTTP error", :error => response.error!)
63
+ end
64
+ end # def receive
65
+ end # class LogStash::Outputs::LogmaticBatch
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-logmatic'
3
- s.version = "0.1.1"
3
+ s.version = "0.1.2"
4
4
  s.licenses = ["GNU 2.0"]
5
5
  s.summary = "Logmatic Output"
6
6
  s.description = "Logmatic output for Logstash"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-logmatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni CLEMENT
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-07 00:00:00.000000000 Z
12
+ date: 2015-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -67,6 +67,7 @@ files:
67
67
  - NOTICE.TXT
68
68
  - README.md
69
69
  - lib/logstash/outputs/logmatic.rb
70
+ - lib/logstash/outputs/logmatic_https.rb
70
71
  - logstash-output-logmatic.gemspec
71
72
  - spec/outputs/logmatic.rb
72
73
  homepage: ''