Splunk Search

How to display default value in rex statements if the value is blank?

manojchacko78
Path Finder

Hi,

I am using the following script in Splunk query. Here i am trying having multiple values in field AdditionalData

and splitting them to extract the fields and writing to separate fields. Now if there is any blank value, in any of these extract fields, i want to have the default value appear as Not Available. 

Thanks in advance

| eval "AddtionalData"=if(isnotnull('cip:AuditMessage.ExtraData'),'cip:AuditMessage.ExtraData',"Not Available")
| rex field=AddtionalData "Legal employer name:(?<LegalEmployerName>[^,]+)"
| rex field=AddtionalData "Legal entity:(?<LegalEntity>[^,]+)"
| rex field=AddtionalData "Country:(?<Country>[^,]+)"
| rex field=AddtionalData "Business unit:(?<BusinessUnit>[^,]+)"

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @manojchacko78,

yu could try fill null:

<your_search>
| eval "AddtionalData"=if(isnotnull('cip:AuditMessage.ExtraData'),'cip:AuditMessage.ExtraData',"Not Available")
| rex field=AddtionalData "Legal employer name:(?<LegalEmployerName>[^,]*)"
| rex field=AddtionalData "Legal entity:(?<LegalEntity>[^,]*)"
| rex field=AddtionalData "Country:(?<Country>[^,]*)"
| rex field=AddtionalData "Business unit:(?<BusinessUnit>[^,]*)"
| fillnull value="Not  Available" LegalEmployerName
| fillnull value="Not  Available" LegalEntity
| fillnull value="Not  Available" Country
| fillnull value="Not  Available" BusinessUnit

remember in your regexes, to use "*" instead "+" when you could have no values.

Ciao.

Giuseppe

View solution in original post

manojchacko78
Path Finder

Thanks a lot @gcusello. You are an angel 🙂

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @manojchacko78,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @manojchacko78,

yu could try fill null:

<your_search>
| eval "AddtionalData"=if(isnotnull('cip:AuditMessage.ExtraData'),'cip:AuditMessage.ExtraData',"Not Available")
| rex field=AddtionalData "Legal employer name:(?<LegalEmployerName>[^,]*)"
| rex field=AddtionalData "Legal entity:(?<LegalEntity>[^,]*)"
| rex field=AddtionalData "Country:(?<Country>[^,]*)"
| rex field=AddtionalData "Business unit:(?<BusinessUnit>[^,]*)"
| fillnull value="Not  Available" LegalEmployerName
| fillnull value="Not  Available" LegalEntity
| fillnull value="Not  Available" Country
| fillnull value="Not  Available" BusinessUnit

remember in your regexes, to use "*" instead "+" when you could have no values.

Ciao.

Giuseppe

Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...