Getting Data In

How to load a CSV file into Splunk & Change the csv file dynamically, so that data is refreshed.

alenseb
Communicator

Hi All,

I am trying to load a .csv file into splunk, using sourcetype(csv). Upload of data is working fine but the only issue if i change the data in this .csv file, new data get appended to the old data. what i need is to replace the old with new.
Example: if i have 4 lines in the csv initially & if i delete one of its line and add 2 new lines.
My new csv data should contain only 4 lines.
Right now when i am doing this, i am getting 9 lines(4-Old & 5-New) of data.

Please help me with the configurations.

Tags (2)
1 Solution

Paolo_Prigione
Builder

CSVs the way you mean them are treated in a different way than regular log files.
There are 2 basic kinds:

  1. "just CSVs", which are only accessed via "| inputcsv" and "| outputcsv"
  2. lookup CSVs, which are accessed with commands "| lookup", "| inputlookup" and "| outputlookup"

In the former case you can:

  1. load your CSV in $SPLUNK_HOME/var/run/splunk/filename.csv
  2. execute the search:

    | inputcsv filename.csv

In the latter you can:

  1. configure it from the Manager and upload the csv file
  2. you will be able to replace the file under this directory $SPLUNK_HOME/etc/apps/APPNAME/lookups/filename.csv.
  3. execute searches like:

    .... | lookup configname inputfield OUTPUT outputfield

View solution in original post

Paolo_Prigione
Builder

CSVs the way you mean them are treated in a different way than regular log files.
There are 2 basic kinds:

  1. "just CSVs", which are only accessed via "| inputcsv" and "| outputcsv"
  2. lookup CSVs, which are accessed with commands "| lookup", "| inputlookup" and "| outputlookup"

In the former case you can:

  1. load your CSV in $SPLUNK_HOME/var/run/splunk/filename.csv
  2. execute the search:

    | inputcsv filename.csv

In the latter you can:

  1. configure it from the Manager and upload the csv file
  2. you will be able to replace the file under this directory $SPLUNK_HOME/etc/apps/APPNAME/lookups/filename.csv.
  3. execute searches like:

    .... | lookup configname inputfield OUTPUT outputfield

Paolo_Prigione
Builder

It will probably will be slower than with the "| lookup" command and limited to some 50k results, but | join joinfield [|inputcsv ... | fields + joinfield otherfield] might do

0 Karma

alenseb
Communicator

Thanks!! Appending worked Just fine!

Can i use this "| inputcsv" command to Join with another log file?

0 Karma

MHibbin
Influencer

Do you not want to do this as a lookup?... http://docs.splunk.com/Documentation/Splunk/latest/User/CreateAndConfigureFieldLookups

If not you should be able to use the dedup command to show the latest event (i.e. the latest csv) depending on how you are indexing it.

MHIbbin

0 Karma

alenseb
Communicator

Thanks in advance!!

0 Karma

alenseb
Communicator

I tried the lookup but it didn't serve my purpose since the replacement of data wasn't happening.
Also i need to join this .csv file with another log file.
Therefore wen the data in csv file change, the result of the Join Query also should change.
Any Configuration files i need to look into. I am basically trying to automate it.

0 Karma

jpmackl
New Member

Any luck completing this effort? I'm trying to do the same thing. I have tool the produces a CSV report every hour, I would like to pull the data into Splunk in an automated fashion and then build real time dashboards from the data. Thank you for any help!

0 Karma

colinmchugo
Explorer

Any luck with this jpmackl ? I want to do something similar

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...