Splunk Enterprise

How to combine two fields if the second field does not equal 0?

snix
Communicator

Okay I have two fields, first one is an error code, example:
ErrorCode_Field = 404

The second field is a sub code of that error code, example:
SubErrorCode_Field = 3

For some reason they entire code is split into two separate fields. I was able to combine the two into a single field to look like this:
FullErrorCode_Field=404.3

Using this code:
eval "FullErrorCode_Field"=ErrorCode_Field . "." . SubErrorCode_Field |

But I would like to put in some kind of "if" statement that says if the SubErrorCode_Field = 0 to not append it or the "." between the split fields to the FullErrorCode_Field. So for example:

if ErrorCode_Field = 404 and SubErrorCode_Field = 3 then FullErrorCode_Field=404.3 but

if ErrorCode_Field = 404 and SubErrorCode_Field = 0 then FullErrorCode_Field=404

0 Karma
1 Solution

somesoni2
Revered Legend

Try like this
fixed typo

your current search | eval "FullErrorCode_Field"=ErrorCode_Field.if(tonumber(SubErrorCode_Field)=0,"",".".SubErrorCode_Field)

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this
fixed typo

your current search | eval "FullErrorCode_Field"=ErrorCode_Field.if(tonumber(SubErrorCode_Field)=0,"",".".SubErrorCode_Field)
0 Karma

snix
Communicator

You the man, that did the trick!

somesoni2
Revered Legend

Thanks @snix for pointing the typo. Corrected the answer.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...