Splunk Search

How to check if the field exists and extract the value?

avtandil
Engager

Hi.
I need to use IP Address in iplocation, but O365 returns 2 different logs. one with "ClientIP" field and others with "ClientIPAddress" field.
The issue is that in the logs only one of them exist. If there was null value for one of them, then it would be easy, I would have just checked for null value.

Search looks like this:
mysearch
|eval IPs= if(ClientIP "exists", ClientIP, ClientIPAddress)
|iplocation IPs
|stats ...

I can't do the "ClientIP exists" part. maybe this is not correct and other approach should be used. Does anyone know the solution?

0 Karma
1 Solution

horsefez
Motivator

Hi @avtandil,

there is a SPL function called isnull() and isnotnull() you can use these together with the if function to check if fields/fieldvalues exist or not.

A solution to your problem could look like this:

| eval IP=if(isnotnull(ClientIP), ClientIP, ClientIPAddress)

View solution in original post

horsefez
Motivator

Hi @avtandil,

there is a SPL function called isnull() and isnotnull() you can use these together with the if function to check if fields/fieldvalues exist or not.

A solution to your problem could look like this:

| eval IP=if(isnotnull(ClientIP), ClientIP, ClientIPAddress)

avtandil
Engager

Hi pyro_wood.

Thanks, I tried that yesterday and did not worked.

At last, I found that I had a fault in dedup function, it was not the eval function that was not working.

Thanks again.

0 Karma
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 ...