fluent-plugin-vmware-loginsight 0.1.0 → 0.1.6

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
- SHA1:
3
- metadata.gz: 7677f5c4289ba3ecb32f9aa6ddc35c6b8f70f4b6
4
- data.tar.gz: 73023509bb66d43595176f3625256009e4187cac
2
+ SHA256:
3
+ metadata.gz: c51be49fa1014357b97a164dd1d7f560a3370abdee80aa461323864a08799c00
4
+ data.tar.gz: c6de42ca3daa2d432a95ead1a9534ce61a09379ecd24bca06a87dbaaa56b98cd
5
5
  SHA512:
6
- metadata.gz: d3662938668a3307722b0ac604186cfc7a1b397c18d16968cd669360fd2a5c148c4d7904547d9a7258abda2818cbce2a8ee1505206259120e9efb0955f109bcb
7
- data.tar.gz: 12c29d1640c720f3b380475d3fd2f9e368817d3b5e794ad14960120c0ba6d70ab789764b64737eb28dcbdafed382af331a700499b0f18400b3d93f1f50ae4ec3
6
+ metadata.gz: eaa154fcc5d89035c02f6544b5badb1258cb3af4bef6642aa54cba61791af656b98ea53bdf84ec299fd8b198e6a6ef479fbfb7ea737e0a37a477a71d818fc795
7
+ data.tar.gz: dc3c4176ffb0dc4765bbaa3bba6dc1cf94528daac797d8c8b6dae878585434faf96074bcd24390ad249424867fc499b3fc83360e71124f1607aa1f94c11e60b7
data/CONTRIBUTING.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  # Contributing to fluent-plugin-vmware-loginsight
4
4
 
5
- The fluent-plugin-vmware-loginsight project team welcomes contributions from the community. If you wish to contribute code and you have not
6
- signed our contributor license agreement (CLA), our bot will update the issue when you open a Pull Request. For any
7
- questions about the CLA process, please refer to our [FAQ](https://cla.vmware.com/faq).
5
+ The fluent-plugin-vmware-loginsight project team welcomes contributions from the community. Before you start working with fluent-plugin-vmware-loginsight, please read our [Developer Certificate of Origin](https://cla.vmware.com/dco). All contributions to this repository must be signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on as an open-source patch.
8
6
 
9
7
  ## Community
10
8
 
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+ source "https://rubygems.org"
12
+
13
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Fluentd plugin for VMware Log Insight
2
+
3
+ Copyright 2018 VMware, Inc. All rights reserved
4
+
5
+ The MIT license (the ìLicenseî) set forth below applies to all parts of the Fluentd plugin for VMware Log Insight project. You may not use this file except in compliance with the License.†
6
+
7
+ MIT License
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+
data/README.md CHANGED
@@ -25,26 +25,121 @@ And then execute:
25
25
  $ bundle
26
26
  ```
27
27
 
28
- ## Configuration
29
-
30
- You can generate configuration template:
28
+ ## Usage
31
29
 
32
30
  ```
33
- $ fluent-plugin-config-format output vmware-loginsight
31
+ <source>
32
+ @type tail
33
+ path /var/log/containers/*.log
34
+ pos_file /var/log/fluentd-docker.pos
35
+ time_format %Y-%m-%dT%H:%M:%S
36
+ tag kubernetes.*
37
+ format json
38
+ read_from_head true
39
+ </source>
40
+
41
+ # Kubernetes metadata filter that tags additional meta data for each event
42
+ <filter kubernetes.var.log.containers.**.log>
43
+ @type kubernetes_metadata
44
+ </filter>
45
+
46
+ <match **>
47
+ @type vmware_loginsight
48
+ scheme https
49
+ ssl_verify true
50
+ # Loginsight host: One may use IP address or cname
51
+ # host X.X.X.X
52
+ host my-loginsight.mycompany.com
53
+ port 9000
54
+ path api/v1/events/ingest
55
+ agent_id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
56
+ http_method post
57
+ serializer json
58
+ rate_limit_msec 0
59
+ raise_on_error false
60
+ include_tag_key true
61
+ tag_key tag
62
+ </match>
63
+ ```
64
+ ### Configuration options
65
+
34
66
  ```
67
+ scheme, :string, :default => 'http' :: Valid Values: http/https
68
+
69
+ # Loginsight Host ex. localhost
70
+ host, :string, :default => 'localhost' :: Valid Values: loginsight_url | loginsight_ip
71
+
72
+ # Loginsight port ex. 9000
73
+ port, :integer, :default => 80
74
+
75
+ # Loginsight ingestion api path ex. 'api/v1/events/ingest'
76
+ path, :string, :default => 'api/v1/events/ingest'
77
+
78
+ # agent_id generated by your LI
79
+ agent_id, :string, :default => '0'
80
+
81
+ # Credentials if used
82
+ username, :string, :default => nil
83
+ password, :string, :default => nil,
84
+
85
+ # Authentication
86
+ authentication, :string, :default => nil :: Valid Value: nil | basic
87
+
88
+ # SSL verification flag
89
+ ssl_verify, :bool, :default => true :: Valid Value: true | false
90
+ # CA Cert filep
91
+ ca_file, :string, :default => nil
92
+
93
+ # HTTP method
94
+ http_method, :string, :default => :post :: Valid Value: post
95
+
96
+ # Serialization
97
+ serializer, :string, :default => :json :: Valid Value: json
35
98
 
36
- You can copy and paste generated documents here.
99
+ # Number of retries
100
+ request_retries, :integer, :default => 3
101
+ # http connection ttl for each request
102
+ request_timeout, :time, :default => 5
37
103
 
38
- ## Documentation
104
+ # If set, enables debug logs for http connection
105
+ http_conn_debug, :bool, :default => false :: Valid Value: true | false
39
106
 
40
- ## Releases & Major Branches
107
+ # Simple rate limiting: ignore any records within `rate_limit_msec` since the last one
108
+ rate_limit_msec, :integer, :default => 0
109
+
110
+ # Raise errors that were rescued during HTTP requests?
111
+ raise_on_error, :bool, :default => false :: Valid Value: true | false
112
+
113
+ # Include tag key as log event?
114
+ include_tag_key, :bool, :default => true :: Valid Value: true | false
115
+
116
+ # Metadata key that identifies Fluentd tags
117
+ tag_key, :string, :default => 'tag'
118
+
119
+ # Keys from log event whose values should be added as log message/text to loginsight.
120
+ # These key/value pairs won't expanded/flattened and won't be added as metadata/fields.
121
+ log_text_keys, :array, :default => ["log", "message", "msg"] :: Valid Value: Array of strings
122
+
123
+ # Flatten hashes to create one key/val pair w/o losing log data
124
+ flatten_hashes, :bool, :default => true :: Valid Value: true | false
125
+
126
+ # Seperator to use for joining flattened keys
127
+ flatten_hashes_separator, :string, :default => "_"
128
+ ```
129
+
130
+ For more examples look at [examples](./examples/)
41
131
 
42
132
  ## Contributing
43
133
 
44
- The fluent-plugin-vmware-loginsight project team welcomes contributions from the community. If you wish to contribute code and you have not
45
- signed our contributor license agreement (CLA), our bot will update the issue when you open a Pull Request. For any
46
- questions about the CLA process, please refer to our [FAQ](https://cla.vmware.com/faq). For more detailed information,
47
- refer to [CONTRIBUTING.md](CONTRIBUTING.md).
134
+ The fluent-plugin-vmware-loginsight project team welcomes contributions from the community. Before you start working with fluent-plugin-vmware-loginsight, please read our [Developer Certificate of Origin](https://cla.vmware.com/dco). All contributions to this repository must be signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on as an open-source patch. For more detailed information, refer to [CONTRIBUTING.md](CONTRIBUTING.md).
48
135
 
49
136
  ## License
137
+ Fluentd plugin for VMware Log Insight
138
+
139
+ Copyright 2018 VMware, Inc. All Rights Reserved.
140
+
141
+ This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
142
+
143
+ This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
50
144
 
145
+ SPDX-License-Identifier: MIT
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+
12
+ require "bundler"
13
+ Bundler::GemHelper.install_tasks
14
+
15
+ require "rake/testtask"
16
+
17
+ Rake::TestTask.new(:test) do |t|
18
+ t.libs.push("lib", "test")
19
+ t.test_files = FileList["test/**/test_*.rb"]
20
+ t.verbose = true
21
+ t.warning = true
22
+ end
23
+
24
+ task default: [:test]
@@ -0,0 +1,108 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+
12
+ <system>
13
+ log_level info
14
+ </system>
15
+
16
+ # Prevent fluentd from handling records containing its own logs to handle cycles.
17
+ <match fluent.**>
18
+ @type null
19
+ </match>
20
+
21
+ <source>
22
+ @type systemd
23
+ path /run/log/journal
24
+ # Can filter logs if we want, e.g.
25
+ #filters [{ "_SYSTEMD_UNIT": "kubelet.service" }]
26
+ <storage>
27
+ @type local
28
+ persistent true
29
+ path /var/log/fluentd-systemdlog.pos
30
+ </storage>
31
+ tag systemdlog
32
+ read_from_head true
33
+ strip_underscores true
34
+ </source>
35
+
36
+ <source>
37
+ @type tail
38
+ path /var/log/containers/*.log
39
+ # One could exclude certain logs like:
40
+ # exclude_path ["/var/log/containers/log-collector*.log"]
41
+ pos_file /var/log/fluentd-docker.pos
42
+ time_format %Y-%m-%dT%H:%M:%S
43
+ tag kubernetes.*
44
+ format json
45
+ read_from_head true
46
+ </source>
47
+
48
+
49
+ # Sample rule for services that generate java like stack trace
50
+ #<source>
51
+ # @type tail
52
+ # path /var/log/containers/javaapp**.log
53
+ # pos_file /var/log/fluentd-dockerlog.pos
54
+ # time_format %b %d %H:%M:%S
55
+ # tag kubernetes.*
56
+ # format multiline
57
+ # format_firstline /\d{4}-\d{1,2}-\d{1,2}/
58
+ # format1 /^(?<time>\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}) \[(?<thread>.*)\] (?<level>[^\s]+)(?<message>.*)/
59
+ # read_from_head true
60
+ #</source>
61
+
62
+ # Kubernetes metadata filter that tags additional meta data for each event
63
+ <filter kubernetes.var.log.containers.**.log>
64
+ @type kubernetes_metadata
65
+ </filter>
66
+
67
+ # If we want to transform events we could use:
68
+ #<filter **>
69
+ # @type record_transformer
70
+ # enable_ruby
71
+ # auto_typecast
72
+ # <record>
73
+ # hostname "#{Socket.gethostname}"
74
+ # mykey ${["message"=>record.to_json]}
75
+ # </record>
76
+ #</filter>
77
+
78
+ <match fluent.**>
79
+ @type null
80
+ </match>
81
+
82
+ <match **>
83
+ @type copy
84
+ <store>
85
+ @type vmware_loginsight
86
+ scheme https
87
+ ssl_verify true
88
+ # Loginsight host: One may use IP address or cname
89
+ # host X.X.X.X
90
+ host my-loginsight.mycompany.com
91
+ port 9000
92
+ path api/v1/events/ingest
93
+ agent_id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
94
+ http_method post
95
+ serializer json
96
+ rate_limit_msec 0
97
+ raise_on_error false
98
+ log_text_keys ["log","msg","message"]
99
+ include_tag_key true
100
+ tag_key tag
101
+ </store>
102
+ # copy plugin supports sending/copying logs to multiple plugins
103
+ # One may choose to send them to multiple LIs
104
+ # Or one may want send a copy to stdout for debugging
105
+ # <store>
106
+ # @type stdout
107
+ # </store>
108
+ </match>
@@ -0,0 +1,36 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018-2019 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+ # Builds a debian-based image that contains fluentd, fluent-plugin-vmware-loginsight, fluent-plugin-kubernetes_metadata_filter
12
+ # and fluent-plugin-systemd.
13
+ #
14
+ # The image is preconfigured with the fluent.conf from the examples dir. For more details see
15
+ # https://github.com/vmware/fluent-plugin-vmware-loginsight/blob/master/examples/fluent.conf
16
+ FROM fluent/fluentd:v0.14.15-debian-onbuild
17
+ # Above image expects the loginsight plugin vmware_loginsight to be available under ./plugins/vmware_loginsight.rb
18
+ # and fluentd config under ./fluent.conf by default
19
+
20
+ USER root
21
+
22
+ RUN buildDeps="sudo make gcc g++ libc-dev ruby-dev libffi-dev" \
23
+ && apt-get update \
24
+ && apt-get install -y --no-install-recommends $buildDeps \
25
+ && sudo gem install \
26
+ fluent-plugin-systemd \
27
+ fluent-plugin-kubernetes_metadata_filter \
28
+ fluent-plugin-vmware-loginsight \
29
+ && sudo gem sources --clear-all \
30
+ && SUDO_FORCE_REMOVE=yes \
31
+ apt-get purge -y --auto-remove \
32
+ -o APT::AutoRemove::RecommendsImportant=false \
33
+ $buildDeps \
34
+ && rm -rf /var/lib/apt/lists/* \
35
+ /home/fluent/.gem/ruby/2.3.0/cache/*.gem \
36
+ /home/root/.gem/ruby/2.3.0/cache/*.gem
@@ -0,0 +1,45 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2019 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+ # Builds a photon-based image that contains fluentd, fluent-plugin-vmware-loginsight some of the tools recommended by fluent
12
+ # (libjemalloc, oj, assync-http). This image is based on the minimalistic VMware Photon OS so the result is smaller in size.
13
+ # Furthermore, all of the needed components are installed from the trusted Photon repository by using the tdnf package manager.
14
+ #
15
+ # Fluentd is configured with the default configuration that gets produced by the `fluentd --setup` command. For an example of
16
+ # a configuration that uses the fluent-plugin-vmware-loginsight plugin check fluent.conf under the examples dir:
17
+ # https://github.com/vmware/fluent-plugin-vmware-loginsight/blob/master/examples/fluent.conf
18
+
19
+ FROM photon:3.0-20190705
20
+
21
+ USER root
22
+
23
+ # Distro sync and install components
24
+ RUN tdnf distro-sync --refresh -y \
25
+ && tdnf install -y \
26
+ rubygem-fluentd-1.6.3 \
27
+ #
28
+ # optional but used by fluentd
29
+ rubygem-oj-3.3.10 \
30
+ rubygem-async-http-0.48.2 \
31
+ jemalloc-4.5.0 \
32
+ #
33
+ # Install Log Insight plugin
34
+ rubygem-fluent-plugin-vmware-loginsight-0.1.5
35
+
36
+ RUN ln -s /usr/lib/ruby/gems/2.5.0/bin/fluentd /usr/bin/fluentd \
37
+ && fluentd --setup
38
+
39
+ # Make sure fluentd picks jemalloc
40
+ ENV LD_PRELOAD="/usr/lib/libjemalloc.so.2"
41
+
42
+ # Standard fluentd ports
43
+ EXPOSE 24224 5140
44
+
45
+ ENTRYPOINT ["/usr/bin/fluentd"]
@@ -0,0 +1,68 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2019 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+ # Builds a photon-based image that contains fluentd, fluent-plugin-vmware-loginsight some of the tools recommended by fluent
12
+ # (libjemalloc, oj, assync-http). This image is based on the minimalistic VMware Photon OS so the result is smaller in size.
13
+ #
14
+ # Fluentd is configured with the default configuration that gets produced by the `fluentd --setup` command. For an example of
15
+ # a configuration that uses the fluent-plugin-vmware-loginsight plugin check fluent.conf under the examples dir:
16
+ # https://github.com/vmware/fluent-plugin-vmware-loginsight/blob/master/examples/fluent.conf
17
+ FROM photon:3.0-20190705
18
+
19
+ USER root
20
+
21
+ RUN buildDeps="\
22
+ binutils linux-api-headers glibc-devel \
23
+ make gcc gmp-devel libffi-devel \
24
+ tar bzip2 sed gawk" \
25
+ #
26
+ # Distro sync and install build dependencies
27
+ && tdnf distro-sync --refresh -y \
28
+ # Toybox conflicts with bzip2. The latter is needed to unpack libjemalloc
29
+ && tdnf remove -y toybox \
30
+ && tdnf install -y $buildDeps ruby \
31
+ #
32
+ # These are not required but are used if available
33
+ && gem install oj -v 3.3.10 \
34
+ && gem install json -v 2.2.0 \
35
+ && gem install async-http -v 0.46.3 \
36
+ #
37
+ # Install fluentd
38
+ && gem install --norc --no-document fluentd -v 1.6.3 \
39
+ && mkdir -p /fluentd/etc /fluentd/plugins \
40
+ #
41
+ # Install Log Insight plugin
42
+ && gem install --norc --no-document -v 0.1.5 fluent-plugin-vmware-loginsight \
43
+ #
44
+ # Install jemalloc 4.5.0
45
+ && curl -L --output /tmp/jemalloc-4.5.0.tar.bz2 https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2 \
46
+ && tar -C /tmp/ -xjvf /tmp/jemalloc-4.5.0.tar.bz2 \
47
+ && cd /tmp/jemalloc-4.5.0 \
48
+ && ./configure && make \
49
+ && mv lib/libjemalloc.so.2 /usr/lib \
50
+ && cd / \
51
+ #
52
+ # Cleanup to reduce image size
53
+ && rm -rf /tmp/jemalloc-4.5.0* \
54
+ && tdnf remove -y $buildDeps \
55
+ && tdnf clean all \
56
+ && gem sources --clear-all \
57
+ && gem cleanup
58
+
59
+ # Create default fluent.conf
60
+ RUN fluentd --setup
61
+
62
+ # Make sure fluentd picks jemalloc
63
+ ENV LD_PRELOAD="/usr/lib/libjemalloc.so.2"
64
+
65
+ # Standard fluentd ports
66
+ EXPOSE 24224 5140
67
+
68
+ ENTRYPOINT ["/usr/bin/fluentd"]
@@ -0,0 +1,174 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+
12
+ ---
13
+ apiVersion: v1
14
+ kind: ConfigMap
15
+ metadata:
16
+ name: fluentd-config
17
+ namespace: kube-system
18
+ data:
19
+ fluent.conf: |
20
+ # We can use this config to load some default config or load user defined config
21
+ @include myapp-fluent.conf
22
+
23
+ myapp-fluent.conf: |
24
+ # Input sources
25
+ @include general.conf
26
+ @include systemd-input.conf
27
+ @include kubernetes-input.conf
28
+
29
+ # Parsing/Filtering
30
+ @include kubernetes-filter.conf
31
+
32
+ # Forwading - Be vigilant of the order in which these plugins are specified. Order matters!
33
+ @include myapp-loginsight-output.conf
34
+
35
+ general.conf: |
36
+ <system>
37
+ log_level info
38
+ </system>
39
+ # Prevent fluentd from handling records containing its own logs to handle cycles.
40
+ <match fluent.**>
41
+ @type null
42
+ </match>
43
+
44
+ systemd-input.conf: |
45
+ <source>
46
+ @type systemd
47
+ path /run/log/journal
48
+ # Can filter logs if we want, e.g.
49
+ # filters [{ "_SYSTEMD_UNIT": "kubelet.service" }]
50
+ <storage>
51
+ @type local
52
+ persistent true
53
+ path /var/log/fluentd-systemdlog.pos
54
+ </storage>
55
+ tag systemdlog
56
+ read_from_head true
57
+ strip_underscores true
58
+ </source>
59
+
60
+ kubernetes-input.conf: |
61
+ <source>
62
+ @type tail
63
+ path /var/log/containers/*.log
64
+ # One could exclude certain logs like:
65
+ # exclude_path ["/var/log/containers/log-collector*.log"]
66
+ pos_file /var/log/fluentd-docker.pos
67
+ time_format %Y-%m-%dT%H:%M:%S
68
+ tag kubernetes.*
69
+ format json
70
+ read_from_head true
71
+ </source>
72
+
73
+ kubernetes-filter.conf: |
74
+ <filter kubernetes.**>
75
+ @type kubernetes_metadata
76
+ merge_json_log true
77
+ preserve_json_log true
78
+ </filter>
79
+
80
+ myapp-loginsight-output.conf: |
81
+ # We are capturing all log messages and redirecting them to endpoints mentioned in each <store> tag.
82
+ # One may redirect these logs to muliple endpoints (including multiple LI instances).
83
+ # Or one may chose to tag their specific logs and add their own config to capture those tagged logs and redirect
84
+ # them to appropriate endpoint. This specific config needs to preceed this generic one.
85
+ <match **>
86
+ @type copy
87
+ <store>
88
+ @type vmware_loginsight
89
+ scheme https
90
+ ssl_verify true
91
+ # Loginsight host: One may use IP address or cname
92
+ # host X.X.X.X
93
+ host my-loginsight.mycompany.com
94
+ port 9000
95
+ path api/v1/events/ingest
96
+ agent_id XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
97
+ http_method post
98
+ serializer json
99
+ rate_limit_msec 0
100
+ raise_on_error false
101
+ include_tag_key true
102
+ tag_key tag
103
+ </store>
104
+ # If we want to debug and send logs to stdout as well
105
+ # <store>
106
+ # @type stdout
107
+ # </store>
108
+ </match>
109
+
110
+
111
+ extra.conf: |
112
+ # If we want to transform events we could use:
113
+ #<filter **>
114
+ # @type record_transformer
115
+ # enable_ruby
116
+ # auto_typecast
117
+ # <record>
118
+ # hostname "#{Socket.gethostname}"
119
+ # mykey ${["message"=>record.to_json]}
120
+ # </record>
121
+ #</filter>
122
+
123
+
124
+ ---
125
+ kind: DaemonSet
126
+ apiVersion: extensions/v1beta1
127
+ metadata:
128
+ name: "log-collector"
129
+ namespace: "kube-system"
130
+ labels:
131
+ app: "log-collector"
132
+ version: v1
133
+ spec:
134
+ template:
135
+ metadata:
136
+ labels:
137
+ app: "log-collector"
138
+ version: v1
139
+ spec:
140
+ containers:
141
+ - name: "log-collector"
142
+ image: "my-container-hub.com/log-collector:1.0.0"
143
+ command: ["fluentd", "-c", "/fluentd/etc/fluent.conf", "-p", "/fluentd/plugins"]
144
+ resources:
145
+ requests:
146
+ memory: "512Mi"
147
+ cpu: "500m"
148
+ limits:
149
+ memory: "512Mi"
150
+ cpu: "500m"
151
+ volumeMounts:
152
+ - name: varlog
153
+ mountPath: /var/log
154
+ - name: varlibdockercontainers
155
+ mountPath: /var/lib/docker/containers
156
+ readOnly: true
157
+ - name: runlogjournal
158
+ mountPath: /run/log/journal
159
+ - name: fluentdconfig
160
+ mountPath: /fluentd/etc
161
+ terminationGracePeriodSeconds: 30
162
+ volumes:
163
+ - name: varlog
164
+ hostPath:
165
+ path: /var/log
166
+ - name: varlibdockercontainers
167
+ hostPath:
168
+ path: /var/lib/docker/containers
169
+ - name: runlogjournal
170
+ hostPath:
171
+ path: /run/log/journal
172
+ - name: fluentdconfig
173
+ configMap:
174
+ name: "fluentd-config"
@@ -0,0 +1,38 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+
12
+ lib = File.expand_path("../lib", __FILE__)
13
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
14
+
15
+ Gem::Specification.new do |spec|
16
+ spec.name = "fluent-plugin-vmware-loginsight"
17
+ spec.version = "0.1.6"
18
+ spec.authors = ["Vishal Mohite", "Chris Todd"]
19
+ spec.email = ["vmohite@vmware.com", "toddc@vmware.com"]
20
+
21
+ spec.summary = %q{Fluend output plugin to forward logs to VMware Log Insight}
22
+ spec.description = spec.summary
23
+ spec.homepage = "https://github.com/vmware/fluent-plugin-vmware-loginsight"
24
+ spec.license = "MIT"
25
+
26
+ test_files, files = `git ls-files -z`.split("\x0").partition do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.files = files
30
+ spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
31
+ spec.test_files = test_files
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.14"
35
+ spec.add_development_dependency "rake", "~> 12.0"
36
+ spec.add_development_dependency "test-unit", "~> 3.0"
37
+ spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
38
+ end
@@ -0,0 +1,321 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+
12
+ require "fluent/plugin/output"
13
+ require 'json'
14
+ require 'net/http'
15
+ require 'uri'
16
+
17
+ module Fluent
18
+ module Plugin
19
+ class Fluent::VmwareLoginsightOutput < Fluent::Output
20
+ class ConnectionFailure < StandardError; end
21
+
22
+ Fluent::Plugin.register_output('vmware_loginsight', self)
23
+
24
+ ### Connection Params ###
25
+ config_param :scheme, :string, :default => 'http'
26
+ # Loginsight Host ex. localhost
27
+ config_param :host, :string, :default => 'localhost'
28
+ # In case we want to post to multiple hosts. This is futuristic, Fluentd copy plugin can support this as is
29
+ #config_param :hosts, :string, :default => nil
30
+ # Loginsight port ex. 9000. Default 80
31
+ config_param :port, :integer, :default => 80
32
+ # Loginsight ingestion api path ex. 'api/v1/events/ingest'
33
+ config_param :path, :string, :default => 'api/v1/events/ingest'
34
+ # agent_id generated by your LI
35
+ config_param :agent_id, :string, :default => '0'
36
+ # Credentials if used
37
+ config_param :username, :string, :default => nil
38
+ config_param :password, :string, :default => nil, :secret => true
39
+ # Authentication nil | 'basic'
40
+ config_param :authentication, :string, :default => nil
41
+
42
+ # Set Net::HTTP.verify_mode to `OpenSSL::SSL::VERIFY_NONE`
43
+ config_param :ssl_verify, :bool, :default => true
44
+ config_param :ca_file, :string, :default => nil
45
+
46
+ ### API Params ###
47
+ # HTTP method
48
+ # post | put
49
+ config_param :http_method, :string, :default => :post
50
+ # form | json
51
+ config_param :serializer, :string, :default => :json
52
+ config_param :request_retries, :integer, :default => 3
53
+ config_param :request_timeout, :time, :default => 5
54
+ config_param :http_conn_debug, :bool, :default => false
55
+ config_param :max_batch_size, :integer, :default => 512000
56
+
57
+ # Simple rate limiting: ignore any records within `rate_limit_msec`
58
+ # since the last one.
59
+ config_param :rate_limit_msec, :integer, :default => 0
60
+ # Raise errors that were rescued during HTTP requests?
61
+ config_param :raise_on_error, :bool, :default => false
62
+ ### Additional Params
63
+ config_param :include_tag_key, :bool, :default => true
64
+ # Metadata key that identifies Fluentd tags
65
+ config_param :tag_key, :string, :default => 'tag'
66
+ # Keys from log event whose values should be added as log message/text
67
+ # to loginsight. Note these key/value pairs won't be added as metadata/fields
68
+ config_param :log_text_keys, :array, default: ["log", "message", "msg"], value_type: :string
69
+ # Flatten hashes to create one key/val pair w/o losing log data
70
+ config_param :flatten_hashes, :bool, :default => true
71
+ # Seperator to use for joining flattened keys
72
+ config_param :flatten_hashes_separator, :string, :default => "_"
73
+
74
+
75
+ def initialize
76
+ super
77
+ end
78
+
79
+ def configure(conf)
80
+ super
81
+
82
+ @ssl_verify_mode = @ssl_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
83
+ @auth = case @authentication
84
+ when 'basic'
85
+ :basic
86
+ else
87
+ :none
88
+ end
89
+
90
+ @last_request_time = nil
91
+ end
92
+
93
+ def start
94
+ super
95
+ end
96
+
97
+ def shutdown
98
+ super
99
+ end
100
+
101
+ def format_url()
102
+ url = "#{@scheme}://#{host}:#{port}/#{path}/#{agent_id}"
103
+ url
104
+ end
105
+
106
+ def set_header(req)
107
+ if @serializer == 'json'
108
+ set_json_header(req)
109
+ end
110
+ req
111
+ end
112
+
113
+ def set_json_header(req)
114
+ req['Content-Type'] = 'application/json'
115
+ req
116
+ end
117
+
118
+ def shorten_key(key)
119
+ # LI doesn't allow some characters in field 'name'
120
+ # like '/', '-', '\', '.', etc. so replace them with @flatten_hashes_separator
121
+ key = key.gsub(/[\/\.\-\\]/,@flatten_hashes_separator).downcase
122
+ # shorten field names
123
+ key = key.gsub(/kubernetes_/,'k8s_')
124
+ key = key.gsub(/namespace/,'ns')
125
+ key = key.gsub(/labels_/,'')
126
+ key = key.gsub(/_name/,'')
127
+ key = key.gsub(/_hash/,'')
128
+ key = key.gsub(/container_/,'')
129
+ key
130
+ end
131
+
132
+ def create_loginsight_event(tag, time, record)
133
+ flattened_records = {}
134
+ if @flatten_hashes
135
+ flattened_records = flatten_record(record, [])
136
+ else
137
+ flattened_records = record
138
+ end
139
+ # tag can be immutable in some cases, use a copy.
140
+ flattened_records[@tag_key] = tag.dup if @include_tag_key
141
+ fields = []
142
+ keys = []
143
+ log = ''
144
+ flattened_records.each do |key, value|
145
+ begin
146
+ next if value.nil?
147
+ # LI doesn't support duplicate fields, make unique names by appending underscore
148
+ key = shorten_key(key)
149
+ while keys.include?(key)
150
+ key = key + '_'
151
+ end
152
+ keys.push(key)
153
+ key.force_encoding("utf-8")
154
+ # convert value to json string if its a hash and to string if not already a string
155
+ begin
156
+ value = value.to_json if value.is_a?(Hash)
157
+ value = value.to_s
158
+ value = value.frozen? ? value.dup : value # if value is immutable, use a copy.
159
+ value.force_encoding("utf-8")
160
+ rescue Exception=>e
161
+ $log.warn "force_encoding exception: " "#{e.class}, '#{e.message}', " \
162
+ "\n Request: #{key} #{record.to_json[1..1024]}"
163
+ value = "Exception during conversion: #{e.message}"
164
+ end
165
+ end
166
+ if @log_text_keys.include?(key)
167
+ if log != "#{value}"
168
+ if log.empty?
169
+ log = "#{value}"
170
+ else
171
+ log += " #{value}"
172
+ end
173
+ end
174
+ else
175
+ # If there is time information available, update time for LI. LI ignores
176
+ # time if it is out of the error/adjusment window of 10 mins. in such
177
+ # cases we would still like to preserve time info, so add it as event.
178
+ # TODO Ignore the below block for now. Handle the case for time being in
179
+ # different formats than milliseconds
180
+ #if ['time', '_source_realtime_timestamp'].include?(key)
181
+ # time = value
182
+ #end
183
+ fields << {"name" => key, "content" => value}
184
+ end
185
+ end
186
+ event = {
187
+ "fields" => fields,
188
+ "text" => log.gsub(/^$\n/, ''),
189
+ "timestamp" => time * 1000
190
+ }
191
+ event
192
+ end
193
+
194
+ def flatten_record(record, prefix=[])
195
+ ret = {}
196
+
197
+ case record
198
+ when Hash
199
+ record.each do |key, value|
200
+ if @log_text_keys.include?(key)
201
+ ret.merge!({key.to_s => value})
202
+ else
203
+ ret.merge! flatten_record(value, prefix + [key.to_s])
204
+ end
205
+ end
206
+ when Array
207
+ record.each do |value|
208
+ ret.merge! flatten_record(value, prefix)
209
+ end
210
+ else
211
+ return {prefix.join(@flatten_hashes_separator) => record}
212
+ end
213
+ ret
214
+ end
215
+
216
+ def create_request(tag, time, record)
217
+ url = format_url()
218
+ uri = URI.parse(url)
219
+ req = Net::HTTP.const_get(@http_method.to_s.capitalize).new(uri.path)
220
+ set_body(req, tag, time, record)
221
+ set_header(req)
222
+ return req, uri
223
+ end
224
+
225
+
226
+ def send_request(req, uri)
227
+ is_rate_limited = (@rate_limit_msec != 0 and not @last_request_time.nil?)
228
+ if is_rate_limited and ((Time.now.to_f - @last_request_time) * 1000.0 < @rate_limit_msec)
229
+ $log.info('Dropped request due to rate limiting')
230
+ return
231
+ end
232
+
233
+ if @auth and @auth == 'basic'
234
+ req.basic_auth(@username, @password)
235
+ end
236
+ begin
237
+ retries ||= 2
238
+ response = nil
239
+ @last_request_time = Time.now.to_f
240
+
241
+ http_conn = Net::HTTP.new(uri.host, uri.port)
242
+ # For debugging, set this
243
+ http_conn.set_debug_output($stdout) if @http_conn_debug
244
+ http_conn.use_ssl = (uri.scheme == 'https')
245
+ if http_conn.use_ssl?
246
+ http_conn.ca_file = @ca_file
247
+ end
248
+ http_conn.verify_mode = @ssl_verify_mode
249
+
250
+ response = http_conn.start do |http|
251
+ http.read_timeout = @request_timeout
252
+ http.request(req)
253
+ end
254
+ rescue => e # rescue all StandardErrors
255
+ # server didn't respond
256
+ # Be careful while turning on below log, if LI instance can't be reached and you're sending
257
+ # log-container logs to LI as well, you may end up in a cycle.
258
+ # TODO handle the cyclic case at plugin level if possible.
259
+ # $log.warn "Net::HTTP.#{req.method.capitalize} raises exception: " \
260
+ # "#{e.class}, '#{e.message}', \n Request: #{req.body[1..1024]}"
261
+ retry unless (retries -= 1).zero?
262
+ raise e if @raise_on_error
263
+ else
264
+ unless response and response.is_a?(Net::HTTPSuccess)
265
+ res_summary = if response
266
+ "Response Code: #{response.code}\n"\
267
+ "Response Message: #{response.message}\n" \
268
+ "Response Body: #{response.body}"
269
+ else
270
+ "Response = nil"
271
+ end
272
+ # ditto cyclic warning
273
+ # $log.warn "Failed to #{req.method} #{uri}\n(#{res_summary})\n" \
274
+ # "Request Size: #{req.body.size} Request Body: #{req.body[1..1024]}"
275
+ end #end unless
276
+ end # end begin
277
+ end # end send_request
278
+
279
+ def send_events(uri, events)
280
+ req = Net::HTTP.const_get(@http_method.to_s.capitalize).new(uri.path)
281
+ event_req = {
282
+ "events" => events
283
+ }
284
+ req.body = event_req.to_json
285
+ set_header(req)
286
+ send_request(req, uri)
287
+ end
288
+
289
+ def handle_records(tag, es)
290
+ url = format_url()
291
+ uri = URI.parse(url)
292
+ events = []
293
+ count = 0
294
+ es.each do |time, record|
295
+ new_event = create_loginsight_event(tag, time, record)
296
+ new_event_size = new_event.to_json.size
297
+ if new_event_size > @max_batch_size
298
+ $log.warn "dropping event larger than max_batch_size: #{new_event.to_json[1..1024]}"
299
+ else
300
+ if (count + new_event_size) > @max_batch_size
301
+ send_events(uri, events)
302
+ events = []
303
+ count = 0
304
+ end
305
+ count += new_event_size
306
+ events << new_event
307
+ end
308
+ end
309
+ if count > 0
310
+ send_events(uri, events)
311
+ end
312
+ end
313
+
314
+ def emit(tag, es, chain)
315
+ handle_records(tag, es)
316
+ chain.next
317
+ end
318
+ end
319
+ end
320
+ end
321
+
data/test/helper.rb ADDED
@@ -0,0 +1,19 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+
12
+ $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
13
+ require "test-unit"
14
+ require "fluent/test"
15
+ require "fluent/test/driver/output"
16
+ require "fluent/test/helpers"
17
+
18
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
19
+ Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -0,0 +1,30 @@
1
+ # Fluentd plugin for VMware Log Insight
2
+ #
3
+ # Copyright 2018 VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.
6
+ #
7
+ # This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
8
+ #
9
+ # SPDX-License-Identifier: MIT
10
+
11
+ # TODO Need to add tests.
12
+
13
+ require "helper"
14
+ require "fluent/plugin/out_vmware_loginsight.rb"
15
+
16
+ class VmwareLoginsightOutputTest < Test::Unit::TestCase
17
+ setup do
18
+ Fluent::Test.setup
19
+ end
20
+
21
+ test "failure" do
22
+ flunk
23
+ end
24
+
25
+ private
26
+
27
+ def create_driver(conf)
28
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::VmwareLoginsightOutput).configure(conf)
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-vmware-loginsight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vishal Mohite
8
+ - Chris Todd
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2018-08-13 00:00:00.000000000 Z
12
+ date: 2019-09-13 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -75,13 +76,26 @@ dependencies:
75
76
  description: Fluend output plugin to forward logs to VMware Log Insight
76
77
  email:
77
78
  - vmohite@vmware.com
79
+ - toddc@vmware.com
78
80
  executables: []
79
81
  extensions: []
80
82
  extra_rdoc_files: []
81
83
  files:
82
84
  - ".gitignore"
83
85
  - CONTRIBUTING.md
86
+ - Gemfile
87
+ - LICENSE
84
88
  - README.md
89
+ - Rakefile
90
+ - examples/fluent.conf
91
+ - examples/fluentd-vrli-plugin-debian.dockerfile
92
+ - examples/fluentd-vrli-plugin-photon-tdnf.dockerfile
93
+ - examples/fluentd-vrli-plugin-photon.dockerfile
94
+ - examples/k8s-log-collector-ds.yaml
95
+ - fluent-plugin-vmware-loginsight.gemspec
96
+ - lib/fluent/plugin/out_vmware_loginsight.rb
97
+ - test/helper.rb
98
+ - test/plugin/test_out_vmware_loginsight.rb
85
99
  homepage: https://github.com/vmware/fluent-plugin-vmware-loginsight
86
100
  licenses:
87
101
  - MIT
@@ -102,8 +116,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
116
  version: '0'
103
117
  requirements: []
104
118
  rubyforge_project:
105
- rubygems_version: 2.5.2.3
119
+ rubygems_version: 2.7.7
106
120
  signing_key:
107
121
  specification_version: 4
108
122
  summary: Fluend output plugin to forward logs to VMware Log Insight
109
- test_files: []
123
+ test_files:
124
+ - test/helper.rb
125
+ - test/plugin/test_out_vmware_loginsight.rb