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 Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...