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!

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...