fluent-plugin-logmatic 0.9.0 → 0.9.1

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: 49374af53808bfdd30a59f976c71fb1e161ceecb
4
- data.tar.gz: 776691802f58b23f15ee374916b7e9b594796253
3
+ metadata.gz: 5a30e2c66cf206b595f59ba1be9bbd34a0c3ac26
4
+ data.tar.gz: 3a426bb92f291ade3dbbe01d669c7f68c97937a7
5
5
  SHA512:
6
- metadata.gz: 845f4a9a04e4ee16e8b3a2386cc452b990aa437c5be54eb9960ed8ea1a2384ac12770b09cd3caace07f31ac74da5c984bfc3b291821ac35dc5fb809a5945fcb8
7
- data.tar.gz: 7c177051f77ae73a8f4f58912763a69547cdbe362e7db1e2c43c3aedeafc67347e880454e9e68e7caed6d82f0b4dc192bc83961d72a587dfc737854ecf320984
6
+ metadata.gz: dbc9ec516620c079c5c00ad5948e398fa814d4982f15a8d43909d8e19d3af7cb32205ac6922ba4aa93ce6f3c61cb56114840f345590f7b1c89e1d5bb7ef9fd07
7
+ data.tar.gz: 30d38f4691524a4641f23ea69db610ce9a32ee6d4ce0260eed1a8cc00cddbd54e8ca4b724f347b4f4886a400ef5ed00840058b168a95e9cc96af49e1dd76bad1
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Fluentd output plugin for Logmatic.io.
2
- Link to the [Logmatic.io documentation](http://doc.logmatic.io/docs/using-fluentd)*
2
+ Link to the [Logmatic.io documentation](http://doc.logmatic.io/docs/using-fluentd)
3
3
 
4
4
 
5
5
  It mainly contains a proper JSON formatter and a socket handler that
@@ -17,6 +17,7 @@ To add the plugin to your fluentd agent, use the following command:
17
17
 
18
18
  To match events and send them to logmatic.io, simply add the following code to your configuration file.
19
19
 
20
+ TCP example
20
21
  ```xml
21
22
  # Match events tagged with "logmatic.**" and
22
23
  # send them to Logmatic.io
@@ -32,6 +33,23 @@ To match events and send them to logmatic.io, simply add the following code to y
32
33
 
33
34
  </match>
34
35
 
36
+ ```
37
+ HTTP example
38
+ ```xml
39
+ # Match events tagged with "logmatic.**" and
40
+ # send them to Logmatic.io
41
+ <match logmatic.**>
42
+
43
+ @type logmatic_http
44
+ @id awesome_agent
45
+ api_key <your_api_key>
46
+
47
+ # Optional
48
+ include_tag_key true
49
+ tag_key 'tag'
50
+
51
+ </match>
52
+
35
53
  ```
36
54
 
37
55
  After a restart of FluentD, any child events tagged with `logmatic` are shipped to your plateform.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-logmatic"
7
- spec.version = "0.9.0"
7
+ spec.version = "0.9.1"
8
8
  spec.authors = ["Logmatic support team"]
9
9
  spec.email = ["support@logmatic.io"]
10
10
  spec.summary = "Logmatic output plugin for Fluent event collector"
@@ -18,4 +18,5 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.5"
20
20
  spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "yajl-ruby", "~> 1.2"
21
22
  end
@@ -1,5 +1,6 @@
1
1
  require 'socket'
2
2
  require 'openssl'
3
+ require 'yajl'
3
4
 
4
5
  class Fluent::LogmaticOutput < Fluent::BufferedOutput
5
6
  class ConnectionFailure < StandardError; end
@@ -75,12 +76,13 @@ class Fluent::LogmaticOutput < Fluent::BufferedOutput
75
76
  messages = Array.new
76
77
  chunk.msgpack_each do |tag, record|
77
78
  next unless record.is_a? Hash
78
- next unless @use_json or record.has_key? "message"
79
+ next unless record.has_key? "message"
80
+
79
81
  if @include_tag_key
80
82
  record[@tag_key] = tag
81
83
  end
82
84
  if @use_json
83
- messages.push "#{api_key} " + record.to_json + "\n"
85
+ messages.push "#{api_key} " + Yajl.dump(record) + "\n"
84
86
  else
85
87
  messages.push "#{api_key} " + record["message"].rstrip() + "\n"
86
88
  end
@@ -1,3 +1,8 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'yajl'
5
+
1
6
  class Fluent::LogmaticOutput < Fluent::BufferedOutput
2
7
  class ConnectionFailure < StandardError;
3
8
  end
@@ -20,9 +25,6 @@ class Fluent::LogmaticOutput < Fluent::BufferedOutput
20
25
 
21
26
  def initialize
22
27
  super
23
- require 'net/http'
24
- require 'net/https'
25
- require 'uri'
26
28
  end
27
29
 
28
30
  def configure(conf)
@@ -56,45 +58,58 @@ class Fluent::LogmaticOutput < Fluent::BufferedOutput
56
58
 
57
59
  # Pack messages
58
60
  chunk.msgpack_each do |tag, record|
61
+
62
+ log.trace("New chunk received: #{record}, #{tag}")
59
63
  next unless record.is_a? Hash
60
- next unless @use_json or record.has_key? "message"
64
+ next unless record.has_key? "message"
65
+
61
66
 
62
67
  if @include_tag_key
63
68
  record[@tag_key] = tag
64
69
  end
65
- messages.push record.to_json
70
+
71
+ log.trace("Json message: #{Yajl.dump(record)}")
72
+ messages.push Yajl.dump(record)
66
73
  end
67
74
 
68
75
  # Send them
69
76
  log.trace("Sending #{messages.length} messages")
70
77
  retries = 0
71
- begin
78
+ force_retry = false
79
+
80
+ if (messages.length > 0)
72
81
 
73
- req = Net::HTTP::Post.new(@uri.path)
74
- req['Content-Type'] = 'application/json'
75
- req.body = data
76
- log.trace("Posting data")
77
- res = @https.request(messages.to_json)
78
- log.trace("Status code: #{res.code}")
82
+ log.trace("Full message body: #{Yajl.dump(messages)}")
83
+ begin
79
84
 
80
- if (res.code != 0 && res.code != 400)
81
- if retries < @max_retries || max_retries == -1
85
+ force_retry = false
86
+ req = Net::HTTP::Post.new(@uri.path)
87
+ req['Content-Type'] = 'application/json'
88
+ req.body = Yajl.dump(messages)
89
+ log.trace("Posting data")
90
+ res = @https.request(req)
91
+ log.trace("Status code: #{res.code}")
82
92
 
83
- a_couple_of_seconds = retries ** 2
84
- a_couple_of_seconds = 30 unless a_couple_of_seconds < 30
85
- retries += 1
86
- log.warn "Could not push logs to Logmatic, attempt=#{retries} max_attempts=#{max_retries} wait=#{a_couple_of_seconds}s error=#{res.code}"
93
+ if (res.code.to_i != 0 && res.code.to_i != 200)
94
+ if retries < @max_retries || max_retries == -1
87
95
 
88
- sleep a_couple_of_seconds
96
+ a_couple_of_seconds = retries ** 2
97
+ a_couple_of_seconds = 30 unless a_couple_of_seconds < 30
98
+ retries += 1
99
+ log.warn "Could not push logs to Logmatic, attempt=#{retries} max_attempts=#{max_retries} wait=#{a_couple_of_seconds}s error=#{res.code}"
89
100
 
90
- raise "Status code: #{res.code}"
101
+ sleep a_couple_of_seconds
102
+ force_retry = true
103
+ raise "Status code: #{res.code}"
91
104
 
105
+ end
92
106
  end
107
+ rescue => e
108
+ # Handle some failures
109
+ log.error("Error while sending data. Making a new attempt. Error: #{e}")
110
+ retry if force_retry
111
+ raise ConnectionFailure, "Could not push logs to Logmatic after #{retries} retries, #{e.message}"
93
112
  end
94
- rescue => e
95
- # Handle some failures
96
- retry
97
- raise ConnectionFailure, "Could not push logs to Logmatic after #{retries} retries, #{e.message}"
98
113
  end
99
114
  end
100
115
 
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-logmatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logmatic support team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-03 00:00:00.000000000 Z
11
+ date: 2017-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yajl-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
41
55
  description:
42
56
  email:
43
57
  - support@logmatic.io
@@ -45,7 +59,7 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
- - ".gitignore"
62
+ - .gitignore
49
63
  - Gemfile
50
64
  - LICENSE
51
65
  - README.md
@@ -63,17 +77,17 @@ require_paths:
63
77
  - lib
64
78
  required_ruby_version: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  required_rubygems_version: !ruby/object:Gem::Requirement
70
84
  requirements:
71
- - - ">="
85
+ - - '>='
72
86
  - !ruby/object:Gem::Version
73
87
  version: '0'
74
88
  requirements: []
75
89
  rubyforge_project:
76
- rubygems_version: 2.6.8
90
+ rubygems_version: 2.0.14.1
77
91
  signing_key:
78
92
  specification_version: 4
79
93
  summary: Logmatic output plugin for Fluent event collector