Splunk Search

How break out user and ip from a single field

omgwut56k
Path Finder

My data for field entity contains either a username or an ip address.

How can make a new field for either user or src_ip?

for example

entity=rhoward
entity=10.0.0.1
entity=192.168.1.1
entity=jbozo

I would like a new field for user and src_ip

Thank you!

Tags (2)
0 Karma
1 Solution

gfuente
Motivator

Hello

You could create two new fields from the entity one, like:

| eval user=if(match(entity, "[a-zA-Z]+"), entity, null) | eval src_ip=if(match(entity, "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"), entity, null)

Regards

View solution in original post

gfuente
Motivator

Hello

You could create two new fields from the entity one, like:

| eval user=if(match(entity, "[a-zA-Z]+"), entity, null) | eval src_ip=if(match(entity, "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"), entity, null)

Regards

gfuente
Motivator

Thanks for the points omgwut56k. If you feel the solution works, please mark it as solved. thanks

0 Karma

omgwut56k
Path Finder

I 'accepted' the answer. Not sure where here to mark it as solved.

0 Karma

nnmiller
Contributor

"Accepted" == solved.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

This is a job for coalesce.

... | eval newField=coalesce(user, src_ip) | ...
---
If this reply helps you, Karma would be appreciated.
0 Karma

omgwut56k
Path Finder

Thank you. However if the field has an ip address I would like that to be expressed src_ip, if it's a user I would like it expressed as user.. Is that possible?

0 Karma
Get Updates on the Splunk Community!

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 ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...