Splunk Search

How to use eval to do simple conversion?

Michael
Contributor

Wow, I can't believe this is kicking my butt -- think I need an idiot check... (yes, I know... 😉

I'm trying to do a simple conversion: sizeK=(fileinfo.size/1024) but it's failing. I've done these hundreds of times before, and have it documented in my notes from years ago. Oh, and triple checked it here against multiple examples.

The whole line is simply:

index=suricata event_type=fileinfo| eval sizeK=(fileinfo.size/1024)

It's not creating "sizeK".

When I change to:

| eval sizeK=round(fileinfo.size/1024)

or

| eval sizeK=round(fileinfo.size/1024,2)

I get: "Error in 'eval' command: The arguments to the 'round' function are invalid. "

Even tried:

| eval sizeK=fileinfo.size/1024

Still no workie. Suggestions?

Tags (2)
0 Karma
1 Solution

Vijeta
Influencer

@Michael Try renaming fileinfo.size.

index=suricata event_type=fileinfo| rename fileinfo.size as size |eval sizeK=(size/1024)

View solution in original post

0 Karma

somesoni2
Revered Legend

Your field name contains special character (dot, even hyphen and spaces will cause this) so when referencing it in expression parts (RHS of eval OR in where clause), you need to include it in single quotes, like this:

index=suricata event_type=fileinfo| eval sizeK=('fileinfo.size'/1024)

Without including it in single quotes, the dot is treated as concatenation operator and it's looking for two fields fileinfo and size to concatenate values, and which probably are not available.

0 Karma

Vijeta
Influencer

@Michael Try renaming fileinfo.size.

index=suricata event_type=fileinfo| rename fileinfo.size as size |eval sizeK=(size/1024)
0 Karma

Michael
Contributor

OMG, that fixed it. That was making me nuts!

That's just silly that it can't handle that fieldname (I even tried "fileinfo.size" and 'fileinfo.size').

Thanks!

0 Karma

Vijeta
Influencer

@Michael If it has worked for you, please do accept the answer. Thanks!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...