Splunk Search

What rex to use for the extraction of virtual from URI?

lbonnes
Observer

These two cells are examples of results I see in IIs logs. 

If the field is just a / (backslash) ( as in the first example data cell ) I want to return just the /. 

If there are characters after the first / (like search in #2) , I need to return the text between the backslashes.  

/
/search/20191108/master.svc

 

My results would look like this. 

field1

root   

search

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This should do it.

| rex "\/(?<field1>[^\/]+)"
| eval field1=if(isnull(field1) OR field1="","root", field1)

  The rex command grabs everything between the first two slashes.  The eval command presumes a missing or empty field1 means the root was specified. 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...