fluent-plugin-mageshlogs 0.1.3 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +51 -0
- data/LICENSE +202 -0
- data/README.md +43 -0
- data/Rakefile +13 -0
- data/fluent-plugin-mageshlogs.gemspec +37 -0
- data/lib/fluent/plugin/2 +0 -0
- data/lib/fluent/plugin/3 +0 -0
- data/lib/fluent/plugin/e +0 -0
- data/lib/fluent/plugin/nil +0 -0
- data/lib/fluent/plugin/out_mageshlogs.rb +353 -0
- data/test/helper.rb +8 -0
- data/test/plugin/test_out_mageshlogs.rb +18 -0
- metadata +67 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e1ccf593a6773573f2d03f10bd7927f73c537f4f3f6e7450843680acf07f3b3
|
4
|
+
data.tar.gz: 6d796f72c9cf59b18fa76a3f93a2b481f806f4b7dddf13b23e8e4d7be076d18b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b9afb3099a91664bb995c49ee25e3f24ff1a34920559fc9ba9eef4bce6aba6be46563f6d847669eeb631c90ad6e6a8ebca3e51105669c49121f0a10e3283a9b
|
7
|
+
data.tar.gz: 2cb975f206aa8ce23b6c8cdce35b57e278df0474df876d8dddd5fef94e407b2e1d1298f20048c3dd458e57f90611da8e69c220049689223bff6e131737c1cabc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-mageshlogs (0.1.0)
|
5
|
+
fluentd (>= 0.14.10, < 2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
concurrent-ruby (1.1.9)
|
11
|
+
cool.io (1.7.1)
|
12
|
+
fluentd (1.13.3)
|
13
|
+
bundler
|
14
|
+
cool.io (>= 1.4.5, < 2.0.0)
|
15
|
+
http_parser.rb (>= 0.5.1, < 0.8.0)
|
16
|
+
msgpack (>= 1.3.1, < 2.0.0)
|
17
|
+
serverengine (>= 2.2.2, < 3.0.0)
|
18
|
+
sigdump (~> 0.2.2)
|
19
|
+
strptime (>= 0.2.2, < 1.0.0)
|
20
|
+
tzinfo (>= 1.0, < 3.0)
|
21
|
+
tzinfo-data (~> 1.0)
|
22
|
+
webrick (>= 1.4.2, < 1.8.0)
|
23
|
+
yajl-ruby (~> 1.0)
|
24
|
+
http_parser.rb (0.7.0)
|
25
|
+
msgpack (1.4.2)
|
26
|
+
power_assert (1.2.0)
|
27
|
+
rake (13.0.3)
|
28
|
+
serverengine (2.2.4)
|
29
|
+
sigdump (~> 0.2.2)
|
30
|
+
sigdump (0.2.4)
|
31
|
+
strptime (0.2.5)
|
32
|
+
test-unit (3.3.7)
|
33
|
+
power_assert
|
34
|
+
tzinfo (2.0.4)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
tzinfo-data (1.2021.1)
|
37
|
+
tzinfo (>= 1.0.0)
|
38
|
+
webrick (1.7.0)
|
39
|
+
yajl-ruby (1.4.1)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
x86_64-linux
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (~> 2.2.24)
|
46
|
+
fluent-plugin-mageshlogs!
|
47
|
+
rake (~> 13.0.3)
|
48
|
+
test-unit (~> 3.3.7)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.2.24
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# fluent-plugin-mageshlogs
|
2
|
+
|
3
|
+
[Fluentd](https://fluentd.org/) output plugin to do something.
|
4
|
+
|
5
|
+
TODO: write description for you plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
### RubyGems
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install fluent-plugin-mageshlogs
|
13
|
+
```
|
14
|
+
|
15
|
+
### Bundler
|
16
|
+
|
17
|
+
Add following line to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem "fluent-plugin-mageshlogs"
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```
|
26
|
+
$ bundle
|
27
|
+
```
|
28
|
+
|
29
|
+
## Configuration
|
30
|
+
|
31
|
+
You can generate configuration template:
|
32
|
+
|
33
|
+
```
|
34
|
+
$ fluent-plugin-config-format output mageshlogs
|
35
|
+
```
|
36
|
+
|
37
|
+
You can copy and paste generated documents here.
|
38
|
+
|
39
|
+
## Copyright
|
40
|
+
|
41
|
+
* Copyright(c) 2021- magesh-1870
|
42
|
+
* License
|
43
|
+
* Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs.push("lib", "test")
|
8
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
9
|
+
t.verbose = true
|
10
|
+
t.warning = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: [:test]
|
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "fluent-plugin-mageshlogs"
|
6
|
+
spec.version = "0.1.7"
|
7
|
+
spec.authors = ["Magesh Rajan"]
|
8
|
+
spec.email = ["mageshrajan0007@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = %q{Magesh output plugin for Fluent event collector}
|
11
|
+
spec.homepage = "https://www.site24x7.com/log-management.html"
|
12
|
+
spec.license = ""
|
13
|
+
|
14
|
+
test_files, files = `git ls-files -z`.split("\x0").partition do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.files = files
|
18
|
+
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = test_files
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
#spec.add_development_dependency "bundler", "~> 2.2.24"
|
23
|
+
#spec.add_development_dependency "rake", "~> 13.0.3"
|
24
|
+
#spec.add_development_dependency "test-unit", "~> 3.3.7"
|
25
|
+
#spec.add_development_dependency "yajl-ruby", "~> 1.2"
|
26
|
+
|
27
|
+
#spec.add_runtime_dependency "fluentd", [">= 1", "< 2"]
|
28
|
+
#spec.add_runtime_dependency "net-http-persistent", '~> 3.1'
|
29
|
+
spec.add_runtime_dependency "fluentd", [">= 1", "< 2"]
|
30
|
+
spec.add_runtime_dependency "net-http-persistent", '~> 3.1'
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
33
|
+
spec.add_development_dependency "test-unit", '~> 3.1'
|
34
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
35
|
+
spec.add_development_dependency "yajl-ruby", "~> 1.2"
|
36
|
+
spec.add_development_dependency 'webmock', '~> 3.5', '>= 3.5.0'
|
37
|
+
end
|
data/lib/fluent/plugin/2
ADDED
File without changes
|
data/lib/fluent/plugin/3
ADDED
File without changes
|
data/lib/fluent/plugin/e
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,353 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2021- magesh-1870
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "fluent/plugin/output"
|
17
|
+
|
18
|
+
module Fluent
|
19
|
+
module Plugin
|
20
|
+
class MageshLogsOutput < Fluent::Plugin::Output
|
21
|
+
Fluent::Plugin.register_output('mageshlogs', self)
|
22
|
+
|
23
|
+
S247_MAX_RECORD_COUNT = 500
|
24
|
+
S247_MAX_RECORD_SIZE = 1000000
|
25
|
+
S247_MAX_BATCH_SIZE = 5000000
|
26
|
+
S247_TRUNCATION_SUFFIX = "##TRUNCATED###"
|
27
|
+
|
28
|
+
helpers :compat_parameters
|
29
|
+
|
30
|
+
config_param :log_type_config, :string
|
31
|
+
config_param :max_retry, :integer, :default => 3
|
32
|
+
config_param :retry_interval, :integer, :default => 2
|
33
|
+
config_param :http_proxy, :string, :default => nil
|
34
|
+
|
35
|
+
config_section :buffer do
|
36
|
+
config_set_default :@type, "memory"
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def configure(conf)
|
44
|
+
compat_parameters_convert(conf, :buffer)
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
def multi_workers_ready?
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
def formatted_to_msgpack_binary?
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
def start
|
57
|
+
super
|
58
|
+
init_variables()
|
59
|
+
init_http_client(@logtype_config)
|
60
|
+
end
|
61
|
+
|
62
|
+
def shutdown
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
def terminate
|
67
|
+
super
|
68
|
+
@s247_http_client.shutdown if @s247_http_client
|
69
|
+
end
|
70
|
+
|
71
|
+
def init_variables()
|
72
|
+
@logtype_config = Yajl::Parser.parse(Base64.decode64(@log_type_config))
|
73
|
+
@s247_custom_regex = if @logtype_config.has_key? 'regex' then Regexp.compile(@logtype_config['regex'].gsub('?P<','?<')) else nil end
|
74
|
+
@s247_ignored_fields = if @logtype_config.has_key? 'ignored_fields' then @logtype_config['ignored_fields'] else [] end
|
75
|
+
@s247_tz = {'hrs': 0, 'mins': 0} #UTC
|
76
|
+
@log_source = Socket.gethostname
|
77
|
+
@s247_datetime_format_string = @logtype_config['dateFormat']
|
78
|
+
@s247_datetime_format_string = @s247_datetime_format_string.sub('%f', '%N')
|
79
|
+
if !@s247_datetime_format_string.include? 'unix'
|
80
|
+
is_year_present = if @s247_datetime_format_string.include?('%y') || @s247_datetime_format_string.include?('%Y') then true else false end
|
81
|
+
if !is_year_present
|
82
|
+
@s247_datetime_format_string = @s247_datetime_format_string+ ' %Y'
|
83
|
+
end
|
84
|
+
is_timezone_present = if @s247_datetime_format_string.include? '%z' then true else false end
|
85
|
+
if !is_timezone_present && @logtype_config.has_key?('timezone')
|
86
|
+
tz_value = @logtype_config['timezone']
|
87
|
+
if tz_value.start_with?('+')
|
88
|
+
@s247_tz['hrs'] = Integer('-' + tz_value[1..4])
|
89
|
+
@s247_tz['mins'] = Integer('-' + tz_value[3..6])
|
90
|
+
elsif tz_value.start_with?('-')
|
91
|
+
@s247_tz['hrs'] = Integer('+' + tz_value[1..4])
|
92
|
+
@s247_tz['mins'] = Integer('+' + tz_value[3..6])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def init_http_client(logtype_config)
|
99
|
+
require 'net/http/persistent'
|
100
|
+
upload_url = 'https://'+logtype_config['uploadDomain']+'/upload'
|
101
|
+
@uri = URI(upload_url)
|
102
|
+
proxy_uri = :ENV
|
103
|
+
if http_proxy
|
104
|
+
proxy_uri = URI.parse(http_proxy)
|
105
|
+
elsif ENV['HTTP_PROXY'] || ENV['http_proxy']
|
106
|
+
log.info "Using HTTP proxy defined in `HTTP_PROXY`/`http_proxy` env vars"
|
107
|
+
end
|
108
|
+
log.info "Starting HTTP connection to #{upload_url}"
|
109
|
+
@s247_http_client = Net::HTTP::Persistent.new name: "fluent-plugin-site24x7", proxy: proxy_uri
|
110
|
+
@s247_http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
111
|
+
@s247_http_client.override_headers["Content-Type"] = "application/json"
|
112
|
+
@s247_http_client.override_headers["Content-Encoding"] = "gzip"
|
113
|
+
@s247_http_client.override_headers["X-DeviceKey"] = logtype_config['apiKey']
|
114
|
+
@s247_http_client.override_headers["X-LogType"] = logtype_config['logType']
|
115
|
+
@s247_http_client.override_headers["X-StreamMode"] = 1
|
116
|
+
@s247_http_client.override_headers["User-Agent"] = 'Fluentd'
|
117
|
+
if !@s247_http_client.proxy_uri.nil?
|
118
|
+
# Log the proxy settings as resolved by the HTTP client
|
119
|
+
log.info "Using HTTP proxy #{@s247_http_client.proxy_uri.scheme}://#{@s247_http_client.proxy_uri.host}:#{@s247_http_client.proxy_uri.port} username: #{@s247_http_client.proxy_uri.user ? "set" : "unset"}, password: #{@s247_http_client.proxy_uri.password ? "set" : "unset"}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_timestamp(datetime_string)
|
124
|
+
begin
|
125
|
+
# If the date value is in unix format the no need to process the date string
|
126
|
+
if @s247_datetime_format_string.include? 'unix'
|
127
|
+
return (if @s247_datetime_format_string == 'unix' then datetime_string+'000' else datetime_string end)
|
128
|
+
end
|
129
|
+
datetime_string += if !is_year_present then ' '+String(Time.new.year) else '' end
|
130
|
+
if !is_timezone_present
|
131
|
+
@s247_datetime_format_string += '%z'
|
132
|
+
time_zone = String(@s247_tz['hrs'])+':'+String(@s247_tz['mins'])
|
133
|
+
datetime_string += if time_zone.start_with?('-') then time_zone else '+'+time_zone end
|
134
|
+
end
|
135
|
+
datetime_data = DateTime.strptime(datetime_string, @s247_datetime_format_string)
|
136
|
+
return Integer(datetime_data.strftime('%Q'))
|
137
|
+
rescue
|
138
|
+
return 0
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def parse_lines(lines)
|
143
|
+
parsed_lines = []
|
144
|
+
log_size = 0
|
145
|
+
lines.each do |line|
|
146
|
+
if !line.empty?
|
147
|
+
begin
|
148
|
+
if match = line.match(@s247_custom_regex)
|
149
|
+
log_size += line.bytesize
|
150
|
+
log_fields = match&.named_captures#matcher.groupdict(default='-')
|
151
|
+
removed_log_size=0
|
152
|
+
@s247_ignored_fields.each do |field_name|
|
153
|
+
removed_log_size += if log_fields.has_key?field_name then log_fields.delete(field_name).bytesize else 0 end
|
154
|
+
end
|
155
|
+
formatted_line = {'_zl_timestamp' => get_timestamp(log_fields[@logtype_config['dateField']]), 's247agentuid' => @log_source}
|
156
|
+
formatted_line.merge!(log_fields)
|
157
|
+
parsed_lines.push(formatted_line)
|
158
|
+
log_size -= removed_log_size
|
159
|
+
end
|
160
|
+
rescue Exception => e
|
161
|
+
log.info "Exception in parse_line #{e.backtrace}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
return parsed_lines, log_size
|
166
|
+
end
|
167
|
+
|
168
|
+
def is_filters_matched(formatted_line)
|
169
|
+
if @logtype_config.has_key?'filterConfig'
|
170
|
+
@logtype_config['filterConfig'].each do |config|
|
171
|
+
if formatted_line.has_key?config && (filter_config[config]['match'] ^ (filter_config[config]['values'].include?formatted_line[config]))
|
172
|
+
return false
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
return true
|
177
|
+
end
|
178
|
+
|
179
|
+
def get_json_value(obj, key, datatype=nil)
|
180
|
+
if obj != nil && (obj.has_key?key)
|
181
|
+
if datatype and datatype == 'json-object'
|
182
|
+
arr_json = []
|
183
|
+
child_obj = obj[key]
|
184
|
+
if child_obj.class == String
|
185
|
+
child_obj = Yajl::Parser.parse(child_obj.gsub('\\','\\\\'))
|
186
|
+
end
|
187
|
+
child_obj.each do |key, value|
|
188
|
+
arr_json.push({'key' => key, 'value' => String(value)})
|
189
|
+
end
|
190
|
+
return arr_json
|
191
|
+
else
|
192
|
+
return (if obj.has_key?key then obj[key] else obj[key.downcase] end)
|
193
|
+
end
|
194
|
+
elsif key.include?'.'
|
195
|
+
parent_key = key[0..key.index('.')-1]
|
196
|
+
child_key = key[key.index('.')+1..-1]
|
197
|
+
child_obj = obj[if obj.has_key?parent_key then parent_key else parent_key.capitalize() end]
|
198
|
+
if child_obj.class == String
|
199
|
+
child_obj = Yajl::Parser.parse(child_obj.replace('\\','\\\\'))
|
200
|
+
end
|
201
|
+
return get_json_value(child_obj, child_key)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def json_log_parser(lines_read)
|
206
|
+
log_size = 0
|
207
|
+
parsed_lines = []
|
208
|
+
lines_read.each do |line|
|
209
|
+
if !line.empty?
|
210
|
+
current_log_size = 0
|
211
|
+
formatted_line = {}
|
212
|
+
event_obj = Yajl::Parser.parse(line)
|
213
|
+
@logtype_config['jsonPath'].each do |path_obj|
|
214
|
+
value = get_json_value(event_obj, path_obj[if path_obj.has_key?'key' then 'key' else 'name' end], path_obj['type'])
|
215
|
+
if value
|
216
|
+
formatted_line[path_obj['name']] = value
|
217
|
+
current_log_size+= String(value).size - (if value.class == Array then value.size*20 else 0 end)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
if is_filters_matched(formatted_line)
|
221
|
+
formatted_line['_zl_timestamp'] = get_timestamp(formatted_line[@logtype_config['dateField']])
|
222
|
+
formatted_line['s247agentuid'] = @log_source
|
223
|
+
parsed_lines.push(formatted_line)
|
224
|
+
log_size+=current_log_size
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
return parsed_lines, log_size
|
229
|
+
end
|
230
|
+
|
231
|
+
def format(tag, time, record)
|
232
|
+
[record['message']].to_msgpack
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
def write(chunk)
|
237
|
+
begin
|
238
|
+
events = Array.new
|
239
|
+
chunk.msgpack_each do |record|
|
240
|
+
next if record.empty?
|
241
|
+
events.push record[0]
|
242
|
+
end
|
243
|
+
process_http_events(events)
|
244
|
+
rescue Exception => e
|
245
|
+
log.info "Exception #{e.backtrace}"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def process_http_events(events)
|
250
|
+
batches = batch_http_events(events)
|
251
|
+
batches.each do |batched_event|
|
252
|
+
formatted_events, log_size = format_http_event_batch(batched_event)
|
253
|
+
formatted_events = gzip_compress(formatted_events)
|
254
|
+
send_logs_to_s247(formatted_events, log_size)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def batch_http_events(encoded_events)
|
259
|
+
batches = []
|
260
|
+
current_batch = []
|
261
|
+
current_batch_size = 0
|
262
|
+
encoded_events.each_with_index do |encoded_event, i|
|
263
|
+
current_event_size = encoded_event.bytesize
|
264
|
+
if current_event_size > S247_MAX_RECORD_SIZE
|
265
|
+
encoded_event = encoded_event[0..(S247_MAX_RECORD_SIZE-DD_TRUNCATION_SUFFIX.length)]+DD_TRUNCATION_SUFFIX
|
266
|
+
current_event_size = encoded_event.bytesize
|
267
|
+
end
|
268
|
+
|
269
|
+
if (i > 0 and i % S247_MAX_RECORD_COUNT == 0) or (current_batch_size + current_event_size > S247_MAX_BATCH_SIZE)
|
270
|
+
batches << current_batch
|
271
|
+
current_batch = []
|
272
|
+
current_batch_size = 0
|
273
|
+
end
|
274
|
+
|
275
|
+
current_batch_size += current_event_size
|
276
|
+
current_batch << encoded_event
|
277
|
+
end
|
278
|
+
batches << current_batch
|
279
|
+
batches
|
280
|
+
end
|
281
|
+
|
282
|
+
def format_http_event_batch(events)
|
283
|
+
parsed_lines = []
|
284
|
+
log_size = 0
|
285
|
+
if @logtype_config.has_key?'jsonPath'
|
286
|
+
parsed_lines, log_size = json_log_parser(events)
|
287
|
+
else
|
288
|
+
parsed_lines, log_size = parse_lines(events)
|
289
|
+
end
|
290
|
+
return Yajl.dump(parsed_lines), log_size
|
291
|
+
end
|
292
|
+
|
293
|
+
def gzip_compress(payload)
|
294
|
+
gz = StringIO.new
|
295
|
+
gz.set_encoding("BINARY")
|
296
|
+
z = Zlib::GzipWriter.new(gz, 9)
|
297
|
+
begin
|
298
|
+
z.write(payload)
|
299
|
+
ensure
|
300
|
+
z.close
|
301
|
+
end
|
302
|
+
gz.string
|
303
|
+
end
|
304
|
+
|
305
|
+
def send_logs_to_s247(gzipped_parsed_lines, log_size)
|
306
|
+
request = Net::HTTP::Post.new @uri.request_uri
|
307
|
+
request.body = gzipped_parsed_lines
|
308
|
+
@s247_http_client.override_headers["Log-Size"] = log_size
|
309
|
+
sleep_interval = @retry_interval
|
310
|
+
begin
|
311
|
+
@max_retry.times do |counter|
|
312
|
+
need_retry = false
|
313
|
+
begin
|
314
|
+
response = @s247_http_client.request @uri, request
|
315
|
+
resp_headers = response.each_header.to_h
|
316
|
+
|
317
|
+
if response.code == '200'
|
318
|
+
if resp_headers.has_key?'LOG_LICENSE_EXCEEDS' && resp_headers['LOG_LICENSE_EXCEEDS'] == 'True'
|
319
|
+
log.error "Log license limit exceeds so not able to send logs"
|
320
|
+
elsif resp_headers.has_key?'BLOCKED_LOGTYPE' && resp_headers['BLOCKED_LOGTYPE'] == 'True'
|
321
|
+
log.error "Max upload limit reached for log type"
|
322
|
+
elsif resp_headers.has_key?'INVALID_LOGTYPE' && resp_headers['INVALID_LOGTYPE'] == 'True'
|
323
|
+
log.error "Log type not present in this account so stopping log collection"
|
324
|
+
else
|
325
|
+
log.info "Successfully sent logs with size #{gzipped_parsed_lines.size} / #{log_size} to site24x7. Upload Id : #{resp_headers['x-uploadid']}"
|
326
|
+
end
|
327
|
+
else
|
328
|
+
log.info "Response Code #{resp_headers} from Site24x7, so retrying (#{counter + 1}/#{@max_retry})"
|
329
|
+
need_retry = true
|
330
|
+
end
|
331
|
+
rescue StandardError => e
|
332
|
+
log.info "Error connecting to Site24x7. exception: #{e} (#{counter + 1}/#{@max_retry})"
|
333
|
+
end
|
334
|
+
|
335
|
+
if need_retry
|
336
|
+
if counter == @max_retry - 1
|
337
|
+
log.error "Could not send your logs after #{max_retry} tries"
|
338
|
+
break
|
339
|
+
end
|
340
|
+
sleep(sleep_interval)
|
341
|
+
sleep_interval *= 2
|
342
|
+
else
|
343
|
+
return
|
344
|
+
end
|
345
|
+
end
|
346
|
+
rescue Exception => e
|
347
|
+
log.error "Exception occurred in sendig logs : #{e}"
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
2
|
+
require "test-unit"
|
3
|
+
require "fluent/test"
|
4
|
+
require "fluent/test/driver/output"
|
5
|
+
require "fluent/test/helpers"
|
6
|
+
|
7
|
+
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
8
|
+
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/out_mageshlogs.rb"
|
3
|
+
|
4
|
+
class MageshlogsOutputTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
test "failure" do
|
10
|
+
flunk
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_driver(conf)
|
16
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::MageshlogsOutput).configure(conf)
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,112 +1,145 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mageshlogs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magesh Rajan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: net-http-persistent
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
16
36
|
requirements:
|
17
37
|
- - "~>"
|
18
38
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
39
|
+
version: '3.1'
|
40
|
+
type: :runtime
|
21
41
|
prerelease: false
|
22
42
|
version_requirements: !ruby/object:Gem::Requirement
|
23
43
|
requirements:
|
24
44
|
- - "~>"
|
25
45
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
46
|
+
version: '3.1'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
48
|
+
name: bundler
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
30
50
|
requirements:
|
31
51
|
- - "~>"
|
32
52
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
53
|
+
version: '2.1'
|
34
54
|
type: :development
|
35
55
|
prerelease: false
|
36
56
|
version_requirements: !ruby/object:Gem::Requirement
|
37
57
|
requirements:
|
38
58
|
- - "~>"
|
39
59
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
60
|
+
version: '2.1'
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: test-unit
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
44
64
|
requirements:
|
45
65
|
- - "~>"
|
46
66
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
67
|
+
version: '3.1'
|
48
68
|
type: :development
|
49
69
|
prerelease: false
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
51
71
|
requirements:
|
52
72
|
- - "~>"
|
53
73
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
74
|
+
version: '3.1'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
76
|
+
name: rake
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
59
79
|
- - "~>"
|
60
80
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
81
|
+
version: '12.0'
|
62
82
|
type: :development
|
63
83
|
prerelease: false
|
64
84
|
version_requirements: !ruby/object:Gem::Requirement
|
65
85
|
requirements:
|
66
86
|
- - "~>"
|
67
87
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
88
|
+
version: '12.0'
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
90
|
+
name: yajl-ruby
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
72
92
|
requirements:
|
73
|
-
- - "
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1'
|
76
|
-
- - "<"
|
93
|
+
- - "~>"
|
77
94
|
- !ruby/object:Gem::Version
|
78
|
-
version: '2'
|
79
|
-
type: :
|
95
|
+
version: '1.2'
|
96
|
+
type: :development
|
80
97
|
prerelease: false
|
81
98
|
version_requirements: !ruby/object:Gem::Requirement
|
82
99
|
requirements:
|
83
|
-
- - "
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '1'
|
86
|
-
- - "<"
|
100
|
+
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
|
-
version: '2'
|
102
|
+
version: '1.2'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
104
|
+
name: webmock
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
107
|
- - "~>"
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version: '3.
|
96
|
-
|
109
|
+
version: '3.5'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 3.5.0
|
113
|
+
type: :development
|
97
114
|
prerelease: false
|
98
115
|
version_requirements: !ruby/object:Gem::Requirement
|
99
116
|
requirements:
|
100
117
|
- - "~>"
|
101
118
|
- !ruby/object:Gem::Version
|
102
|
-
version: '3.
|
119
|
+
version: '3.5'
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 3.5.0
|
103
123
|
description:
|
104
124
|
email:
|
105
125
|
- mageshrajan0007@gmail.com
|
106
126
|
executables: []
|
107
127
|
extensions: []
|
108
128
|
extra_rdoc_files: []
|
109
|
-
files:
|
129
|
+
files:
|
130
|
+
- Gemfile
|
131
|
+
- Gemfile.lock
|
132
|
+
- LICENSE
|
133
|
+
- README.md
|
134
|
+
- Rakefile
|
135
|
+
- fluent-plugin-mageshlogs.gemspec
|
136
|
+
- lib/fluent/plugin/2
|
137
|
+
- lib/fluent/plugin/3
|
138
|
+
- lib/fluent/plugin/e
|
139
|
+
- lib/fluent/plugin/nil
|
140
|
+
- lib/fluent/plugin/out_mageshlogs.rb
|
141
|
+
- test/helper.rb
|
142
|
+
- test/plugin/test_out_mageshlogs.rb
|
110
143
|
homepage: https://www.site24x7.com/log-management.html
|
111
144
|
licenses:
|
112
145
|
- ''
|
@@ -130,4 +163,6 @@ rubygems_version: 3.2.24
|
|
130
163
|
signing_key:
|
131
164
|
specification_version: 4
|
132
165
|
summary: Magesh output plugin for Fluent event collector
|
133
|
-
test_files:
|
166
|
+
test_files:
|
167
|
+
- test/helper.rb
|
168
|
+
- test/plugin/test_out_mageshlogs.rb
|