Getting Data In

How to upload multiple XML files and have the sourcetype be defined as the name of the file automatically?

ektasiwani
Communicator

Hi,

I have a folder with 10 XML files and it can be more in the future.
My requirement is to upload this file, and the sourcetype name should be equal to name of file.
I want everything to be automatic.
For that, do I need to use a python script or can it be done by Splunk?
Is there any tutorial link for creating a sourcetype and uploading the file through a python script?

Thanks.

0 Karma
1 Solution

woodcock
Esteemed Legend

You can do it in Splunk by using props.conf and transforms.conf like this (be sure not to set a sourcetype= in your inputs.conf😞

#props.conf:
[source::<your stuff here>]
TRANSFORMS-sourcetypeSetFromFilename=sourcetypeSetFromFilename

Then

#transforms.conf:
[sourcetypeSetFromFilename]
SOURCE_KEY = MetaData:Source
REGEX = <your RegEx here with one capture group>
FORMAT = sourcetype::$1
DEST_KEY = MetaData:Sourcetype

View solution in original post

0 Karma

woodcock
Esteemed Legend

You can do it in Splunk by using props.conf and transforms.conf like this (be sure not to set a sourcetype= in your inputs.conf😞

#props.conf:
[source::<your stuff here>]
TRANSFORMS-sourcetypeSetFromFilename=sourcetypeSetFromFilename

Then

#transforms.conf:
[sourcetypeSetFromFilename]
SOURCE_KEY = MetaData:Source
REGEX = <your RegEx here with one capture group>
FORMAT = sourcetype::$1
DEST_KEY = MetaData:Sourcetype
0 Karma

ektasiwani
Communicator

Hi,

I am getting it.
here is my pros file

My files are in splunk-input fiolder in local computer.

props.conf:

[source::/opt/splunk-input/]
TRANSFORMS-sourcetypeSetFromFilename=sourcetypeSetFromFilename

here is my transform file

#transforms.conf:
[sourcetypeSetFromFilename]
SOURCE_KEY = MetaData:Source
REGEX = .\/(.)
FORMAT = sourcetype::$1
DEST_KEY = MetaData:Sourcetype

i copied both files in splunk/etc/system/local folder

And i am uploading files through setting->data->new
and for sourcetype i selected automatic.

0 Karma

woodcock
Esteemed Legend

I don't think it will work with [source::/opt/splunk-input/]; you need to use something with wildcards like [source::/opt/splunk-input/*], otherwise it will not match any of your sources. Other than that, it should work, once you bounce your forwarders.

0 Karma

ektasiwani
Communicator

Thanx for rply,

That regex in transforms.conf is to set the name of sourcetype? or for something else?

And if i will upload a folder with all the file through settings-->data input , sourcetype will be equal to folder name and one for all the files? or each file will have there sourcetype?

for example i have file 1 , file 2, file 3 in a folder name file. my requirement is to have three sourcetype with name file 1, file2, file 3.
but dont want to upload each file one by one.

0 Karma

woodcock
Esteemed Legend

Right, if you need to use the filename as the sourcetype, you use a RegEx like this:

 REGEX = .*\/(.*)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...