fluent-plugin-parser_cef 1.0.1 → 1.2.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 +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +41 -14
- data/VERSION +1 -1
- data/lib/fluent/plugin/config/cef_version_0_keys.yaml +50 -0
- data/lib/fluent/plugin/parser_cef.rb +102 -28
- data/spec/fluent/plugin/parser_cef_spec.rb +236 -3
- metadata +1 -2
- data/.rubocop.yml +0 -1156
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b15b0ff74bba7ae5207f7493b100edcc016d903d28021b605e6d557c30c1c8fd
|
|
4
|
+
data.tar.gz: '0966c3be3606e6b05b5bf55c96c4dd7bebf48dd91d341c4be4ac9736cab5941e'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de60cf54a72888ed1f228615974c8ea62c517196fb46b4627d9b30ca16ddc8b2b8b7c0fd41ac3bf3b6d2567425e695e7eff39f58c6faf9b83fc26e566fc29c1e
|
|
7
|
+
data.tar.gz: df7da836cdc179cd1b36dea33d2a2c928ebb81d4c060fb8d6ef89f17ffc3bc481285a0dc267b19cee70cfdfc16c3221728d6d47f4cd02e8ce358d048dedc6b25
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 1.2.0 - 2026-12-05
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `cef_unescape` option to handle CEF escape sequences: escaped `|` in
|
|
10
|
+
header fields and escaped `=` in extension values no longer act as
|
|
11
|
+
separators, and `\|` `\\` (header) and `\=` `\\` `\|` `\n` `\r`
|
|
12
|
+
(extension) are unescaped. Defaults to `false`, which keeps the 1.1.0
|
|
13
|
+
output (#14).
|
|
14
|
+
|
|
15
|
+
### Removed
|
|
16
|
+
|
|
17
|
+
- The outdated `.rubocop.yml`, which current RuboCop rejects and which was
|
|
18
|
+
shipped in the gem (#15).
|
|
19
|
+
|
|
20
|
+
## 1.1.0 - 2026-12-05
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Lines with a syslog `<PRI>` value (added as `syslog_pri`), an RFC 5424
|
|
25
|
+
header (adds `syslog_version`, `syslog_procid`, `syslog_msgid` and
|
|
26
|
+
`syslog_structured_data`; APP-NAME goes to `syslog_tag`) or no syslog
|
|
27
|
+
header (starting with `CEF:`) are now parsed instead of being emitted
|
|
28
|
+
as `raw` (#3, #8, #12; based on #4).
|
|
29
|
+
- Palo Alto Networks PAN-OS keys in the default key file (#6, #12).
|
|
30
|
+
- `cef_additional_keys` option to add known keys for strict mode (#12).
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- Strict mode: when the first extension key was not a known key, the
|
|
35
|
+
whole extension was dropped. Such a key now becomes a field (#12).
|
|
36
|
+
- Timestamps ending in `Z` are read as UTC (#12).
|
|
37
|
+
|
|
5
38
|
## 1.0.1 - 2026-12-05
|
|
6
39
|
|
|
7
40
|
### Fixed
|
data/README.md
CHANGED
|
@@ -99,20 +99,24 @@ Record (event time: `2026-12-05 10:00:00 +09:00` with `log_utc_offset +09:00`):
|
|
|
99
99
|
}
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
Lines that do not match any supported format are emitted as
|
|
103
|
+
`{"raw": "<the original line>"}`.
|
|
104
104
|
|
|
105
|
-
### Supported input
|
|
105
|
+
### Supported input formats
|
|
106
106
|
|
|
107
|
-
Each line
|
|
108
|
-
|
|
107
|
+
Each line may start with a syslog `<PRI>` value (added as `syslog_pri`),
|
|
108
|
+
followed by one of:
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
| Header | Example | Added fields |
|
|
111
|
+
|--------|---------|--------------|
|
|
112
|
+
| Traditional (RFC 3164 style) | `Dec 5 10:00:00 fw01 tag CEF:0\|...` | `syslog_timestamp`, `syslog_hostname`, `syslog_tag` |
|
|
113
|
+
| RFC 5424 | `1 2026-12-05T10:00:00+09:00 fw01 app 1234 ID47 - CEF:0\|...` | `syslog_version`, `syslog_timestamp`, `syslog_hostname`, `syslog_tag` (APP-NAME), `syslog_procid`, `syslog_msgid`, `syslog_structured_data` |
|
|
114
|
+
| None | `CEF:0\|...` | - |
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
The syslog timestamp becomes the event time. Without one (no header, or the
|
|
117
|
+
RFC 5424 `-` NILVALUE) the current time is used.
|
|
118
|
+
|
|
119
|
+
The `<PRI>`, RFC 5424 and header-less formats are supported from 1.1.0.
|
|
116
120
|
|
|
117
121
|
## Parameters
|
|
118
122
|
|
|
@@ -120,11 +124,13 @@ header are not supported yet and are emitted as `raw`.
|
|
|
120
124
|
|---------------------------|---------|-----------------------------------------------|-------------|
|
|
121
125
|
| `log_format` | string | `syslog` | Input format. Only `syslog` is supported. |
|
|
122
126
|
| `log_utc_offset` | string | `nil` | UTC offset (e.g. `+09:00`) used when the timestamp has no time zone. When unset or invalid, the system time zone is used. Ignored for timestamps that include a time zone. |
|
|
123
|
-
| `syslog_timestamp_format` | string | `\w{3}\s+\d{1,2}\s\d{2}:\d{2}:\d{2}` | Regular expression that matches the syslog
|
|
127
|
+
| `syslog_timestamp_format` | string | `\w{3}\s+\d{1,2}\s\d{2}:\d{2}:\d{2}` | Regular expression that matches the timestamp of the traditional syslog header. The default matches `Dec 5 10:00:00`. |
|
|
124
128
|
| `cef_version` | integer | `0` | CEF version in the `CEF:<version>` header. |
|
|
125
129
|
| `parse_strict_mode` | bool | `true` | Only treat known CEF keys as keys. See below. |
|
|
126
130
|
| `cef_keyfilename` | string | `config/cef_version_0_keys.yaml` | YAML file with the known CEF keys used in strict mode. Relative paths are resolved from the plugin directory. |
|
|
127
131
|
| `output_raw_field` | bool | `false` | Also add the original line as `raw` when parsing succeeds. |
|
|
132
|
+
| `cef_additional_keys` | array | `[]` | Extra keys treated as known keys in strict mode, e.g. `cef_additional_keys vendorKey1,vendorKey2`. (1.1.0+) |
|
|
133
|
+
| `cef_unescape` | bool | `false` | Handle CEF escape sequences. See below. (1.2.0+) |
|
|
128
134
|
|
|
129
135
|
### Strict mode
|
|
130
136
|
|
|
@@ -139,9 +145,30 @@ cs1=test cs2=foo hoge=fuga cs3=bar
|
|
|
139
145
|
starts a new field, so `cs2` becomes `foo` and an extra `hoge` field with
|
|
140
146
|
`fuga` is added.
|
|
141
147
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
The default key file contains the ArcSight dictionary and the Palo Alto
|
|
149
|
+
Networks PAN-OS keys. In strict mode, other vendor-specific keys are appended
|
|
150
|
+
to the previous value (a key at the start of the extension still becomes a
|
|
151
|
+
field). Add them with `cef_additional_keys`, use your own key file, or set
|
|
152
|
+
`parse_strict_mode false`.
|
|
153
|
+
|
|
154
|
+
### Escape sequences
|
|
155
|
+
|
|
156
|
+
CEF escapes `|` and `\` in header fields, and `=` and `\` in extension
|
|
157
|
+
values, with a backslash, and encodes line breaks in extension values as `\n`
|
|
158
|
+
and `\r`. With `cef_unescape true`:
|
|
159
|
+
|
|
160
|
+
- an escaped `\|` does not end a header field, and an escaped `\=` does not
|
|
161
|
+
start a new key;
|
|
162
|
+
- `\|` and `\\` in header fields, and `\=`, `\\`, `\|`, `\n` and `\r` in
|
|
163
|
+
extension values, are unescaped. Other backslash sequences are kept.
|
|
164
|
+
|
|
165
|
+
For example, `CEF:0|Vend\|or|...|msg=a\=b cs1=C:\\temp` gives
|
|
166
|
+
`cef_device_vendor` = `Vend|or`, `msg` = `a=b` and `cs1` = `C:\temp`.
|
|
167
|
+
|
|
168
|
+
The default is `false`, which keeps the behaviour of 1.1.0 and earlier: escape
|
|
169
|
+
sequences are left in the values, and an escaped `|` or `=` can split fields
|
|
170
|
+
incorrectly. Enable it for new setups; the default may change in a future
|
|
171
|
+
major version.
|
|
145
172
|
|
|
146
173
|
## Development
|
|
147
174
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0
|
|
1
|
+
1.2.0
|
|
@@ -171,3 +171,53 @@ cef_key_names_for_event_consumers:
|
|
|
171
171
|
- sourceZoneExternalID
|
|
172
172
|
- sourceZoneURI
|
|
173
173
|
|
|
174
|
+
# CEF Key Names For Palo Alto Networks PAN-OS
|
|
175
|
+
cef_key_names_for_paloalto:
|
|
176
|
+
- slocation
|
|
177
|
+
- dlocation
|
|
178
|
+
- PanOSPacketsReceived
|
|
179
|
+
- PanOSPacketsSent
|
|
180
|
+
- PanOSThreatCategory
|
|
181
|
+
- PanOSThreatID
|
|
182
|
+
- PanOSThreatName
|
|
183
|
+
- PanOSThreatDomain
|
|
184
|
+
- PanOSSeverity
|
|
185
|
+
- PanOSReferer
|
|
186
|
+
- PanOSURLCatList
|
|
187
|
+
- PanOSLogTimeStamp
|
|
188
|
+
- PanOSVirtualSystem
|
|
189
|
+
- PanOSEventID
|
|
190
|
+
- PanOSStage
|
|
191
|
+
- PanOSAuthMethod
|
|
192
|
+
- PanOSTunnelType
|
|
193
|
+
- PanOSSourceUserName
|
|
194
|
+
- PanOSSourceRegion
|
|
195
|
+
- PanOSEndpointDeviceName
|
|
196
|
+
- PanOSPublicIPv4
|
|
197
|
+
- PanOSPublicIPv6
|
|
198
|
+
- PanOSPrivateIPv4
|
|
199
|
+
- PanOSPrivateIPv6
|
|
200
|
+
- PanOSHostID
|
|
201
|
+
- PanOSDeviceSN
|
|
202
|
+
- PanOSGlobalProtectClientVersion
|
|
203
|
+
- PanOSEndpointOSType
|
|
204
|
+
- PanOSEndpointOSVersion
|
|
205
|
+
- PanOSCountOfRepeats
|
|
206
|
+
- PanOSQuarantineReason
|
|
207
|
+
- PanOSConnectionError
|
|
208
|
+
- PanOSDescription
|
|
209
|
+
- PanOSEventStatus
|
|
210
|
+
- PanOSGPGatewayLocation
|
|
211
|
+
- PanOSLoginDuration
|
|
212
|
+
- PanOSConnectionMethod
|
|
213
|
+
- PanOSConnectionErrorID
|
|
214
|
+
- PanOSPortal
|
|
215
|
+
- PanOSSequenceNo
|
|
216
|
+
- PanOSActionFlags
|
|
217
|
+
- PanOSTimeGeneratedHighResolution
|
|
218
|
+
- PanOSGatewaySelectionType
|
|
219
|
+
- PanOSSSLResponseTime
|
|
220
|
+
- PanOSGatewayPriority
|
|
221
|
+
- PanOSAttemptedGateways
|
|
222
|
+
- PanOSGateway
|
|
223
|
+
- PanOSEndpointDeviceSN
|
|
@@ -16,11 +16,26 @@ module Fluent
|
|
|
16
16
|
config_param :parse_strict_mode, :bool, :default => true
|
|
17
17
|
config_param :cef_keyfilename, :string, :default => 'config/cef_version_0_keys.yaml'
|
|
18
18
|
config_param :output_raw_field, :bool, :default => false
|
|
19
|
+
config_param :cef_additional_keys, :array, :value_type => :string, :default => []
|
|
20
|
+
config_param :cef_unescape, :bool, :default => false
|
|
21
|
+
|
|
22
|
+
CEF_HEADER_FIELDS = %w[
|
|
23
|
+
cef_device_vendor cef_device_product cef_device_version
|
|
24
|
+
cef_device_event_class_id cef_name cef_severity
|
|
25
|
+
].freeze
|
|
19
26
|
|
|
20
27
|
def configure(conf)
|
|
21
28
|
super
|
|
22
|
-
@key_value_format_regexp =
|
|
23
|
-
|
|
29
|
+
@key_value_format_regexp =
|
|
30
|
+
if @cef_unescape
|
|
31
|
+
# Keys cannot contain backslashes, and escape sequences (\\, \=)
|
|
32
|
+
# are consumed as a unit, so an escaped "=" never starts a key. A
|
|
33
|
+
# lone backslash at the very end is kept as part of the value.
|
|
34
|
+
/([^\s=\\]+)=((?:\\.|[^\\]|\\\z)*?)(?:(?=[^\s=\\]+=)|\z)/m
|
|
35
|
+
else
|
|
36
|
+
/([^\s=]+)=(.*?)(?:(?=[^\s=]+=)|\z)/
|
|
37
|
+
end
|
|
38
|
+
@valid_format_regexps = create_valid_format_regexps
|
|
24
39
|
@utc_offset = get_utc_offset(@log_utc_offset)
|
|
25
40
|
begin
|
|
26
41
|
if @parse_strict_mode
|
|
@@ -31,6 +46,7 @@ module Fluent
|
|
|
31
46
|
end
|
|
32
47
|
@keys_array = []
|
|
33
48
|
yaml_fieldinfo.each {|_key, value| @keys_array.concat(value) }
|
|
49
|
+
@keys_array.concat(@cef_additional_keys)
|
|
34
50
|
$log.info "running with strict mode, #{@keys_array.length} keys are valid."
|
|
35
51
|
else
|
|
36
52
|
$log.info "running without strict mode"
|
|
@@ -50,14 +66,23 @@ module Fluent
|
|
|
50
66
|
text.force_encoding("utf-8")
|
|
51
67
|
replaced_text = text.scrub('?')
|
|
52
68
|
record = {}
|
|
53
|
-
record_overview =
|
|
69
|
+
record_overview = nil
|
|
70
|
+
@valid_format_regexps.each do |regexp|
|
|
71
|
+
record_overview = regexp.match(replaced_text)
|
|
72
|
+
break unless record_overview.nil?
|
|
73
|
+
end
|
|
54
74
|
if record_overview.nil?
|
|
55
75
|
yield Engine.now, { "raw" => replaced_text }
|
|
56
76
|
return
|
|
57
77
|
end
|
|
58
|
-
|
|
78
|
+
timestamp = record_overview.names.include?("syslog_timestamp") ? record_overview["syslog_timestamp"] : nil
|
|
79
|
+
time = get_unixtime_with_utc_offset(timestamp, @utc_offset)
|
|
59
80
|
begin
|
|
60
|
-
|
|
81
|
+
# Optional parts that are absent (e.g. <PRI> or the syslog header)
|
|
82
|
+
# are not added to the record.
|
|
83
|
+
record_overview.names.each do |key|
|
|
84
|
+
record[key] = record_overview[key] unless record_overview[key].nil?
|
|
85
|
+
end
|
|
61
86
|
text_cef_extension = record_overview["cef_extension"]
|
|
62
87
|
record.delete("cef_extension")
|
|
63
88
|
rescue
|
|
@@ -68,6 +93,11 @@ module Fluent
|
|
|
68
93
|
record_cef_extension = parse_cef_extension(text_cef_extension)
|
|
69
94
|
record.merge!(record_cef_extension)
|
|
70
95
|
end
|
|
96
|
+
if @cef_unescape
|
|
97
|
+
CEF_HEADER_FIELDS.each do |key|
|
|
98
|
+
record[key] = unescape_cef_header(record[key]) if record.key?(key)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
71
101
|
record["raw"] = replaced_text if @output_raw_field
|
|
72
102
|
yield time, record
|
|
73
103
|
return
|
|
@@ -88,41 +118,62 @@ module Fluent
|
|
|
88
118
|
return utc_offset
|
|
89
119
|
end
|
|
90
120
|
|
|
91
|
-
|
|
121
|
+
# Formats are tried in this order:
|
|
122
|
+
# 1. traditional (RFC 3164 style) syslog header
|
|
123
|
+
# 2. RFC 5424 syslog header
|
|
124
|
+
# 3. no syslog header (the line starts with "CEF:")
|
|
125
|
+
# Each may be preceded by a syslog <PRI> value.
|
|
126
|
+
def create_valid_format_regexps()
|
|
92
127
|
case @log_format
|
|
93
128
|
when "syslog"
|
|
94
|
-
|
|
129
|
+
syslog_pri = /(?:<(?<syslog_pri>\d{1,3})>)?/
|
|
130
|
+
rfc3164_header = /
|
|
95
131
|
(?<syslog_timestamp>#{@syslog_timestamp_format})\s
|
|
96
132
|
(?<syslog_hostname>\S+)\s
|
|
97
133
|
(?<syslog_tag>\S*)\s*
|
|
98
134
|
/x
|
|
135
|
+
rfc5424_header = /
|
|
136
|
+
(?<syslog_version>[1-9]\d{0,2})\s
|
|
137
|
+
(?<syslog_timestamp>\S+)\s
|
|
138
|
+
(?<syslog_hostname>\S+)\s
|
|
139
|
+
(?<syslog_tag>\S+)\s
|
|
140
|
+
(?<syslog_procid>\S+)\s
|
|
141
|
+
(?<syslog_msgid>\S+)\s
|
|
142
|
+
(?<syslog_structured_data>-|(?:\[(?:[^\]\\]|\\.)*\])+)\s
|
|
143
|
+
/x
|
|
144
|
+
# With cef_unescape, "\|" and "\\" inside a header field do not end it.
|
|
145
|
+
field = @cef_unescape ? /(?:\\.|[^|\\])*/ : /[^|]*/
|
|
99
146
|
cef_header = /
|
|
100
147
|
CEF:(?<cef_version>#{@cef_version})\|
|
|
101
|
-
(?<cef_device_vendor
|
|
102
|
-
(?<cef_device_product
|
|
103
|
-
(?<cef_device_version
|
|
104
|
-
(?<cef_device_event_class_id
|
|
105
|
-
(?<cef_name
|
|
106
|
-
(?<cef_severity
|
|
148
|
+
(?<cef_device_vendor>#{field})\|
|
|
149
|
+
(?<cef_device_product>#{field})\|
|
|
150
|
+
(?<cef_device_version>#{field})\|
|
|
151
|
+
(?<cef_device_event_class_id>#{field})\|
|
|
152
|
+
(?<cef_name>#{field})\|
|
|
153
|
+
(?<cef_severity>#{field})
|
|
107
154
|
/x
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
155
|
+
[rfc3164_header, rfc5424_header, nil].map do |syslog_header|
|
|
156
|
+
Regexp.new(/
|
|
157
|
+
\A
|
|
158
|
+
#{syslog_pri}
|
|
159
|
+
#{syslog_header}
|
|
160
|
+
(?:\u{feff})?
|
|
161
|
+
#{cef_header}\|
|
|
162
|
+
(?<cef_extension>.*)
|
|
163
|
+
\z
|
|
164
|
+
/x)
|
|
165
|
+
end
|
|
116
166
|
else
|
|
117
167
|
raise Fluent::ConfigError, "#{@log_format} is unknown format"
|
|
118
168
|
end
|
|
119
|
-
return Regexp.new(valid_format_regexp)
|
|
120
169
|
end
|
|
121
170
|
|
|
122
171
|
def get_unixtime_with_utc_offset(timestamp, utc_offset)
|
|
172
|
+
# No syslog header, or the RFC 5424 NILVALUE
|
|
173
|
+
return Engine.now if timestamp.nil? || timestamp == "-"
|
|
123
174
|
unixtime = nil
|
|
124
175
|
begin
|
|
125
|
-
if timestamp =~ /[-+]\d{2}:?\d{2}\z/
|
|
176
|
+
if timestamp =~ /(?:Z|[-+]\d{2}:?\d{2})\z/
|
|
126
177
|
unixtime = Time.parse(timestamp).to_i
|
|
127
178
|
else
|
|
128
179
|
unixtime = Time.parse("#{timestamp} #{utc_offset}").to_i
|
|
@@ -134,10 +185,31 @@ module Fluent
|
|
|
134
185
|
end
|
|
135
186
|
|
|
136
187
|
def parse_cef_extension(text)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
188
|
+
record =
|
|
189
|
+
if @parse_strict_mode == true
|
|
190
|
+
parse_cef_extension_with_strict_mode(text)
|
|
191
|
+
else
|
|
192
|
+
parse_cef_extension_without_strict_mode(text)
|
|
193
|
+
end
|
|
194
|
+
record.transform_values! { |value| unescape_cef_extension(value) } if @cef_unescape
|
|
195
|
+
record
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# CEF header fields escape "|" and "\" with a backslash.
|
|
199
|
+
def unescape_cef_header(value)
|
|
200
|
+
value.gsub(/\\([|\\])/, '\\1')
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# CEF extension values escape "=" and "\" with a backslash and encode
|
|
204
|
+
# line breaks as \n or \r. An escaped "|" is accepted as well. Other
|
|
205
|
+
# backslash sequences are kept as they are.
|
|
206
|
+
def unescape_cef_extension(value)
|
|
207
|
+
value.gsub(/\\([=\\|nr])/) do
|
|
208
|
+
case $1
|
|
209
|
+
when "n" then "\n"
|
|
210
|
+
when "r" then "\r"
|
|
211
|
+
else $1
|
|
212
|
+
end
|
|
141
213
|
end
|
|
142
214
|
end
|
|
143
215
|
|
|
@@ -146,7 +218,9 @@ module Fluent
|
|
|
146
218
|
begin
|
|
147
219
|
last_valid_key_name = nil
|
|
148
220
|
text.scan(@key_value_format_regexp) do |key, value|
|
|
149
|
-
|
|
221
|
+
# A key that is not in the key list is treated as part of the
|
|
222
|
+
# previous value, unless no known key has been seen yet.
|
|
223
|
+
if @keys_array.include?(key) || last_valid_key_name.nil?
|
|
150
224
|
record[key] = value
|
|
151
225
|
record[last_valid_key_name].rstrip! unless last_valid_key_name.nil?
|
|
152
226
|
last_valid_key_name = key
|
|
@@ -193,7 +193,8 @@ RSpec.describe Fluent::Plugin::CommonEventFormatParser do
|
|
|
193
193
|
"cef_device_version" => "Version",
|
|
194
194
|
"cef_device_event_class_id" => "ID",
|
|
195
195
|
"cef_name" => "Name",
|
|
196
|
-
"cef_severity" => "Severity"
|
|
196
|
+
"cef_severity" => "Severity",
|
|
197
|
+
"foo" => "bar" }]}
|
|
197
198
|
end
|
|
198
199
|
context "timestamp is rfc3339, UTC+3" do
|
|
199
200
|
let (:config) {%[
|
|
@@ -221,7 +222,8 @@ RSpec.describe Fluent::Plugin::CommonEventFormatParser do
|
|
|
221
222
|
"cef_device_version" => "Version",
|
|
222
223
|
"cef_device_event_class_id" => "ID",
|
|
223
224
|
"cef_name" => "Name",
|
|
224
|
-
"cef_severity" => "Severity"
|
|
225
|
+
"cef_severity" => "Severity",
|
|
226
|
+
"foo" => "bar" }]}
|
|
225
227
|
end
|
|
226
228
|
context "timestamp is rfc3339, UTC+0" do
|
|
227
229
|
let (:config) {%[
|
|
@@ -249,7 +251,8 @@ RSpec.describe Fluent::Plugin::CommonEventFormatParser do
|
|
|
249
251
|
"cef_device_version" => "Version",
|
|
250
252
|
"cef_device_event_class_id" => "ID",
|
|
251
253
|
"cef_name" => "Name",
|
|
252
|
-
"cef_severity" => "Severity"
|
|
254
|
+
"cef_severity" => "Severity",
|
|
255
|
+
"foo" => "bar" }]}
|
|
253
256
|
end
|
|
254
257
|
context "utc offset set to +04:00" do
|
|
255
258
|
let (:config) {%[
|
|
@@ -376,5 +379,235 @@ RSpec.describe Fluent::Plugin::CommonEventFormatParser do
|
|
|
376
379
|
"dpt" => "80",
|
|
377
380
|
"msg" => "\xe3\x2e\x2e\x2e".scrub('?') }]}
|
|
378
381
|
end
|
|
382
|
+
|
|
383
|
+
context "other syslog formats" do
|
|
384
|
+
CEF_HEADER_FIELDS = {
|
|
385
|
+
"cef_version" => "0",
|
|
386
|
+
"cef_device_vendor" => "Vendor",
|
|
387
|
+
"cef_device_product" => "Product",
|
|
388
|
+
"cef_device_version" => "Version",
|
|
389
|
+
"cef_device_event_class_id" => "ID",
|
|
390
|
+
"cef_name" => "Name",
|
|
391
|
+
"cef_severity" => "Severity",
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
def parse_text(text, conf = %[log_utc_offset +09:00])
|
|
395
|
+
parsed = nil
|
|
396
|
+
create_driver(conf).instance.parse(text) { |time, record| parsed = [time, record] }
|
|
397
|
+
parsed
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
before :each do
|
|
401
|
+
@now = Fluent::EventTime.now
|
|
402
|
+
allow(Fluent::Engine).to receive(:now).and_return(@now)
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
it "parses a traditional syslog header preceded by <PRI>" do
|
|
406
|
+
time, record = parse_text("<134>Dec 12 10:11:12 hostname tag CEF:0|Vendor|Product|Version|ID|Name|Severity|src=192.0.2.1")
|
|
407
|
+
expect(time).to eq Time.parse("Dec 12 10:11:12 +09:00").to_i
|
|
408
|
+
expect(record).to eq({
|
|
409
|
+
"syslog_pri" => "134",
|
|
410
|
+
"syslog_timestamp" => "Dec 12 10:11:12",
|
|
411
|
+
"syslog_hostname" => "hostname",
|
|
412
|
+
"syslog_tag" => "tag",
|
|
413
|
+
"src" => "192.0.2.1",
|
|
414
|
+
}.merge(CEF_HEADER_FIELDS))
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
it "parses CEF without a syslog header and uses the current time" do
|
|
418
|
+
time, record = parse_text("CEF:0|Vendor|Product|Version|ID|Name|Severity|src=192.0.2.1 act=blocked")
|
|
419
|
+
expect(time).to eq @now
|
|
420
|
+
expect(record).to eq({ "src" => "192.0.2.1", "act" => "blocked" }.merge(CEF_HEADER_FIELDS))
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
it "parses CEF preceded only by <PRI>" do
|
|
424
|
+
time, record = parse_text("<164>CEF:0|Vendor|Product|Version|ID|Name|Severity|src=192.0.2.1")
|
|
425
|
+
expect(time).to eq @now
|
|
426
|
+
expect(record).to eq({ "syslog_pri" => "164", "src" => "192.0.2.1" }.merge(CEF_HEADER_FIELDS))
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
it "parses an RFC 5424 header with NILVALUE fields" do
|
|
430
|
+
time, record = parse_text("<164>1 2024-10-02T14:35:05+02:00 fw1 - - - - CEF:0|Vendor|Product|Version|ID|Name|Severity|src=192.0.2.1 dpt=443")
|
|
431
|
+
expect(time).to eq Time.parse("2024-10-02T14:35:05+02:00").to_i
|
|
432
|
+
expect(record).to eq({
|
|
433
|
+
"syslog_pri" => "164",
|
|
434
|
+
"syslog_version" => "1",
|
|
435
|
+
"syslog_timestamp" => "2024-10-02T14:35:05+02:00",
|
|
436
|
+
"syslog_hostname" => "fw1",
|
|
437
|
+
"syslog_tag" => "-",
|
|
438
|
+
"syslog_procid" => "-",
|
|
439
|
+
"syslog_msgid" => "-",
|
|
440
|
+
"syslog_structured_data" => "-",
|
|
441
|
+
"src" => "192.0.2.1",
|
|
442
|
+
"dpt" => "443",
|
|
443
|
+
}.merge(CEF_HEADER_FIELDS))
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
it "parses an RFC 5424 header with structured data and a UTC timestamp, without <PRI>" do
|
|
447
|
+
text = '1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog 1234 ID47 [exampleSDID@32473 iut="3" eventSource="App\\]lication"][x@1 a="b"] CEF:0|Vendor|Product|Version|ID|Name|Severity|msg=hello'
|
|
448
|
+
time, record = parse_text(text)
|
|
449
|
+
expect(time).to eq Time.parse("2003-10-11T22:14:15.003Z").to_i
|
|
450
|
+
expect(record).to eq({
|
|
451
|
+
"syslog_version" => "1",
|
|
452
|
+
"syslog_timestamp" => "2003-10-11T22:14:15.003Z",
|
|
453
|
+
"syslog_hostname" => "mymachine.example.com",
|
|
454
|
+
"syslog_tag" => "evntslog",
|
|
455
|
+
"syslog_procid" => "1234",
|
|
456
|
+
"syslog_msgid" => "ID47",
|
|
457
|
+
"syslog_structured_data" => '[exampleSDID@32473 iut="3" eventSource="App\\]lication"][x@1 a="b"]',
|
|
458
|
+
"msg" => "hello",
|
|
459
|
+
}.merge(CEF_HEADER_FIELDS))
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
it "uses the current time for an RFC 5424 NILVALUE timestamp" do
|
|
463
|
+
time, record = parse_text("1 - fw1 app - - - CEF:0|Vendor|Product|Version|ID|Name|Severity|src=192.0.2.1")
|
|
464
|
+
expect(time).to eq @now
|
|
465
|
+
expect(record["syslog_timestamp"]).to eq "-"
|
|
466
|
+
expect(record["src"]).to eq "192.0.2.1"
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
it "still emits raw for text that only contains CEF after an unknown prefix" do
|
|
470
|
+
time, record = parse_text("garbage CEF:0|Vendor|Product|Version|ID|Name|Severity|src=192.0.2.1")
|
|
471
|
+
expect(record).to eq({ "raw" => "garbage CEF:0|Vendor|Product|Version|ID|Name|Severity|src=192.0.2.1" })
|
|
472
|
+
end
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
context "strict mode and unknown keys" do
|
|
476
|
+
def parse_extension(extension, conf = "")
|
|
477
|
+
parsed = nil
|
|
478
|
+
create_driver(conf).instance.parse("Dec 12 10:11:12 hostname tag CEF:0|Vendor|Product|Version|ID|Name|Severity|#{extension}") do |_time, record|
|
|
479
|
+
parsed = record.reject { |key, _| key.start_with?("syslog_", "cef_") }
|
|
480
|
+
end
|
|
481
|
+
parsed
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
it "keeps the extension when the first key is unknown" do
|
|
485
|
+
expect(parse_extension("vendorKey=1 src=192.0.2.1 act=blocked")).to eq(
|
|
486
|
+
"vendorKey" => "1", "src" => "192.0.2.1", "act" => "blocked")
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
it "appends unknown keys after a known key to the previous value" do
|
|
490
|
+
expect(parse_extension("src=192.0.2.1 vendorKey=1 act=blocked")).to eq(
|
|
491
|
+
"src" => "192.0.2.1 vendorKey=1", "act" => "blocked")
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
it "treats keys listed in cef_additional_keys as known keys" do
|
|
495
|
+
conf = %[cef_additional_keys vendorKey,otherKey]
|
|
496
|
+
expect(parse_extension("src=192.0.2.1 vendorKey=1 otherKey=a b act=blocked", conf)).to eq(
|
|
497
|
+
"src" => "192.0.2.1", "vendorKey" => "1", "otherKey" => "a b", "act" => "blocked")
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
context "Palo Alto Networks keys" do
|
|
502
|
+
let (:config) {%[
|
|
503
|
+
log_utc_offset +09:00
|
|
504
|
+
]}
|
|
505
|
+
|
|
506
|
+
def parse_paloalto(text)
|
|
507
|
+
parsed = nil
|
|
508
|
+
create_driver(config).instance.parse(text) { |time, record| parsed = [time, record] }
|
|
509
|
+
parsed
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
it "parses a PAN-OS log with an empty extension" do
|
|
513
|
+
time, record = parse_paloalto("Jan 1 00:00:00 Paloalto - CEF:0|Palo Alto Networks|PAN-OS|10.1.8|TRAFFIC|end|0|")
|
|
514
|
+
expect(time).to eq Time.parse("Jan 1 00:00:00 +09:00").to_i
|
|
515
|
+
expect(record).to eq({
|
|
516
|
+
"syslog_timestamp" => "Jan 1 00:00:00",
|
|
517
|
+
"syslog_hostname" => "Paloalto",
|
|
518
|
+
"syslog_tag" => "-",
|
|
519
|
+
"cef_version" => "0",
|
|
520
|
+
"cef_device_vendor" => "Palo Alto Networks",
|
|
521
|
+
"cef_device_product" => "PAN-OS",
|
|
522
|
+
"cef_device_version" => "10.1.8",
|
|
523
|
+
"cef_device_event_class_id" => "TRAFFIC",
|
|
524
|
+
"cef_name" => "end",
|
|
525
|
+
"cef_severity" => "0",
|
|
526
|
+
})
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
it "splits PAN-OS specific keys in strict mode" do
|
|
530
|
+
time, record = parse_paloalto("Jan 1 00:00:00 Paloalto - CEF:0|Palo Alto Networks|PAN-OS|10.1.7|TRAFFIC|start|0|deviceExternalId=000000000000001 PanOSPacketsReceived=0 PanOSPacketsSent=1")
|
|
531
|
+
expect(time).to eq Time.parse("Jan 1 00:00:00 +09:00").to_i
|
|
532
|
+
expect(record).to include(
|
|
533
|
+
"deviceExternalId" => "000000000000001",
|
|
534
|
+
"PanOSPacketsReceived" => "0",
|
|
535
|
+
"PanOSPacketsSent" => "1",
|
|
536
|
+
)
|
|
537
|
+
end
|
|
538
|
+
end
|
|
539
|
+
|
|
540
|
+
context "CEF escape sequences" do
|
|
541
|
+
def parse_cef(text, conf = "")
|
|
542
|
+
parsed = nil
|
|
543
|
+
create_driver(conf).instance.parse(text) { |_time, record| parsed = record }
|
|
544
|
+
parsed
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
let (:header_text) { 'CEF:0|Vend\|or|Prod\\\\uct|1.0|ID|Name|5|src=192.0.2.1' }
|
|
548
|
+
let (:extension_text) { 'CEF:0|V|P|1|1|N|1|msg=a\=b c=d cs1=C:\\\\temp\\\\x cs2=line1\nline2\rend src=192.0.2.1' }
|
|
549
|
+
|
|
550
|
+
context "with cef_unescape false (default)" do
|
|
551
|
+
it "keeps the 1.1.0 behaviour for escaped pipes in the header" do
|
|
552
|
+
record = parse_cef(header_text)
|
|
553
|
+
expect(record["cef_device_vendor"]).to eq 'Vend\\'
|
|
554
|
+
expect(record["cef_device_product"]).to eq 'or'
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
it "keeps escape sequences in extension values" do
|
|
558
|
+
record = parse_cef(extension_text)
|
|
559
|
+
expect(record["msg"]).to eq 'a\=b c=d'
|
|
560
|
+
expect(record["cs1"]).to eq 'C:\\\\temp\\\\x'
|
|
561
|
+
expect(record["cs2"]).to eq 'line1\nline2\rend'
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
context "with cef_unescape true" do
|
|
566
|
+
it "does not split header fields on escaped pipes and unescapes them" do
|
|
567
|
+
record = parse_cef(header_text, %[cef_unescape true])
|
|
568
|
+
expect(record).to include(
|
|
569
|
+
"cef_device_vendor" => "Vend|or",
|
|
570
|
+
"cef_device_product" => 'Prod\\uct',
|
|
571
|
+
"cef_device_version" => "1.0",
|
|
572
|
+
"cef_device_event_class_id" => "ID",
|
|
573
|
+
"cef_name" => "Name",
|
|
574
|
+
"cef_severity" => "5",
|
|
575
|
+
"src" => "192.0.2.1",
|
|
576
|
+
)
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
it "unescapes extension values in strict mode" do
|
|
580
|
+
record = parse_cef(extension_text, %[cef_unescape true])
|
|
581
|
+
expect(record.reject { |key, _| key.start_with?("cef_") }).to eq(
|
|
582
|
+
"msg" => "a=b c=d",
|
|
583
|
+
"cs1" => 'C:\\temp\\x',
|
|
584
|
+
"cs2" => "line1\nline2\rend",
|
|
585
|
+
"src" => "192.0.2.1",
|
|
586
|
+
)
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
it "does not treat an escaped equals sign as a key separator without strict mode" do
|
|
590
|
+
record = parse_cef(extension_text, %[cef_unescape true\nparse_strict_mode false])
|
|
591
|
+
expect(record.reject { |key, _| key.start_with?("cef_") }).to eq(
|
|
592
|
+
"msg" => "a=b",
|
|
593
|
+
"c" => "d",
|
|
594
|
+
"cs1" => 'C:\\temp\\x',
|
|
595
|
+
"cs2" => "line1\nline2\rend",
|
|
596
|
+
"src" => "192.0.2.1",
|
|
597
|
+
)
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
it "unescapes values that absorbed unknown keys in strict mode" do
|
|
601
|
+
record = parse_cef('CEF:0|V|P|1|1|N|1|src=192.0.2.1 vendorKey=a\=b act=x', %[cef_unescape true])
|
|
602
|
+
expect(record["src"]).to eq "192.0.2.1 vendorKey=a=b"
|
|
603
|
+
expect(record["act"]).to eq "x"
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
it "keeps a trailing backslash and unknown escape sequences" do
|
|
607
|
+
record = parse_cef('CEF:0|V|P|1|1|N|1|msg=keep\t end\\', %[cef_unescape true])
|
|
608
|
+
expect(record["msg"]).to eq 'keep\t end\\'
|
|
609
|
+
end
|
|
610
|
+
end
|
|
611
|
+
end
|
|
379
612
|
end
|
|
380
613
|
end
|