Skip to content

Commit 73b0ae5

Browse files
fix-parsing-error-due-to-duplicate-fields Don't remove Mesages or Folders field if they have not been renamed
1 parent e045a70 commit 73b0ae5

File tree

2 files changed

+31
-41
lines changed

2 files changed

+31
-41
lines changed

packages/o365/changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
changes:
44
- description: >-
55
Fix flattening errors in `Action` List items due to duplicate `QueryTime` fields by removing duplicate field.
6-
type: bugfix
6+
type: enhancement
77
link: https://github.com/elastic/integrations/pull/15699
88
- description: >-
99
Fixes undefined errors by adding fields `ActorInfoString`, `OperationCount`, `TokenObjectId`, `TokenTenantId`
1010
type: bugfix
1111
link: https://github.com/elastic/integrations/pull/15699
1212
- description: >-
13-
Fixes errors due to SizInBytes fields in `Messages` and `Folders` structures previously imported as long
13+
Fixes errors due to SizeInBytes fields in `Messages` and `Folders` structures previously imported as long
1414
and then being sent as floats. Moves the fields to explicitly defined fields `ExchangeAggregatedMessages` and
1515
`ExchangeAggregatedFolders`and explicitly converts SizeInBytes to long for record type 50: `ExchangeItemAggregated`.
1616
type: bugfix

packages/o365/data_stream/audit/elasticsearch/ingest_pipeline/default.yml

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,15 @@ processors:
132132
if (!(ctx.o365audit.Actions instanceof List)) {
133133
ctx.o365audit.Actions = [ctx.o365audit.Actions];
134134
}
135-
/*
136-
* Actions contains both a human readable `QueryTime` using AM/PM and an ISO8601 format `QueryTime`
137-
* We remove the AM/PM containing `QueryTime` to avoid duplicate field errors on flattening.
138-
*/
139-
def regex = /,"QueryTime":"[0-9\/]+\s[0-9]+:[0-9]+:[0-9]+\s[AP]M"|"QueryTime":"[0-9\/]+\s[0-9]+:[0-9]+:[0-9]+\s[AP]M",/;
135+
136+
// Actions contains both a human readable `QueryTime` using AM/PM and an ISO8601 format `QueryTime`
137+
// We remove the AM/PM containing `QueryTime` to avoid duplicate field errors on flattening.
138+
def queryTimePattern = /,"QueryTime":"[0-9\/]+\s[0-9]+:[0-9]+:[0-9]+\s[AP]M"|"QueryTime":"[0-9\/]+\s[0-9]+:[0-9]+:[0-9]+\s[AP]M",/;
140139
for (def e: ctx.o365audit.Actions) {
141140
if (e instanceof Map) {
142141
actions.add(e);
143142
} else if (e instanceof String) {
144-
ctx._tmp.action_strings.add(regex.matcher(e).replaceAll(''));
143+
ctx._tmp.action_strings.add(queryTimePattern.matcher(e).replaceAll(''));
145144
}
146145
}
147146
if (actions.length == ctx.o365audit.Actions.length) {
@@ -1801,70 +1800,61 @@ processors:
18011800
- append:
18021801
field: event.type
18031802
value: access
1804-
if: ctx.o365audit?.RecordType != null && ctx.o365audit?.RecordType == "50"
1803+
if: ctx.o365audit?.RecordType == "50"
18051804
- append:
18061805
field: event.category
18071806
value: email
1808-
if: ctx.o365audit?.RecordType != null && ctx.o365audit?.RecordType == "50"
1807+
if: ctx.o365audit?.RecordType == "50"
18091808
- rename:
18101809
field: o365audit.Messages
18111810
target_field: o365audit.ExchangeAggregatedMessages
18121811
tag: rename_messages_exchange
1813-
description: 'Move generic Messages field to the ExchangeAggregatedMessages field type'
1814-
if: ctx.o365audit?.Messages != null && ctx.o365audit?.RecordType != null && ctx.o365audit?.RecordType == "50"
1812+
description: 'move generic Messages field to the ExchangeAggregatedMessages field type'
1813+
if: ctx.o365audit?.Messages != null && ctx.o365audit.RecordType == "50"
18151814
- script:
18161815
tag: convert_exchange_message_size_to_long
18171816
if: ctx.o365audit?.ExchangeAggregatedMessages != null
18181817
lang: painless
18191818
source: |
18201819
for (def i = 0; i < ctx.o365audit.ExchangeAggregatedMessages.length; i++) {
1821-
if (ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems != null) {
1822-
for (def j = 0; j < ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems.length; j++) {
1823-
def size = ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems[j].SizeInBytes;
1824-
if (size instanceof String) {
1825-
ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems[j].SizeInBytes = Long.parseLong(size);
1826-
} else {
1827-
ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems[j].SizeInBytes = (long)size;
1828-
}
1820+
if (ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems == null) {
1821+
continue;
1822+
}
1823+
for (def j = 0; j < ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems.length; j++) {
1824+
def size = ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems[j].SizeInBytes;
1825+
if (size instanceof String) {
1826+
ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems[j].SizeInBytes = Long.parseLong(size);
1827+
} else {
1828+
ctx.o365audit.ExchangeAggregatedMessages[i].MessageItems[j].SizeInBytes = (long)size;
18291829
}
18301830
}
18311831
}
18321832
1833-
- remove:
1834-
field: o365audit.Messages
1835-
tag: remove_messages_field
1836-
if: ctx.o365audit?.Messages != null
1837-
description: 'remove o365audit.Messages if we have not explicitly renamed them based on record type'
1838-
18391833
- rename:
18401834
field: o365audit.Folders
18411835
target_field: o365audit.ExchangeAggregatedFolders
18421836
tag: rename_folders_exchange
1843-
description: 'Move generic Folders field to the O365 ExchangeAggregatedFolders field type'
1844-
if: ctx.o365audit?.Folders != null && ctx.o365audit?.RecordType != null && ctx.o365audit?.RecordType == "50"
1837+
description: 'move generic Folders field to the O365 ExchangeAggregatedFolders field type'
1838+
if: ctx.o365audit?.Folders != null && ctx.o365audit.RecordType == "50"
18451839
- script:
18461840
tag: convert_exchange_folder_size_to_long
18471841
if: ctx.o365audit?.ExchangeAggregatedFolders != null
18481842
lang: painless
18491843
source: |
18501844
for (def i = 0; i < ctx.o365audit.ExchangeAggregatedFolders.length; i++) {
1851-
if (ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems != null) {
1852-
for (def j = 0; j < ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems.length; j++) {
1853-
def size = ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems[j].SizeInBytes;
1854-
if (size instanceof String) {
1855-
ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems[j].SizeInBytes = Long.parseLong(size);
1856-
} else {
1857-
ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems[j].SizeInBytes = (long)size;
1858-
}
1845+
if (ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems == null) {
1846+
continue;
1847+
}
1848+
for (def j = 0; j < ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems.length; j++) {
1849+
def size = ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems[j].SizeInBytes;
1850+
if (size instanceof String) {
1851+
ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems[j].SizeInBytes = Long.parseLong(size);
1852+
} else {
1853+
ctx.o365audit.ExchangeAggregatedFolders[i].FolderItems[j].SizeInBytes = (long)size;
18591854
}
18601855
}
18611856
}
18621857
1863-
- remove:
1864-
field: o365audit.Folders
1865-
tag: remove_folders_field
1866-
if: ctx.o365audit?.Folders != null
1867-
description: 'Remove o365audit.Folders if we have not explicitly renamed them based on record type'
18681858
- script:
18691859
description: Handle _tmp.entities.ThreatDetectionMethods containing list of lists.
18701860
lang: painless

0 commit comments

Comments
 (0)