fluent-plugin-systemd 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afd6dfa882a391ee1baee61851e2f7d277439e43389857c88278541fbac339cf
4
- data.tar.gz: 757d8056bf7e918c18f806bab6437eb9c432ce753a12398c01e7db19c3508d13
3
+ metadata.gz: f94db112984a3413fe3ba1c596a8f51dae261665defc3fe4bcfc34f24b2a1aa1
4
+ data.tar.gz: d371e3abd3f24f0d889db702aa5df4ce3bdf54898d9b4d4ce03dcbf74ea3fcf8
5
5
  SHA512:
6
- metadata.gz: 18e6f3a84a0e44008a37f54e1b245c8af565099640746108d8aa22b17bda6205d7d54ae90b49f00f0ef26664bd947ced40e930ac19327f927f778c1610e88fe2
7
- data.tar.gz: e3e5d91220e70391ea08f5ae7a115bbe8e617c3ac1c21ec1660bf4f435c57de679fb23b7b01d4035ed0e47f5ad129543fec2d880e811cbaeb6ba4d43f4c7d6e9
6
+ metadata.gz: 0fa42e69a59fbf29b074a6c882db1c7e228f646ea6e3ed131f388d5705d1b9af85a9ee4616cb2ccd968118490bd1a1e57f10279a7b8a5f9f4ec6d18e557c5034
7
+ data.tar.gz: 8d846a57a05c53be90f351d5d4a7ccdd6a1ff3fd0d030ae0ca4aafd21c6f0fe11d7c68f1796d98ac9015fb80ea6e46fd935b6dc300a7b75d42dcd56d5f22fb6d
data/README.md CHANGED
@@ -69,7 +69,9 @@ If you are upgrading to version 1.0 from a previous version of this plugin take
69
69
 
70
70
  **`path`**
71
71
 
72
- Path to the systemd journal, defaults to `/var/log/journal`
72
+ Path to the systemd journal **directory**, defaults to `/var/log/journal`.
73
+
74
+ This must be a directory, not an individual file or a glob pattern — for example, `/var/log/journal/*.journal` will not work. All journal files in the given directory are read automatically.
73
75
 
74
76
  **`filters`**
75
77
 
@@ -141,6 +143,13 @@ If true, lowercase all non-mapped fields. Defaults to false.
141
143
 
142
144
  If true, strip leading underscores from all non-mapped fields. Defaults to false.
143
145
 
146
+ Journald reserves the leading underscore for its trusted fields, which a client cannot forge,
147
+ while a client is free to send a user field with the same name minus the underscore.
148
+ Stripping makes both names collide, so the trusted field wins and the user field of that name is dropped.
149
+ For example, if an entry holds `_SYSTEMD_UNIT` and a client supplied `SYSTEMD_UNIT`,
150
+ the result only holds the trusted value.
151
+ Map the trusted field to another name with `field_map` if you need to keep both.
152
+
144
153
  ### Filter Example
145
154
 
146
155
  Given a systemd journal source entry:
@@ -50,7 +50,8 @@ module Fluent
50
50
  def configure(conf)
51
51
  super
52
52
  @journal = nil
53
- @pos_storage = storage_create(usage: 'positions')
53
+ config = conf.elements.find { |e| e.name == 'storage' }
54
+ @pos_storage = storage_create(usage: 'positions', conf: config, default_type: DEFAULT_STORAGE_TYPE)
54
55
  @mutator = SystemdEntryMutator.new(**@entry_opts.to_h)
55
56
  @mutator.warnings.each { |warning| log.warn(warning) }
56
57
  end
@@ -15,6 +15,7 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'fluent/config/error'
18
+ require 'systemd/journal/fields'
18
19
 
19
20
  module Fluent
20
21
  module Plugin
@@ -33,7 +34,7 @@ module Fluent
33
34
  # "<new_field1>" => ["<source_field1>", "<source_field2>"],
34
35
  # "<new_field2>" => ["<source_field2>"]
35
36
  # }
36
- class SystemdEntryMutator
37
+ class SystemdEntryMutator # rubocop:disable Metrics/ClassLength
37
38
  Options = Struct.new(
38
39
  :field_map,
39
40
  :field_map_strict,
@@ -41,6 +42,8 @@ module Fluent
41
42
  :fields_strip_underscores
42
43
  )
43
44
 
45
+ TRUSTED_FIELDS = (Systemd::Journal::TRUSTED_FIELDS + Systemd::Journal::KERNEL_FIELDS).freeze
46
+
44
47
  def self.default_opts
45
48
  Options.new({}, false, false, false)
46
49
  end
@@ -103,13 +106,20 @@ module Fluent
103
106
  # mapped - Optional hash that represents a previously mapped entry to
104
107
  # which the formatted fields will be added
105
108
  def format_fields(entry, mapped = nil)
109
+ reserved = reserved_field_names(entry)
106
110
  entry.each_with_object(mapped || {}) do |(fld, val), formatted_entry|
107
111
  # don't mess with explicitly mapped fields
108
112
  next if @map_src_fields.include?(fld)
109
113
 
110
- fld = format_field_name(fld)
114
+ name = format_field_name(fld)
115
+ # A client may send `SYSTEMD_UNIT` but never `_SYSTEMD_UNIT`, so the
116
+ # trusted field keeps the name when stripping underscores makes the
117
+ # two collide. Otherwise any local process could fake the journal
118
+ # metadata that the trusted fields are supposed to guarantee.
119
+ next if !fld.start_with?('_') && reserved.include?(name)
120
+
111
121
  # account for mapping (appending) to an existing systemd field
112
- formatted_entry[fld] = join_if_needed([val, mapped[fld]])
122
+ formatted_entry[name] = join_if_needed([val, mapped[name]])
113
123
  end
114
124
  end
115
125
 
@@ -128,6 +138,25 @@ module Fluent
128
138
  values.join(' ')
129
139
  end
130
140
 
141
+ def reserved_field_names(entry)
142
+ return [] unless @opts.fields_strip_underscores
143
+
144
+ trusted_field_names(entry).each_with_object([]) do |fld, names|
145
+ name = format_field_name(fld)
146
+ next if @map_src_fields.include?(fld) && !Array(@opts.field_map[fld]).include?(name)
147
+
148
+ names << name
149
+ end
150
+ end
151
+
152
+ # Journald never lets a client send a leading underscore, so the known
153
+ # trusted names stay reserved even when this entry does not carry them.
154
+ def trusted_field_names(entry)
155
+ entry.each_with_object(TRUSTED_FIELDS.dup) do |(fld, _val), flds|
156
+ flds << fld if fld.start_with?('_')
157
+ end
158
+ end
159
+
131
160
  def format_field_name(name)
132
161
  name = name.gsub(/\A_+/, '') if @opts.fields_strip_underscores
133
162
  name = name.downcase if @opts.fields_lowercase
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-systemd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Robinson
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-02-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -112,11 +111,13 @@ files:
112
111
  - lib/fluent/plugin/filter_systemd_entry.rb
113
112
  - lib/fluent/plugin/in_systemd.rb
114
113
  - lib/fluent/plugin/systemd/entry_mutator.rb
115
- homepage: https://github.com/reevoo/fluent-plugin-systemd
114
+ homepage: https://github.com/fluent-plugins-nursery/fluent-plugin-systemd
116
115
  licenses:
117
116
  - Apache-2.0
118
- metadata: {}
119
- post_install_message:
117
+ metadata:
118
+ homepage_uri: https://github.com/fluent-plugins-nursery/fluent-plugin-systemd
119
+ source_code_uri: https://github.com/fluent-plugins-nursery/fluent-plugin-systemd
120
+ bug_tracker_uri: https://github.com/fluent-plugins-nursery/fluent-plugin-systemd/issues
120
121
  rdoc_options: []
121
122
  require_paths:
122
123
  - lib
@@ -131,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  - !ruby/object:Gem::Version
132
133
  version: '0'
133
134
  requirements: []
134
- rubygems_version: 3.5.22
135
- signing_key:
135
+ rubygems_version: 3.6.9
136
136
  specification_version: 4
137
137
  summary: Input plugin to read from systemd journal.
138
138
  test_files: []