Splunk Search

What is the issue with my SPL?

ACyber
Engager

Hi, I am a new Splunk user and this is my first post on the community forum.  If I am not following guidelines please let me know.  I am getting an error for the last line of my search, what is the issue? 

index=web
| eval hash=md5(file)
| stats count by file, hash
| sort - count
| eval bad_hash=case((hash==7bd51c850d0aa1df0a4ad7073aeaadf7), "malicious_file")

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@ACyber 

When posting search fragments, use the code sample button </> 

index=web
| eval hash=md5(file)
| stats count by file, hash
| sort - count
| eval bad_hash=case((hash="7bd51c850d0aa1df0a4ad7073aeaadf7"), "malicious_file")

 You need to wrap your hash in double quotes as you are looking for a string. Without the quotes, Splunk thinks it is a field and because it start with a number, fields containing numbers and odd characters must be wrapped in SINGLE quotes on the right hand side on an eval statement.

So the first one will given an error, the second will compare the hash field against a field called 7bd51c850d0aa1df0a4ad7073aeaadf7 and the last one will compare the hash field against the string 7bd51c850d0aa1df0a4ad7073aeaadf7

| eval bad_hash=case((hash=7bd51c850d0aa1df0a4ad7073aeaadf7), "malicious_file")

| eval bad_hash=case((hash='7bd51c850d0aa1df0a4ad7073aeaadf7'), "malicious_file")

| eval bad_hash=case((hash="7bd51c850d0aa1df0a4ad7073aeaadf7"), "malicious_file")

Note that you do not need double == sign. It's not like a programming language where there is a distinction between equality and assignment.

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

@ACyber 

When posting search fragments, use the code sample button </> 

index=web
| eval hash=md5(file)
| stats count by file, hash
| sort - count
| eval bad_hash=case((hash="7bd51c850d0aa1df0a4ad7073aeaadf7"), "malicious_file")

 You need to wrap your hash in double quotes as you are looking for a string. Without the quotes, Splunk thinks it is a field and because it start with a number, fields containing numbers and odd characters must be wrapped in SINGLE quotes on the right hand side on an eval statement.

So the first one will given an error, the second will compare the hash field against a field called 7bd51c850d0aa1df0a4ad7073aeaadf7 and the last one will compare the hash field against the string 7bd51c850d0aa1df0a4ad7073aeaadf7

| eval bad_hash=case((hash=7bd51c850d0aa1df0a4ad7073aeaadf7), "malicious_file")

| eval bad_hash=case((hash='7bd51c850d0aa1df0a4ad7073aeaadf7'), "malicious_file")

| eval bad_hash=case((hash="7bd51c850d0aa1df0a4ad7073aeaadf7"), "malicious_file")

Note that you do not need double == sign. It's not like a programming language where there is a distinction between equality and assignment.

Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

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

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...