Splunk Search

Any idea why eval doesn't assign value

Ruslan
Engager

Query example:

 

 

 

index=eks sourcetype="kube:container" message=log
| fields data.user_agent
| rex field=data.user_agent mode=sed "s/[0-9]//g"
| rex field=data.user_agent mode=sed "s/\.//g"
| eval agent = data.user_agent
| table data.user_agent, agent

 

 

 

After this query `agent` column is empty. While data.user_agent is filled with data.

Was expecting to have a text copy.

Also if will add some logic, based on data.user_agent it will not work for reason as well:

 

 

 

index=eks-prod sourcetype="kube:container:api-auth" message=web_login
| fields data.user_agent
| rex field=data.user_agent mode=sed "s/[0-9]//g"
| rex field=data.user_agent mode=sed "s/\.//g"
| eval agent = if(like(data.user_agent, "Mozilla%"), "browser", "device")
| stats count by agent

 

 

 

this will produce result with always "device", never "browser"

Labels (1)
0 Karma
1 Solution

renjith_nair
Legend

Try

| eval agent = 'data.user_agent'
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

@Ruslan 

In eval statements, always wrap field names that contain anything other than letters with single quotes. Same applies to fields starting with numbers.

 

renjith_nair
Legend

Try

| eval agent = 'data.user_agent'
---
What goes around comes around. If it helps, hit it with Karma 🙂
Get Updates on the Splunk Community!

Splunk Enterprise Security(ES) 7.3 is approaching the end of support. Get ready for ...

Hi friends!    At Splunk, your product success is our top priority. With Enterprise Security (ES), we're here ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...