Splunk Search

How to populate a dropdown with file extensions extracted from a search?

dreamwork801
Path Finder

I want my users to be able to chose a file extension from a drop down that is populated with a search. I was thinking I could do something that looks for a decimal point like this:

index = git | rex field = Data.payload.head_commit.modified{} max_match=1 "(?<extension>*"."*)" | table extension

But that doesn't work because some of the file addresses have decimal points in them so it would grab an address an not a specific file name.

Some examples:

files/payments/Request.cs
App.files/payments.js
Hello/test.payments/request.xml

And I basically would want the drop down list to populate .cs, .js, .xml and NOT .files/payments.js or NOT .payments/request.xml

Tags (2)
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try this

index = git | rex field = Data.payload.head_commit.modified{} max_match=1 "\w+(?<extension>\.\w+)$" | table extension

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try this

index = git | rex field = Data.payload.head_commit.modified{} max_match=1 "\w+(?<extension>\.\w+)$" | table extension

somesoni2
SplunkTrust
SplunkTrust

For getting all the values matched in a multivalued field, use max_match=0 (for unlimited)

0 Karma

dreamwork801
Path Finder

I want the rex to get all extensions.
Okay will do. Thank you

0 Karma

somesoni2
SplunkTrust
SplunkTrust

If Data.payload.head_commit.modified{} is a multivalued field, do you want the rex to get all the extentions or just the first one?

By the way your approach is good as stats also eliminates duplicates. You might want to get rid of "sort extension" though, stats output will already by sorted by extension.

dreamwork801
Path Finder

That works! Thank you. The only small problem I have is that Data.payload.head_commit.modified{} may have multiple values and so when the rex grabs the extensions it groups them weird. So I have a way around by doing

index = git | rex field=Data.payload.head_commit.modified{} max_match=1 "\w+(?.\w+)$" | stats count by extension | sort extension | fields - count

Because stats pulls out the indivual values instead of leaving them grouped. I didn't know if you knew of a cleaner way to do this. Thanks

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...