fluent-plugin-fluent-package-update-notifier 0.1.0
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 +7 -0
- data/LICENSE +202 -0
- data/README.md +71 -0
- data/Rakefile +13 -0
- data/lib/fluent/plugin/fluent_package_update_checker.rb +235 -0
- data/lib/fluent/plugin/in_fluent_package_update_notifier.rb +80 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf90e9f7087062ad11435cdfdf83799e06ec3f27b0866e794d98ec0bd4d904c8
|
4
|
+
data.tar.gz: 6cc31d61d115e3c277eff7670da0f8056bac9949e33f8d27753c90b176a42174
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f82f1c34bfa6b2bb8e7bca0dbc223958e4f32771ea28a97c4d625e41a55e19c27cada4234f2af0b119ead4628a2d3282611c67a1ed63396df6ee3a1a3d1c0c3
|
7
|
+
data.tar.gz: a1fbcd13577f46364d342da34b74820a08981f5bef0d63f05a05a915b96b5ddae9192d886081a8ea43eaf75be1afe42c57657bb78ac6e3327fb8cd5e8a50c2ba
|
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,71 @@
|
|
1
|
+
# fluent-plugin-fluent-package-update-notifier
|
2
|
+
|
3
|
+
[Fluentd](https://fluentd.org/) input plugin to notify with
|
4
|
+
update logging when newer `fluent-package` is available.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
### RubyGems
|
9
|
+
|
10
|
+
```
|
11
|
+
$ gem install fluent-plugin-fluent-package-update-notifier
|
12
|
+
```
|
13
|
+
|
14
|
+
### Bundler
|
15
|
+
|
16
|
+
Add following line to your Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem "fluent-plugin-fluent-package-update-notifier"
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ bundle
|
26
|
+
```
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
|parameter|type|description|default|
|
31
|
+
|---|---|---|---|
|
32
|
+
|lts|bool (optional)|Notify fluent-package updates which depends on channel (e.g. Monitor LTS by default)|`true`|
|
33
|
+
|notify_major_upgrade|bool (optional)|Notify whether major upgrade is available or not (e.g. from v5 to v6)|`true`|
|
34
|
+
|notify_level|enum (optional)|Specify notification log level when update is available (`info`, `warn`)|`info`|
|
35
|
+
|notify_interval|integer (optional)|Notify checking update intervals|`86400`|
|
36
|
+
|repository_sites|array (optional)|Package repository site|`["https://packages.treasuredata.com"]`|
|
37
|
+
|
38
|
+
## Example
|
39
|
+
|
40
|
+
If you want to collect update notification via log stream to specific file, let's configure it with @FLUENT_LOG label:
|
41
|
+
|
42
|
+
```
|
43
|
+
<source>
|
44
|
+
@type fluent_package_update_notifier
|
45
|
+
</source>
|
46
|
+
|
47
|
+
<label @FLUENT_LOG>
|
48
|
+
<match fluent.{warn,info}>
|
49
|
+
@type file
|
50
|
+
path notify-fluent-log
|
51
|
+
<buffer []>
|
52
|
+
flush_at_shutdown
|
53
|
+
</buffer>
|
54
|
+
</match>
|
55
|
+
</label>
|
56
|
+
```
|
57
|
+
|
58
|
+
When shutting down fluentd, `notify-fluent-log_0.log` or similar file (`notify-fluent-log_N.log`) will be saved.
|
59
|
+
|
60
|
+
```
|
61
|
+
2025-04-21T12:30:53+09:00 fluent.info {"pid":134883,"ppid":134869,"worker":0,"message":"starting fluentd worker pid=134883 ppid=134869 worker=0"}
|
62
|
+
2025-04-21T12:30:53+09:00 fluent.info {"message":"fluent-package v5.0.6 is available! See https://github.com/fluent/fluent-package-builder/releases/tag/v5.0.6 in details.\n"}
|
63
|
+
2025-04-21T12:30:53+09:00 fluent.info {"worker":0,"message":"fluentd worker is now running worker=0"}
|
64
|
+
2025-04-21T12:31:00+09:00 fluent.info {"worker":0,"message":"fluentd worker is now stopping worker=0"}
|
65
|
+
```
|
66
|
+
|
67
|
+
## Copyright
|
68
|
+
|
69
|
+
* Copyright(c) 2025- Kentaro Hayashi
|
70
|
+
* License
|
71
|
+
* 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,235 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'rbconfig'
|
5
|
+
|
6
|
+
module Fluent
|
7
|
+
module Plugin
|
8
|
+
module FluentPackage
|
9
|
+
class UpdateChecker
|
10
|
+
DEFAULT_PACKAGE_CONFIG_PATH = "/opt/fluent/share/config"
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
@logger = options[:logger]
|
14
|
+
@options = options
|
15
|
+
@newer_versions = []
|
16
|
+
@newer_lts_versions = []
|
17
|
+
@major_lts_updates = []
|
18
|
+
@major_updates = []
|
19
|
+
@tmp_dir = Dir.mktmpdir("fluent_package_update_notifier")
|
20
|
+
begin
|
21
|
+
require ENV["FLUENT_PACKAGE_CONFIG"] || DEFAULT_PACKAGE_CONFIG_PATH
|
22
|
+
rescue LoadError
|
23
|
+
@logger.error "Failed to load #{ENV["FLUENT_PACKAGE_CONFIG"] || DEFAULT_PACKAGE_CONFIG_PATH}"
|
24
|
+
end
|
25
|
+
@host_os = RbConfig::CONFIG['host_os']
|
26
|
+
end
|
27
|
+
|
28
|
+
def windows?
|
29
|
+
!!(@host_os =~ /mswin|mingw/)
|
30
|
+
end
|
31
|
+
|
32
|
+
def linux?
|
33
|
+
!!(@host_os =~ /linux/)
|
34
|
+
end
|
35
|
+
|
36
|
+
def tags_cached?
|
37
|
+
File.exist?(cached_tags_path) and
|
38
|
+
(Time.now - 60 * 60 * 24) < File.mtime(cached_tags_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def cached_tags_path
|
42
|
+
ENV["FLUENT_PACKAGE_TAGS_PATH"] ?
|
43
|
+
ENV["FLUENT_PACKAGE_TAGS_PATH"] : "#{@tmp_dir}/fluent-package-tags.json"
|
44
|
+
end
|
45
|
+
|
46
|
+
def release_tags_url
|
47
|
+
"https://api.github.com/repos/fluent/fluent-package-builder/tags"
|
48
|
+
end
|
49
|
+
|
50
|
+
def fetch_tags
|
51
|
+
begin
|
52
|
+
if tags_cached?
|
53
|
+
yield JSON.parse(File.open(cached_tags_path).read)
|
54
|
+
else
|
55
|
+
URI.open(release_tags_url) do |resource|
|
56
|
+
File.open(cached_tags_path, "w+") do |f|
|
57
|
+
json = resource.read
|
58
|
+
f.write(json)
|
59
|
+
yield JSON.parse(json)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
rescue => e
|
64
|
+
@logger.error "Failed to fetch tags", error: e
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def same_lts_series?(base_version, target_version)
|
69
|
+
# compare [major, 0] pair information
|
70
|
+
@options[:lts] and [base_version.segments.first, 0] == target_version.segments[..1]
|
71
|
+
end
|
72
|
+
|
73
|
+
def major_lts_update?(base_version, target_version)
|
74
|
+
@options[:lts] and
|
75
|
+
base_version.segments.first < target_version.segments.first and
|
76
|
+
[base_version.segments[1], target_version.segments[1]] == [0, 0]
|
77
|
+
end
|
78
|
+
|
79
|
+
def parse_os_release(key)
|
80
|
+
File.open("/etc/os-release").readlines.each do |line|
|
81
|
+
if line.start_with?(key)
|
82
|
+
line.chomp =~ /^#{key}=(.+)$/
|
83
|
+
return $1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def package_url(prefix, distribution, version)
|
90
|
+
major = version.segments.first
|
91
|
+
channel = @options[:lts] ? "lts/#{major}" : major
|
92
|
+
case distribution
|
93
|
+
when "debian", "ubuntu"
|
94
|
+
release = parse_os_release("VERSION_CODENAME")
|
95
|
+
"#{prefix}/#{channel}/#{distribution}/#{release}/pool/contrib/f/fluent-package/fluent-package_#{version}-1_amd64.deb"
|
96
|
+
when "redhat/8"
|
97
|
+
"#{prefix}/#{channel}/#{distribution}/x86_64/fluent-package_#{version}-1.el8.x86_64.rpm"
|
98
|
+
when "redhat/9"
|
99
|
+
"#{prefix}/#{channel}/#{distribution}/x86_64/fluent-package_#{version}-1.el9.x86_64.rpm"
|
100
|
+
when "amazon/2023"
|
101
|
+
"#{prefix}/#{channel}/#{distribution}/x86_64/fluent-package_#{version}-1.amzn2023.x86_64.rpm"
|
102
|
+
when "amazon/2"
|
103
|
+
"#{prefix}/#{channel}/#{distribution}/x86_64/fluent-package_#{version}-1.amzn2.x86_64.rpm"
|
104
|
+
when "windows"
|
105
|
+
"#{prefix}/#{channel}/#{distribution}/fluent-package-#{version}-x64.msi"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def generate_remote_package_url(url_prefix, target_version)
|
110
|
+
if linux?
|
111
|
+
os_release_id = parse_os_release("ID")
|
112
|
+
case os_release_id
|
113
|
+
when "debian"
|
114
|
+
url = package_url(url_prefix, "debian", target_version)
|
115
|
+
@logger.debug("Check existence of #{url}")
|
116
|
+
url
|
117
|
+
when "ubuntu"
|
118
|
+
package_url(url_prefix, "ubuntu", target_version)
|
119
|
+
when "rocky", "almalinux", "amzn"
|
120
|
+
cpe = parse_os_release("CPE_NAME")
|
121
|
+
case cpe
|
122
|
+
when /rocky:8/, /almalinux:8/
|
123
|
+
package_url(url_prefix, "redhat/8", target_version)
|
124
|
+
when /rocky:9/, /almalinux:9/
|
125
|
+
package_url(url_prefix, "redhat/9", target_version)
|
126
|
+
when /amazon_linux:2023/, /amazon_linux:2/
|
127
|
+
version = parse_os_release("VERSION")
|
128
|
+
case version
|
129
|
+
when "2023"
|
130
|
+
package_url(url_prefix, "amazon/2023", target_version)
|
131
|
+
when "2"
|
132
|
+
package_url(url_prefix, "amazon/2", target_version)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
elsif windows?
|
137
|
+
package_url(url_prefix, "windows", target_version)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def check_remote_packages(target_version)
|
142
|
+
@options[:repository_sites].each do |url_prefix|
|
143
|
+
yield generate_remote_package_url(url_prefix, target_version)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def check_package_released?(target_version)
|
148
|
+
major = target_version.segments.first
|
149
|
+
check_remote_packages(target_version) do |url|
|
150
|
+
begin
|
151
|
+
URI.open(url)
|
152
|
+
return true
|
153
|
+
rescue => e
|
154
|
+
# package is not available
|
155
|
+
@logger.debug("#{url} is inaccessible", error: e)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
# assume package is not available by default
|
159
|
+
false
|
160
|
+
end
|
161
|
+
|
162
|
+
def check_update_versions
|
163
|
+
current_version = Gem::Version.new("#{PACKAGE_VERSION}")
|
164
|
+
fetch_tags do |releases|
|
165
|
+
releases.each do |release|
|
166
|
+
version = release["name"]
|
167
|
+
next if version.include?("-") # skip test artifacts
|
168
|
+
target_version = Gem::Version.new(version.delete("v"))
|
169
|
+
if target_version > current_version
|
170
|
+
major = current_version.segments.first
|
171
|
+
if same_lts_series?(current_version, target_version)
|
172
|
+
@newer_lts_versions << version if check_package_released?(target_version)
|
173
|
+
elsif version.start_with?("v#{major}")
|
174
|
+
@newer_versions << version if check_package_released?(target_version)
|
175
|
+
else
|
176
|
+
# major upgrade standard/LTS version
|
177
|
+
if major_lts_update?(current_version, target_version)
|
178
|
+
# LTS
|
179
|
+
@major_lts_updates << version if check_package_released?(target_version)
|
180
|
+
else
|
181
|
+
@major_updates << version if check_package_released?(target_version)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
FileUtils.rm_rf(@tmp_dir)
|
188
|
+
end
|
189
|
+
|
190
|
+
def notify_update_log
|
191
|
+
candidates = nil
|
192
|
+
if @options[:lts]
|
193
|
+
if @options[:notify_major_upgrade]
|
194
|
+
candidates = if @major_lts_updates.count > 0
|
195
|
+
@major_lts_updates
|
196
|
+
elsif @newer_lts_versions.count > 0
|
197
|
+
@newer_lts_versions
|
198
|
+
end
|
199
|
+
else
|
200
|
+
candidates = @newer_lts_versions
|
201
|
+
end
|
202
|
+
else
|
203
|
+
if @options[:notify_major_upgrade]
|
204
|
+
candidates = if @major_updates.count > 0
|
205
|
+
@major_updates
|
206
|
+
elsif @newer_versions.count > 0
|
207
|
+
@newer_versions
|
208
|
+
end
|
209
|
+
else
|
210
|
+
candidates = @newer_versions
|
211
|
+
end
|
212
|
+
end
|
213
|
+
if candidates
|
214
|
+
# Assume the version information are already sorted in descendant order by GitHub API
|
215
|
+
url = "https://github.com/fluent/fluent-package-builder/releases/tag/#{candidates.first}"
|
216
|
+
message = "fluent-package #{candidates.first} is available! See #{url} in details."
|
217
|
+
else
|
218
|
+
message = "No update for fluent-package #{PACKAGE_VERSION}"
|
219
|
+
end
|
220
|
+
case @options[:notify_level]
|
221
|
+
when :warn
|
222
|
+
@logger.warn(message)
|
223
|
+
when :info
|
224
|
+
@logger.info(message)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def run
|
229
|
+
check_update_versions
|
230
|
+
notify_update_log
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2025- Kentaro Hayashi
|
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/input"
|
17
|
+
require "fluent/log"
|
18
|
+
require "fluent/config/error"
|
19
|
+
require_relative "./fluent_package_update_checker"
|
20
|
+
|
21
|
+
module Fluent
|
22
|
+
module Plugin
|
23
|
+
class FluentPackageUpdateNotifierInput < Fluent::Plugin::Input
|
24
|
+
Fluent::Plugin.register_input("fluent_package_update_notifier", self)
|
25
|
+
|
26
|
+
helpers :timer
|
27
|
+
|
28
|
+
desc "Notify fluent-package updates which depends on channel (e.g. Monitor LTS by default)"
|
29
|
+
config_param :lts, :bool, default: true
|
30
|
+
|
31
|
+
desc "Notify whether major upgrade is available or not (e.g. from v5 to v6)"
|
32
|
+
config_param :notify_major_upgrade, :bool, default: true
|
33
|
+
|
34
|
+
desc "Specify notification log level when update is available"
|
35
|
+
config_param :notify_level, :enum, list: [:info, :warn], default: :info
|
36
|
+
|
37
|
+
desc "Notify checking update intervals"
|
38
|
+
config_param :notify_interval, :integer, default: 60 * 60 * 24
|
39
|
+
|
40
|
+
desc "Package repository site"
|
41
|
+
config_param :repository_sites, :array, default: ["https://packages.treasuredata.com"]
|
42
|
+
|
43
|
+
def configure(conf)
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def start
|
48
|
+
super
|
49
|
+
check_fluent_pacakge_update_information
|
50
|
+
timer_execute(:in_fluent_package_update_notifier_worker, @notify_interval, &method(:run))
|
51
|
+
end
|
52
|
+
|
53
|
+
def shutdown
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
def run
|
58
|
+
check_fluent_pacakge_update_information
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def check_fluent_pacakge_update_information
|
64
|
+
begin
|
65
|
+
options = {
|
66
|
+
lts: @lts,
|
67
|
+
notify_major_upgrade: @notify_major_upgrade,
|
68
|
+
notify_level: @notify_level,
|
69
|
+
logger: log,
|
70
|
+
repository_sites: @repository_sites
|
71
|
+
}
|
72
|
+
checker = Fluent::Plugin::FluentPackage::UpdateChecker.new(options)
|
73
|
+
checker.run
|
74
|
+
rescue => e
|
75
|
+
log.error "Failed to check updates: #{e.message}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-fluent-package-update-notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kentaro Hayashi
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: bundler
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.4'
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '2.4'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 13.2.1
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 13.2.1
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: test-unit
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.6.7
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.6.7
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: test-unit-rr
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.0.5
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.0.5
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: fluentd
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.14.10
|
75
|
+
- - "<"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.14.10
|
85
|
+
- - "<"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '2'
|
88
|
+
description: Notify latest version of fluent-package on startup
|
89
|
+
email:
|
90
|
+
- hayashi@clear-code.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/fluent/plugin/fluent_package_update_checker.rb
|
99
|
+
- lib/fluent/plugin/in_fluent_package_update_notifier.rb
|
100
|
+
homepage: https://github.com/fluent-plugins-nursery/fluent-plugin-fluent-package-update-notifier
|
101
|
+
licenses:
|
102
|
+
- Apache-2.0
|
103
|
+
metadata:
|
104
|
+
homepage_uri: https://github.com/fluent-plugins-nursery/fluent-plugin-fluent-package-update-notifier
|
105
|
+
source_code_uri: https://github.com/fluent-plugins-nursery/fluent-plugin-fluent-package-update-notifier
|
106
|
+
changelog_uri: https://github.com/fluent-plugins-nursery/fluent-plugin-fluent-package-update-notifier/blob/main/CHANGELOG.md
|
107
|
+
bug_tracker_uri: https://github.com/fluent-plugins-nursery/fluent-plugin-fluent-package-update-notifier/issues
|
108
|
+
rubygems_mfa_required: 'true'
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubygems_version: 3.6.7
|
124
|
+
specification_version: 4
|
125
|
+
summary: Notify latest version of fluent-package
|
126
|
+
test_files: []
|