Splunk Search

trim everything till refusal reason from the start

man03359
Communicator

Hi,

I am trying to trim everything before the "211 Withdrawal amount exceeded: from the output --

WITHDRAWAL_AMOUNT_EXCEEDED; Refusal Reason: 211 Withdrawal amount exceeded.

But in my logs, at some events Refusal Reason is blank, so in that case I need to trim off the first part.

e.g.,

Validation failed: Total amount is lower than configured min amount. ; Refusal Reason 

MAINTENANCE; Refusal Reason:

 

please help

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You have inconsistently used punctuation so this may not be correct, but hopefully you will get the idea

| rex "(?<reason>(.+(?=; Refusal Reason: $)|(?<=Refusal Reason: ).+))"

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

To trim the event at index-time, use SEDCMD in props.conf

SEDCMD-trimReason = s/.*(; Refusal Reason.*)/\1/

To trim it at search time, try this

| rex mode=sed "s/.*(; Refusal Reason.*)/\1/"
---
If this reply helps you, Karma would be appreciated.
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It is not clear what you are trying to do.

For a field with:

WITHDRAWAL_AMOUNT_EXCEEDED; Refusal Reason: 211 Withdrawal amount exceeded.

are you trying to set it to

211 Withdrawal amount exceeded.

And for a field with

Validation failed: Total amount is lower than configured min amount. ; Refusal Reason 

are you trying to set it to

Refusal Reason 

Or something else?

0 Karma

man03359
Communicator

Yes, correct! 

For a field with:

WITHDRAWAL_AMOUNT_EXCEEDED; Refusal Reason: 211 Withdrawal amount exceeded.

 I am trying to capture 

211 Withdrawal amount exceeded.

and fields with 

And for a field with

Validation failed: Total amount is lower than configured min amount. ; Refusal Reason 

trying to capture 

Validation failed: Total amount is lower than configured min amount. 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You have inconsistently used punctuation so this may not be correct, but hopefully you will get the idea

| rex "(?<reason>(.+(?=; Refusal Reason: $)|(?<=Refusal Reason: ).+))"
0 Karma

man03359
Communicator

Thanks, but it did not worked for me as expected. So I finally used 2 regex to extract both the field values of Message and Refusal Reason into two separate fields.

Happy Splunking 🙂

0 Karma

yuanliu
SplunkTrust
SplunkTrust

In that case, you will need two rex commands to capture them:

| rex "Refusal Reason: *(?<refusal_reason>.+)"
| rex "(?<refusal_reason>.+) *; Refusal Reason$"

The first is anchored against colon (:) which the second event does not contain.  The second is anchored to the end of line after "Refusal Reason" which the first event does not meet. 

Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...