fluent-plugin-loggly-anno 0.0.1 → 0.0.2

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: babb9e88dd84a549aac49454c9353d3d79e9f5a8
4
- data.tar.gz: 8b9dcc3bb0b04eff3f31b1d1f27935ef80ffb256
3
+ metadata.gz: 73c7ef48b9797dd0749b0b6d07cb6c8cf0e4e61b
4
+ data.tar.gz: 96768b22283ea6fa8530decfca400da716969172
5
5
  SHA512:
6
- metadata.gz: 30b17dfce5a55a443940adbecf5c7a413388879f4d257596e1381b2a8c5e98c69c2f4328ca4c6e31e0a620846ab851598e32e9bb5dac268a5057f994e9df699d
7
- data.tar.gz: dff545814895749f8c17055c8b50d50296c7a2e681c0b386bc34052e27147ee5147ff9c0d3bcc7c00fecd4bf21414bb2f2741c156eb9f37457d318742221b45f
6
+ metadata.gz: 2d09e63a2b95de604d4094a84a3c3e43db80daa943879ac4ae915015c6d8962a45d0e192655e773f1bbb153d1e3656b9dd09ad390251c679172c421fe5b05d47
7
+ data.tar.gz: 83d12fc04ad22dfd963e38f01fefc73a7c0c595297ffd60ed9fe8289e805e90048f1cb7d1539c5a5e09e93ae9a8008081241abed6fc7f30059601d45d361e267
data/README.md CHANGED
@@ -40,10 +40,22 @@ The `xxx-xxxx...` is your Loggly access token.
40
40
 
41
41
  ## Annotations
42
42
 
43
- If you're running on Kubernetes you can redirect your logs, to a separate loggly url, by simply adding the following annotation to your namespace or pod:
43
+ If you're running on Kubernetes you can use annotations to redirect logs to alternate Loggly URLs.
44
+
45
+ Simply enable the [fluent-plugin-kubernetes_metadata_filter](https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter) gem in your Fluentd setup and configure it to match annotations on the namespace and pod:
46
+
47
+ ```
48
+ <filter kubernetes.**>
49
+ type kubernetes_metadata
50
+ include_namespace_metadata true
51
+ annotation_match ["solarwinds.io/*"]
52
+ </filter>
53
+ ```
54
+
55
+ Then add the following annotation to each namespace or pod that you'd like to redirect logs for:
44
56
 
45
57
  ```
46
58
  solarwinds.io/loggly_url: 'https://logs-01.loggly.com/inputs/xxx-xxxx-xxxx-xxxxx-xxxxxxxxxx'
47
59
  ```
48
60
 
49
- If both the Pod and Namespace have annotations for any running Pod, the Pod's annotation takes precedence.
61
+ If both a pod and the namespace it's in have this annotation, the pod's annotation takes precedence.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-loggly-anno"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.2"
7
7
  s.authors = ["Chris Rust"]
8
8
  s.email = ["chris.rust@solarwinds.com"]
9
9
  s.homepage = "https://github.com/cmrust/fluent-plugin-loggly"
@@ -33,17 +33,30 @@ class LogglyOutputBuffred < Fluent::BufferedOutput
33
33
 
34
34
  def configure(conf)
35
35
  super
36
- $log.debug "Loggly url #{@loggly_url}"
36
+ $log.debug "Configured loggly url: #{@loggly_url}"
37
37
  end
38
38
 
39
39
  def start
40
40
  super
41
41
  require 'net/http/persistent'
42
- @uri = URI @loggly_url
43
42
  @http = Net::HTTP::Persistent.new 'fluentd-plugin-loggly', :ENV
44
43
  @http.headers['Content-Type'] = 'text'
45
44
  end
46
45
 
46
+ def pick_uri(record)
47
+ # if kubernetes pod has loggly url as annotation, use it
48
+ if record.dig('kubernetes', 'annotations', 'solarwinds_io/loggly_url')
49
+ url = record['kubernetes']['annotations']['solarwinds_io/loggly_url']
50
+ # else if kubernetes namespace has papertrail destination as annotation, use it
51
+ elsif record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/loggly_url')
52
+ url = record['kubernetes']['namespace_annotations']['solarwinds_io/loggly_url']
53
+ # else use pre-configured destination
54
+ else
55
+ url = @loggly_url
56
+ end
57
+ URI url
58
+ end
59
+
47
60
  def shutdown
48
61
  super
49
62
  end
@@ -57,20 +70,24 @@ class LogglyOutputBuffred < Fluent::BufferedOutput
57
70
  end
58
71
 
59
72
  def write(chunk)
60
- records = []
61
73
  chunk.msgpack_each {|tag,time,record|
74
+ records = []
62
75
  record['timestamp'] ||= Time.at(time).iso8601(@time_precision_digits) if @output_include_time
63
76
  records.push(Yajl::Encoder.encode(record))
77
+ uri = pick_uri(record)
78
+ $log.debug "#{records.length} records sent"
79
+ post = Net::HTTP::Post.new uri.path
80
+ post.body = records.join("\n")
81
+ begin
82
+ response = @http.request uri, post
83
+ $log.debug "HTTP Response code #{response.code}"
84
+ if response.code != '200'
85
+ $log.error "Received HTTP #{response.code} from #{uri}: #{response.body}"
86
+ end
87
+ rescue => e
88
+ $log.error "Error posting to #{uri}: #{e}"
89
+ end
64
90
  }
65
- $log.debug "#{records.length} records sent"
66
- post = Net::HTTP::Post.new @uri.path
67
- post.body = records.join("\n")
68
- begin
69
- response = @http.request @uri, post
70
- $log.debug "HTTP Response code #{response.code}"
71
- $log.error response.body if response.code != "200"
72
- rescue
73
- $log.error "Error connecting to loggly verify the url #{@loggly_url}"
74
- end
91
+
75
92
  end
76
- end
93
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-loggly-anno
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Rust
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http-persistent