fluent-plugin-parser_cef 1.0.1 → 1.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 +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +21 -14
- data/VERSION +1 -1
- data/lib/fluent/plugin/config/cef_version_0_keys.yaml +50 -0
- data/lib/fluent/plugin/parser_cef.rb +49 -17
- data/spec/fluent/plugin/parser_cef_spec.rb +163 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0b377ec06f9633e8cec0a789315bd8ad5a659773344d73607897c6b8adc192e6
|
|
4
|
+
data.tar.gz: 52ebe7cebfd303741fd0992dcdaf3df612ce98441ead5b2f9b9eb65ae8182b84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f71acec6579ffae1975da597e62156cd8e522d9cb26316288b9d9b6b33e2f32741edd1498af5baa737b67edfd376541ca077673d8f37c43edf2cc0189009dbf7
|
|
7
|
+
data.tar.gz: 72ae69b82cf81ade1dfc54d6b5175cd133d0320b8e3cf58957be47c533fa9190545efb49d07f4af2d2a7746b6cb705ffd113e0fe8f0e1d445cdf73721c280ff5
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 1.1.0 - 2026-12-05
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Lines with a syslog `<PRI>` value (added as `syslog_pri`), an RFC 5424
|
|
10
|
+
header (adds `syslog_version`, `syslog_procid`, `syslog_msgid` and
|
|
11
|
+
`syslog_structured_data`; APP-NAME goes to `syslog_tag`) or no syslog
|
|
12
|
+
header (starting with `CEF:`) are now parsed instead of being emitted
|
|
13
|
+
as `raw` (#3, #8, #12; based on #4).
|
|
14
|
+
- Palo Alto Networks PAN-OS keys in the default key file (#6, #12).
|
|
15
|
+
- `cef_additional_keys` option to add known keys for strict mode (#12).
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Strict mode: when the first extension key was not a known key, the
|
|
20
|
+
whole extension was dropped. Such a key now becomes a field (#12).
|
|
21
|
+
- Timestamps ending in `Z` are read as UTC (#12).
|
|
22
|
+
|
|
5
23
|
## 1.0.1 - 2026-12-05
|
|
6
24
|
|
|
7
25
|
### 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\|...` | - |
|
|
115
|
+
|
|
116
|
+
The syslog timestamp becomes the event time. Without one (no header, or the
|
|
117
|
+
RFC 5424 `-` NILVALUE) the current time is used.
|
|
113
118
|
|
|
114
|
-
|
|
115
|
-
header are not supported yet and are emitted as `raw`.
|
|
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,12 @@ 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+) |
|
|
128
133
|
|
|
129
134
|
### Strict mode
|
|
130
135
|
|
|
@@ -139,9 +144,11 @@ cs1=test cs2=foo hoge=fuga cs3=bar
|
|
|
139
144
|
starts a new field, so `cs2` becomes `foo` and an extra `hoge` field with
|
|
140
145
|
`fuga` is added.
|
|
141
146
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
The default key file contains the ArcSight dictionary and the Palo Alto
|
|
148
|
+
Networks PAN-OS keys. In strict mode, other vendor-specific keys are appended
|
|
149
|
+
to the previous value (a key at the start of the extension still becomes a
|
|
150
|
+
field). Add them with `cef_additional_keys`, use your own key file, or set
|
|
151
|
+
`parse_strict_mode false`.
|
|
145
152
|
|
|
146
153
|
## Development
|
|
147
154
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0
|
|
1
|
+
1.1.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,12 @@ 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 => []
|
|
19
20
|
|
|
20
21
|
def configure(conf)
|
|
21
22
|
super
|
|
22
23
|
@key_value_format_regexp = /([^\s=]+)=(.*?)(?:(?=[^\s=]+=)|\z)/
|
|
23
|
-
@
|
|
24
|
+
@valid_format_regexps = create_valid_format_regexps
|
|
24
25
|
@utc_offset = get_utc_offset(@log_utc_offset)
|
|
25
26
|
begin
|
|
26
27
|
if @parse_strict_mode
|
|
@@ -31,6 +32,7 @@ module Fluent
|
|
|
31
32
|
end
|
|
32
33
|
@keys_array = []
|
|
33
34
|
yaml_fieldinfo.each {|_key, value| @keys_array.concat(value) }
|
|
35
|
+
@keys_array.concat(@cef_additional_keys)
|
|
34
36
|
$log.info "running with strict mode, #{@keys_array.length} keys are valid."
|
|
35
37
|
else
|
|
36
38
|
$log.info "running without strict mode"
|
|
@@ -50,14 +52,23 @@ module Fluent
|
|
|
50
52
|
text.force_encoding("utf-8")
|
|
51
53
|
replaced_text = text.scrub('?')
|
|
52
54
|
record = {}
|
|
53
|
-
record_overview =
|
|
55
|
+
record_overview = nil
|
|
56
|
+
@valid_format_regexps.each do |regexp|
|
|
57
|
+
record_overview = regexp.match(replaced_text)
|
|
58
|
+
break unless record_overview.nil?
|
|
59
|
+
end
|
|
54
60
|
if record_overview.nil?
|
|
55
61
|
yield Engine.now, { "raw" => replaced_text }
|
|
56
62
|
return
|
|
57
63
|
end
|
|
58
|
-
|
|
64
|
+
timestamp = record_overview.names.include?("syslog_timestamp") ? record_overview["syslog_timestamp"] : nil
|
|
65
|
+
time = get_unixtime_with_utc_offset(timestamp, @utc_offset)
|
|
59
66
|
begin
|
|
60
|
-
|
|
67
|
+
# Optional parts that are absent (e.g. <PRI> or the syslog header)
|
|
68
|
+
# are not added to the record.
|
|
69
|
+
record_overview.names.each do |key|
|
|
70
|
+
record[key] = record_overview[key] unless record_overview[key].nil?
|
|
71
|
+
end
|
|
61
72
|
text_cef_extension = record_overview["cef_extension"]
|
|
62
73
|
record.delete("cef_extension")
|
|
63
74
|
rescue
|
|
@@ -88,14 +99,29 @@ module Fluent
|
|
|
88
99
|
return utc_offset
|
|
89
100
|
end
|
|
90
101
|
|
|
91
|
-
|
|
102
|
+
# Formats are tried in this order:
|
|
103
|
+
# 1. traditional (RFC 3164 style) syslog header
|
|
104
|
+
# 2. RFC 5424 syslog header
|
|
105
|
+
# 3. no syslog header (the line starts with "CEF:")
|
|
106
|
+
# Each may be preceded by a syslog <PRI> value.
|
|
107
|
+
def create_valid_format_regexps()
|
|
92
108
|
case @log_format
|
|
93
109
|
when "syslog"
|
|
94
|
-
|
|
110
|
+
syslog_pri = /(?:<(?<syslog_pri>\d{1,3})>)?/
|
|
111
|
+
rfc3164_header = /
|
|
95
112
|
(?<syslog_timestamp>#{@syslog_timestamp_format})\s
|
|
96
113
|
(?<syslog_hostname>\S+)\s
|
|
97
114
|
(?<syslog_tag>\S*)\s*
|
|
98
115
|
/x
|
|
116
|
+
rfc5424_header = /
|
|
117
|
+
(?<syslog_version>[1-9]\d{0,2})\s
|
|
118
|
+
(?<syslog_timestamp>\S+)\s
|
|
119
|
+
(?<syslog_hostname>\S+)\s
|
|
120
|
+
(?<syslog_tag>\S+)\s
|
|
121
|
+
(?<syslog_procid>\S+)\s
|
|
122
|
+
(?<syslog_msgid>\S+)\s
|
|
123
|
+
(?<syslog_structured_data>-|(?:\[(?:[^\]\\]|\\.)*\])+)\s
|
|
124
|
+
/x
|
|
99
125
|
cef_header = /
|
|
100
126
|
CEF:(?<cef_version>#{@cef_version})\|
|
|
101
127
|
(?<cef_device_vendor>[^|]*)\|
|
|
@@ -105,24 +131,28 @@ module Fluent
|
|
|
105
131
|
(?<cef_name>[^|]*)\|
|
|
106
132
|
(?<cef_severity>[^|]*)
|
|
107
133
|
/x
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
[rfc3164_header, rfc5424_header, nil].map do |syslog_header|
|
|
135
|
+
Regexp.new(/
|
|
136
|
+
\A
|
|
137
|
+
#{syslog_pri}
|
|
138
|
+
#{syslog_header}
|
|
139
|
+
(?:\u{feff})?
|
|
140
|
+
#{cef_header}\|
|
|
141
|
+
(?<cef_extension>.*)
|
|
142
|
+
\z
|
|
143
|
+
/x)
|
|
144
|
+
end
|
|
116
145
|
else
|
|
117
146
|
raise Fluent::ConfigError, "#{@log_format} is unknown format"
|
|
118
147
|
end
|
|
119
|
-
return Regexp.new(valid_format_regexp)
|
|
120
148
|
end
|
|
121
149
|
|
|
122
150
|
def get_unixtime_with_utc_offset(timestamp, utc_offset)
|
|
151
|
+
# No syslog header, or the RFC 5424 NILVALUE
|
|
152
|
+
return Engine.now if timestamp.nil? || timestamp == "-"
|
|
123
153
|
unixtime = nil
|
|
124
154
|
begin
|
|
125
|
-
if timestamp =~ /[-+]\d{2}:?\d{2}\z/
|
|
155
|
+
if timestamp =~ /(?:Z|[-+]\d{2}:?\d{2})\z/
|
|
126
156
|
unixtime = Time.parse(timestamp).to_i
|
|
127
157
|
else
|
|
128
158
|
unixtime = Time.parse("#{timestamp} #{utc_offset}").to_i
|
|
@@ -146,7 +176,9 @@ module Fluent
|
|
|
146
176
|
begin
|
|
147
177
|
last_valid_key_name = nil
|
|
148
178
|
text.scan(@key_value_format_regexp) do |key, value|
|
|
149
|
-
|
|
179
|
+
# A key that is not in the key list is treated as part of the
|
|
180
|
+
# previous value, unless no known key has been seen yet.
|
|
181
|
+
if @keys_array.include?(key) || last_valid_key_name.nil?
|
|
150
182
|
record[key] = value
|
|
151
183
|
record[last_valid_key_name].rstrip! unless last_valid_key_name.nil?
|
|
152
184
|
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,162 @@ 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
|
|
379
539
|
end
|
|
380
540
|
end
|