Splunk Search

eval parsing issue?

mwibowo1
New Member

index=xyz CurrentAgentSnapshot.Contacts{}.State=ENDED | table CurrentAgentSnapshot.Contacts{}.StartTime There is no issue with this.
but it gives me error when i try to do eval x = CurrentAgentSnapshot.Contacts{}.StartTime (the error is Error in 'eval' command: The expression is malformed.)

I need to do some calculation using eval on some of the variables CurrentAgentSnapshot.Contacts{}.variables .. such as
eval startTime = strptime(CurrentAgentSnapshot.Contacts{}.StartTime, "%Y-%m-%dT%H:%M:%S.%3N") |
eval endTime = strptime(CurrentAgentSnapshot.Contacts{}.EndTime, "%Y-%m-%dT%H:%M:%S.%3N") |
eval diff = tostring((endTime - startTime), "duration")

Tags (1)
0 Karma

somesoni2
Revered Legend

Your field names contains special characters (dot, curly braces) so you need to enclose them in single quotes when using it on right side of expressions in eval (or in where clause). Try like this

index=xyz CurrentAgentSnapshot.Contacts{}.State=ENDED|
eval startTime = strptime('CurrentAgentSnapshot.Contacts{}.StartTime', "%Y-%m-%dT%H:%M:%S.%3N") |
eval endTime = strptime('CurrentAgentSnapshot.Contacts{}.EndTime', "%Y-%m-%dT%H:%M:%S.%3N") | 
eval diff = tostring((endTime - startTime), "duration") 

mwibowo1
New Member

thanks - that works... also | rename CurrentAgentSnapshot.Contacts{}.StartTime as StartTime works as well (just to share the knowledge)

0 Karma

HiroshiSatoh
Champion

I do not know whether it is a bug or specification
It is a workaround.

Even if you set the field name "{}", "{}" seems to have been deleted, so delete "{}" if you use it with EVAL.
Please do not forget to enclose it with a single quotation.

| makeresults | eval CurrentAgentSnapshot.Contacts{}.StartTime="2018-05-24T01:02:03.004"
| eval startTime = strptime('CurrentAgentSnapshot.Contacts.StartTime', "%Y-%m-%dT%H:%M:%S.%3N")

0 Karma

mwibowo1
New Member

sorry - the workaround does not work... i try to remove the {} but the result does not show up..

0 Karma

HiroshiSatoh
Champion

I fixed the answer. Instead of deleting from the field name, delete it when using it with EVAL.

0 Karma

mwibowo1
New Member

sorry - i cannot delete the {} , the data does not show up.

0 Karma

mwibowo1
New Member

it seems like the eval operation cannot parse the json array {} .. please help

0 Karma
Get Updates on the Splunk Community!

Splunk Platform | Upgrading your Splunk Deployment to Python 3.9

Splunk initially announced the removal of Python 2 during the release of Splunk Enterprise 8.0.0, aiming to ...

From Product Design to User Insights: Boosting App Developer Identity on Splunkbase

co-authored by Yiyun Zhu & Dan Hosaka Engaging with the Community at .conf24 At .conf24, we revitalized the ...

Detect and Resolve Issues in a Kubernetes Environment

We’ve gone through common problems one can encounter in a Kubernetes environment, their impacts, and the ...