Reporting

use source name as outputcsv filename

ryastrebov
Communicator

Hello!
It is possible? If yes, how this can be done?

Tags (2)
0 Karma
1 Solution

cramasta
Builder

This will output a csv using the source of the data set you are searching against. It should work for both linux and window file paths

index=foo sourcetype=bar | outputcsv [ index=foo sourcetype=bar | head 1| eval search = replace(source, ".*/|.*\\\|\.\w+", "") | fields search]

This example will give you the source file name plus add the current timestamp to the end of the filename

index=foo sourcetype=bar | outputcsv [ index=foo sourcetype=bar | head 1| eval search = replace(source, ".*/|.*\\\|\.\w+", "") | eval search=strftime(now(), search."_%Y%m%d%H%M%S") | fields search]

View solution in original post

ryastrebov
Communicator

Thank you for your comment!

0 Karma

cramasta
Builder

This will output a csv using the source of the data set you are searching against. It should work for both linux and window file paths

index=foo sourcetype=bar | outputcsv [ index=foo sourcetype=bar | head 1| eval search = replace(source, ".*/|.*\\\|\.\w+", "") | fields search]

This example will give you the source file name plus add the current timestamp to the end of the filename

index=foo sourcetype=bar | outputcsv [ index=foo sourcetype=bar | head 1| eval search = replace(source, ".*/|.*\\\|\.\w+", "") | eval search=strftime(now(), search."_%Y%m%d%H%M%S") | fields search]

ryastrebov
Communicator

Thank you, cramasta!
This is exactly what I need!

0 Karma

jonuwz
Influencer

Having dynamic output filenames is possible. I use it to output files with the date. Post an example search since the technique varies. The all use sub searches with "return" though.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...