Splunk Search

How to produce a csv based on a complex business logic?

danielbb
Motivator

We have a Splunk UI that allows the users to export a certain set of the rows from a lookup. The caveat is that each row might produce multiple output rows with quite a complex logic.

So, I wonder whether to use the mv set of functions maybe coupled with the map command or to develop a python function to do it.

Any suggestions? 

 

 

Labels (1)
0 Karma
1 Solution

johnhuang
Motivator

Use mvrange to generate a multivalue field with a value for each box, then use mvexpand to create one row for each value.

 

| makeresults | eval events="3,Alan D.,6 Pixel Rd. TX;5,Yusuf A.,11 Apple Ave. FL;3,Michele Y.,9 Monitor Lake IL"
| eval events=split(events, ";") | mvexpand events
| rex field=events "^(?<num_of_boxes>[^\,]*)\,(?<customer_name>[^\,]*)\,(?<address>[^\,]*)"
| eval item_num=mvrange(1, num_of_boxes+1)
| mvexpand item_num
| table num_of_boxes customer_name address item_num

 

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @danielbb,

as @starcher said, I'd use a python script as the last solution to your need, unless you are a super python expert, and probably I'd avoid in every case!

I'd create a search using all your rules and with this search I'd create a report or a dashboard.

Ciao.

Giusppe

0 Karma

danielbb
Motivator

@gcusello @starcher 

Thank you for your feedback.

We have a lookup that has the following data and we present it to our users via a dashboard - 

number of boxes, customer name, address
3	Alan D.		6 Pixel Rd. TX
5	Yusuf A.	11 Apple Ave. FL
3	Michele Y. 	9 Monitor Lake IL

 

The dashboard user will have a button to create an exportable csv. Based on the number of boxes, the exportable csv will have three rows for Alan, five for Yusuf and three for Michele with their addresses.

Can we do it with SPL?

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @danielbb,

you could create a dashboard with a dropdown input that permits to choose the customer_name and then displays the rows of the lookup related to that name.

then you can export it in csv using the export button in Splunk panels or your custom script.

Ciao.

Giuseppe

0 Karma

johnhuang
Motivator

Use mvrange to generate a multivalue field with a value for each box, then use mvexpand to create one row for each value.

 

| makeresults | eval events="3,Alan D.,6 Pixel Rd. TX;5,Yusuf A.,11 Apple Ave. FL;3,Michele Y.,9 Monitor Lake IL"
| eval events=split(events, ";") | mvexpand events
| rex field=events "^(?<num_of_boxes>[^\,]*)\,(?<customer_name>[^\,]*)\,(?<address>[^\,]*)"
| eval item_num=mvrange(1, num_of_boxes+1)
| mvexpand item_num
| table num_of_boxes customer_name address item_num

 

danielbb
Motivator

Thank you @johnhuan - really neat !!!

0 Karma

starcher
Influencer

Use python. Multi value manipulation can be complex and fragile. With various limitations you will find the hard way. 

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...