i have events that contains a specific field that sometimes contain a very long field which make the rest of the event be truncated, i want to remove this field or change it "long field detected".
the problematic field call "file" and i should catch it's last appearnce, also i want the data after it so i should stop the removal after the first "," (comma). also the event contains nested fields.
i've tried props.conf+transform conf like that:
[APIGW]
TRANSFORMS-replace_long_field = replace_long_field
[replace_long_field]
REGEX = \"file\\\":\s*\"(.{5000,}?),"
FORMAT = file": \"$1long field detected"
DEST_KEY = _raw
but it doesn't work.
here is an example for 1 event:
{"nativeHttpMethod":"POST","apiName":"OT-API","sourceGatewayNode":"10.0.23.27","customFields":{},"origin":null,"sourceGatewayDetails":null,"planName":null,"httpMethod":"post","responseCode":"500","cachedResponse":"Not-Cached","apiVersion":"1.0","messageType":null,"queryParameters":{},"nativeRequestHeaders":{"content-length":"6917","Accept":"*/*","User-Agent":"PostmanRuntime/7.1.5","Postman-Token":"87d68438-4111-4ae6-8171-0fe0d6748e1a","cache-control":"no-cache","accept-encoding":"gzip, deflate","Content-Type":"application/json"},"nativeResponseHeaders":{"Transfer-Encoding":"chunked","Server":"Microsoft-IIS/10.0","Date":"Thu, 01 May 2025 06:16:04 GMT","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},"errorOrigin":"NATIVE","totalDataSize":7051,"planId":null,"nativeRequestPayload":"{\r\n \"mapProfile\": \"ConfirmAbs\",\r\n \"keyMap\": [\r\n {\r\n \"AbsName\": \"מילואים - תעש\",\r\n \"EmployeeNumber\": \"1324332\",\r\n \"Period\": \"1202410\",\r\n \"StartDate\": \"28/10/2024\",\r\n \"EndDate\": \"31/10/2024\",\r\n \"WorkLocation\": \"1רמה\\\"ש חמח\",\r\n \"Secretary\": \"1אדרי טל\",\r\n \"AccumCode\": \"17\"\r\n }\r\n ],\r\n \"fileName\": \"123_4311.pdf\",\r\n \"file\": \"CldoZXJlIGRvZXMgaXQgY29tZSBmcm9tPwpDb250cmFyeSB0byBwb3B1bGFyIGJlbGllZiwgTG9yZW0gSXBzdW0gaXMgbm90IHNpbXBseS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GNhbiBJIGdldCBzb21lPw==\",\r\n \"mapCompany\": \"152\",\r\n \"fileAuthor\": \"ecmuser\",\r\n \"fileType\": \"Document\"\r\n}","nativeResponsePayload":"{\"message\"😕"Failed to make REST call. Type : POST, URL : /v2/nodes, Error : {\\r\\n \\\"error\\\": \\\"An item with the name '123_4311.pdf' already exists.\\\"\\r\\n}\"}","packageName":null,"providerTime":2962,"isCallbackRequest":false,"apiId":"78924a81-0e30-47fb-a512-3f3372333a18","applicationName":"SAG","applicationIp":"10.0.112.240","resPayload":"{\"message\"😕"Failed to make REST call. Type : POST, URL : /v2/nodes, Error : {\\r\\n \\\"error\\\": \\\"An item with the name '123_4311.pdf' already exists.\\\"\\r\\n}\"}","totalTime":2964,"packageId":null,"operationName":"/api/OTFiles/UploadFile","eventType":"Transactional","creationDate":1732704809440,"requestHeaders":{"content-length":"6917","x-Gateway-APIKey":"**************","Accept":"*/*","User-Agent":"PostmanRuntime/7.1.5","Connection":"keep-alive","Postman-Token":"87d68438-4111-4ae6-8171-0fe0d6748e1a","Host":"TINTAPIGW02.elbitsystems.com:5443","cache-control":"no-cache","accept-encoding":"gzip, deflate","Content-Type":"application/json"},"responseHeaders":{"Transfer-Encoding":"chunked","Server":"Microsoft-IIS/10.0","Date":"Thu, 01 May 2025 06:16:04 GMT","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},"sourceGateway":"APIGateway","externalCalls":[{"externalCallType":"NATIVE_SERVICE_CALL","externalURL":"https://twebwses.elbitsystems.com/OT-API/api/OTFiles/UploadFile","callStartTime":1732704809441,"callEndTime":1732704812403,"callDuration":2962,"responseCode":"500"}],"correlationID":"APIGW:8de36863-18bc-4d00-812e-bed164d66a3b:26912","applicationId":"791f2759-d36d-4fd9-9695-e8797a19b990","reqPayload":"{\r\n \"mapProfile\": \"ConfirmAbs\",\r\n \"keyMap\": [\r\n {\r\n \"AbsName\": \"מילואים - תעש\",\r\n \"EmployeeNumber\": \"1324332\",\r\n \"Period\": \"1202410\",\r\n \"StartDate\": \"28/10/2024\",\r\n \"EndDate\": \"31/10/2024\",\r\n \"WorkLocation\": \"1רמה\\\"ש חמח\",\r\n \"Secretary\": \"1אדרי טל\",\r\n \"AccumCode\": \"17\"\r\n }\r\n ],\r\n \"fileName\": \"123_4311.pdf\",\r\n \"file\": \"CldoZXJlIGRvZXMgaXQgY29tZSBmcm9tPwpDb250cmFyeSB0byBwb3B1bGFy
This way you can only (if the regex matches) extract indexed field, not modify the original event (maybe except when you overwrite the _raw event).
You're looking for the SEDCMD functionality. I'd also slightly modify your regex since you're looking for a base64-encoded contents which may not contain neither backslash nor a quote.
SEDCMD-trim-file = s/(\\"file\\":\s*\\")([^\\"]{5000,}?)/\1long_file/g
See it here
https://regex101.com/r/8nX7FY/1
(the regex101 substitution uses a bit different format to SEDCMD - it uses $1 instead of \1)
This way you can only (if the regex matches) extract indexed field, not modify the original event (maybe except when you overwrite the _raw event).
You're looking for the SEDCMD functionality. I'd also slightly modify your regex since you're looking for a base64-encoded contents which may not contain neither backslash nor a quote.
SEDCMD-trim-file = s/(\\"file\\":\s*\\")([^\\"]{5000,}?)/\1long_file/g
See it here
https://regex101.com/r/8nX7FY/1
(the regex101 substitution uses a bit different format to SEDCMD - it uses $1 instead of \1)
is this props.conf/transform.conf command or in splunk command? the goal is to remove/alter the field prior entering it to splunk.
https://docs.splunk.com/Documentation/Splunk/Latest/Admin/Propsconf#Field_extraction_configuration
SEDCMD-<class> = <sed script> * Only used at index time. * Commonly used to anonymize incoming data at index time, such as credit card or social security numbers. For more information, search the online documentation for "anonymize data." * Used to specify a sed script which Splunk software applies to the _raw field. * A sed script is a space-separated list of sed commands. Currently the following subset of sed commands is supported: * replace (s) and character substitution (y). * Syntax: * replace - s/regex/replacement/flags * regex is a perl regular expression (optionally containing capturing groups). * replacement is a string to replace the regex match. Use \n for back references, where "n" is a single digit. * flags can be either: g to replace all matches, or a number to replace a specified match. * substitute - y/string1/string2/ * substitutes the string1[i] with string2[i] * No default.
That's a good direction! unfortunately still not working 100% , i used your code in my props.conf :
[APIGW]
SEDCMD-trim-file = s/(\\"file\\":\s*\\")([^\\"]{5000,}?)/\1long_file/g
and here are the results:
it's like it only replace the 5000 first character instead the entire filed but this is a big step in the right direction thank you for your help!
i will try taking it from here but it will be mostly appreciated if you have the solution in you mind and can share it
EDIT:
From a few tests I've made it stops the field change exactly after 5000 characters instead of running till the first comma / end of field.
EDIT2:
the regex that was needed was:
SEDCMD-trim-file = s/(\\"file\\":\s*\\")([^\\"]{5000,})(\\")/\1long_file/g
but thank you for all the help!
EDIT3:
Well, apparently this solution alone is not enough, I also had to increase the truncate value because when the secmd command run it replaces the string at the end meaning it first recive the default 10,000 characters and only than replace which is not good enough because the final result is still truncated events, i needed to increase truncate value so it will recive the entire event and later on it's doing the replacement.
The REGEX does not match the sample data because backslashes must be escaped. Try
REGEX = \\"file\\":\s*\\"(.{5000,}?),"