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!

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

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...