fluent-plugin-papertrail 0.1.3 → 0.1.4

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: 0c64afb4983305a88b12faeb066bedb5dd09c077
4
- data.tar.gz: dd5f6d86951f19f121609a5fab36aac1b6a30658
3
+ metadata.gz: c23981bf5baa13f2c2d8a8ec0dd586a37b5db034
4
+ data.tar.gz: 29a543b565b6a14d407f6daacced1b8a7ea2eb35
5
5
  SHA512:
6
- metadata.gz: 991a840b6840f26e3812b95908905ce16e9151b3d1c1c15d0ca81a10079f2967324ee78614ca830db6d14211d0b48bd16cb54e365cb2ad809bf0df352506c679
7
- data.tar.gz: '056480b9fb04bc1789745c5cc0481e21761e7e8651aad1b01946598dd6daa5194f73b3227349a5f70e98b061c145da14d2674f8d53abfde9965a9a060571a089'
6
+ metadata.gz: a91ac215ba2fcc071522845b42d4e5ec78566747a176d155605f8689195b5e2bdba809808337d7ba77b02a55000791333fba1ba4230ccd55885c6009c4e2df48
7
+ data.tar.gz: 1e421735baa691d46ba660717dc64d46f472983e0ca069203f29bfd18e6c3d6a7599885259308e1dfc516d68ad73c34c97d1ca26275ee51f0bd5007ca1941673
data/README.md CHANGED
@@ -83,9 +83,9 @@ If you want to change any of these parameters simply add them to a match stanza.
83
83
 
84
84
  ## Kubernetes
85
85
 
86
- This repo also includes Kubernetes and Docker assets which do all of the heavy lifting for you.
86
+ This repo includes a Kubernetes DaemonSet and accompanying Docker container which will stream all of your Kubernetes logs, containers and services, to Papertrail.
87
87
 
88
- If you'd like to deploy this plugin as a DaemonSet to your Kubernetes cluster, just adjust the `FLUENT_*` environment variables in `kubernetes/fluentd-daemonset-papertrail.yaml` and push it to your cluster with:
88
+ To deploy this plugin as a DaemonSet to your Kubernetes cluster, just adjust the `FLUENT_*` environment variables in `kubernetes/fluentd-daemonset-papertrail.yaml` and push it to your cluster with:
89
89
 
90
90
  ```
91
91
  kubectl apply -f kubernetes/fluentd-daemonset-papertrail.yaml
@@ -93,6 +93,19 @@ kubectl apply -f kubernetes/fluentd-daemonset-papertrail.yaml
93
93
 
94
94
  The Dockerfile that generates [the image used in this DaemonSet](https://quay.io/repository/solarwinds/fluentd-kubernetes), can be found at `docker/Dockerfile`.
95
95
 
96
+ ### Annotations
97
+
98
+ You can redirect logs to alternate Papertrail destinations by adding annotations to your Pods or Namespaces:
99
+
100
+ ```
101
+ solarwinds.io/papertrail_host: 'logs0.papertrailapp.com'
102
+ solarwinds.io/papertrail_port: '12345'
103
+ ```
104
+
105
+ If both the Pod and Namespace have annotations for any running Pod, the Pod's annotation is used.
106
+
107
+ ### Audit Logs
108
+
96
109
  If you'd like to redirect Kubernetes API Server Audit logs to a seperate Papertrail destination, add the following to your `fluent.conf`:
97
110
  ```
98
111
  <match kube-apiserver-audit>
@@ -104,6 +117,8 @@ If you'd like to redirect Kubernetes API Server Audit logs to a seperate Papertr
104
117
  </match>
105
118
  ```
106
119
 
120
+ This requires you to configure an [audit policy file](https://kubernetes.io/docs/tasks/debug-application-cluster/audit/) on your cluster.
121
+
107
122
  ## Development
108
123
 
109
124
  This plugin is targeting Ruby 2.4 and Fluentd v1.0, although it should work with older versions of both.
data/docker/Dockerfile CHANGED
@@ -13,7 +13,7 @@ RUN apt-get update \
13
13
  RUN echo 'gem: --no-document' >> /etc/gemrc \
14
14
  && gem install fluent-plugin-systemd -v 0.3.1 \
15
15
  && gem install fluent-plugin-rewrite-tag-filter -v 1.6.0 \
16
- && gem install fluent-plugin-papertrail -v 0.1.3 \
16
+ && gem install fluent-plugin-papertrail -v 0.1.4 \
17
17
  && gem install fluent-plugin-kubernetes_metadata_filter
18
18
 
19
19
  RUN SUDO_FORCE_REMOVE=yes \
@@ -140,6 +140,8 @@
140
140
 
141
141
  <filter kubernetes.**>
142
142
  type kubernetes_metadata
143
+ include_namespace_metadata true
144
+ annotation_match ["solarwinds.io/papertrail_*"]
143
145
  </filter>
144
146
 
145
147
  <filter kube-apiserver-audit>
@@ -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-papertrail"
7
- spec.version = "0.1.3"
7
+ spec.version = "0.1.4"
8
8
  spec.authors = ["Jonathan Lozinski", "Alex Ouzounis", "Chris Rust"]
9
9
  spec.email = ["jonathan.lozinski@solarwinds.com", "alex.ouzounis@solarwinds.com", "chris.rust@solarwinds.com"]
10
10
 
@@ -22,7 +22,7 @@ spec:
22
22
  effect: NoSchedule
23
23
  containers:
24
24
  - name: fluentd
25
- image: quay.io/solarwinds/fluentd-kubernetes:v1.1.1-debian-papertrail
25
+ image: quay.io/solarwinds/fluentd-kubernetes:v1.1.1-debian-papertrail-0.1.4
26
26
  imagePullPolicy: Always
27
27
  env:
28
28
  - name: FLUENT_PAPERTRAIL_HOST
@@ -3,7 +3,7 @@ require 'syslog_protocol'
3
3
  module Fluent
4
4
  class Papertrail < Fluent::BufferedOutput
5
5
  class SocketFailureError < StandardError; end
6
- attr_accessor :socket
6
+ attr_accessor :sockets
7
7
 
8
8
  # if left empty in fluent config these config_param's will error
9
9
  config_param :papertrail_host, :string
@@ -13,13 +13,16 @@ module Fluent
13
13
  # overriding default flush_interval (60 sec) from Fluent::BufferedOutput
14
14
  config_param :flush_interval, :time, default: 1
15
15
 
16
-
17
16
  # register as 'papertrail' fluent plugin
18
17
  Fluent::Plugin.register_output('papertrail', self)
19
18
 
20
19
  def configure(conf)
21
20
  super
22
- @socket = create_socket(@papertrail_host, @papertrail_port)
21
+ # create initial sockets hash and socket based on config param
22
+ @sockets = {}
23
+ socket_key = "#{@papertrail_host}:#{@papertrail_port}"
24
+ @sockets[socket_key] = create_socket(@papertrail_host, @papertrail_port)
25
+ # redefine default hostname if it's been passed in through ENV
23
26
  @default_hostname = ENV['FLUENT_HOSTNAME'] || @default_hostname
24
27
  end
25
28
 
@@ -29,8 +32,9 @@ module Fluent
29
32
 
30
33
  def write(chunk)
31
34
  chunk.msgpack_each {|(tag, time, record)|
35
+ socket_key = pick_socket(record)
32
36
  packet = create_packet(tag, time, record)
33
- send_to_papertrail(packet)
37
+ send_to_papertrail(packet, socket_key)
34
38
  }
35
39
  end
36
40
 
@@ -51,7 +55,7 @@ module Fluent
51
55
  ssl
52
56
  end
53
57
 
54
- def create_packet(tag,time,record)
58
+ def create_packet(tag, time, record)
55
59
  # construct syslog packet from fluent record
56
60
  packet = SyslogProtocol::Packet.new
57
61
  packet.hostname = record['hostname'] || @default_hostname
@@ -63,25 +67,42 @@ module Fluent
63
67
  packet
64
68
  end
65
69
 
66
- def send_to_papertrail(packet)
67
- # recreate the socket if it's nil -- see below
68
- @socket ||= create_socket(@papertrail_host, @papertrail_port)
69
-
70
- papertrail_addr = "#{@papertrail_host}:#{@papertrail_port}"
70
+ def pick_socket(record)
71
+ # if kubernetes pod has papertrail destination as annotation, use it
72
+ if record.dig('kubernetes', 'annotations', 'solarwinds_io/papertrail_host') && \
73
+ record.dig('kubernetes', 'annotations', 'solarwinds_io/papertrail_port')
74
+ host = record['kubernetes']['annotations']['solarwinds_io/papertrail_host']
75
+ port = record['kubernetes']['annotations']['solarwinds_io/papertrail_port']
76
+ # else if kubernetes namespace has papertrail destination as annotation, use it
77
+ elsif record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/papertrail_host') && \
78
+ record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/papertrail_port')
79
+ host = record['kubernetes']['namespace_annotations']['solarwinds_io/papertrail_host']
80
+ port = record['kubernetes']['namespace_annotations']['solarwinds_io/papertrail_port']
81
+ # else use pre-configured destination
82
+ else
83
+ host = @papertrail_host
84
+ port = @papertrail_port
85
+ end
86
+ socket_key = "#{host}:#{port}"
87
+ # recreate the socket if it's nil
88
+ @sockets[socket_key] ||= create_socket(host, port)
89
+ socket_key
90
+ end
71
91
 
72
- if @socket.nil?
73
- err_msg = "Unable to create socket with #{papertrail_addr}"
92
+ def send_to_papertrail(packet, socket_key)
93
+ if @sockets[socket_key].nil?
94
+ err_msg = "Unable to create socket with #{socket_key}"
74
95
  log.error err_msg
75
96
  raise SocketFailureError, err_msg
76
97
  else
77
98
  begin
78
99
  # send it
79
- @socket.puts packet.assemble
100
+ @sockets[socket_key].puts packet.assemble
80
101
  rescue => e
81
- err_msg = "Error writing to #{papertrail_addr}: #{e}"
102
+ err_msg = "Error writing to #{socket_key}: #{e}"
82
103
  log.error err_msg
83
104
  # socket failed, reset to nil to recreate for the next write
84
- @socket = nil
105
+ @sockets[socket_key] = nil
85
106
  raise SocketFailureError, err_msg, e.backtrace
86
107
  end
87
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-papertrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Lozinski
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-03-13 00:00:00.000000000 Z
13
+ date: 2018-03-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.6.14
163
+ rubygems_version: 2.5.2.2
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: Remote Syslog Output Fluentd plugin for papertrail