fluent-plugin-loggly-anno 0.0.1 → 0.0.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 +4 -4
- data/README.md +14 -2
- data/fluent-plugin-loggly.gemspec +1 -1
- data/lib/fluent/plugin/out_loggly_buffered.rb +31 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73c7ef48b9797dd0749b0b6d07cb6c8cf0e4e61b
|
4
|
+
data.tar.gz: 96768b22283ea6fa8530decfca400da716969172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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.
|
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 "
|
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
|
-
|
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.
|
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-
|
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
|