Dashboards & Visualizations

how to create dynamic csv file from the splunk query

ektasiwani
Communicator

My requirement is to find day wise count of each ip for last 7 days.
and i want to update that csv file automatically each day.
for creating last 7 days ip count i run this query:

sourcetype=xxxxxx action=allowed | timechart span=1d count by src_ip limit=0 | outputcsv test

but i dont want to run same query daily.
i just want to know how to check if today data is there or not, if its not there append that in csv.

or is there any way, splunk can do it by itself. dynamic

Tags (1)
0 Karma

jimodonald
Contributor

You can run the search to be only the previous day and append the results to your CSV. The following search does that by limiting the time range from the previous day starting at midnight (earliest=-1d@d) to midnight last night (latest=@d). The bucket command puts everything into a 1 day time bucket. I'm using chart instead of timechart because this search is only pulling information for 1 day. And finally, the outputcsv is updating the file named test.

sourcetype=xxxxxx action=allowed earliest=-1d@d latest=@d| bucket span=1d _time | chart count by src_ip limit=0 | outputcsv append=true test
0 Karma

SanthoshSreshta
Contributor

How to change the path of the file saving.?

0 Karma

Arun_N_007
Communicator

If you do |inputlookup then it will be stored in lookups folder of the Application.

If you want to write and store it in different location you can write a custom command in Python. Which will write the file in specified location where you can pass the location which you want.

|<custom command> arg1=<location>

In command write normal file operation program which will write output records from previous command to a file.

0 Karma

ektasiwani
Communicator

Thanks jimodonald,

I achieve that by scheduling the search for daily mid night.

0 Karma

krish3
Contributor

Nope. I believe it cannot be changed.

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