Getting Data In

dynamically assign sourcetype on folder

fredkaiser
Path Finder

I'll like to assign the sourcetype on the folder the logs are sitting in

What I have

File location pick up by forwarder

C:\Program Files (x86)\License\Current\test\filename.log

props.conf

[source::C:\\Program Files (x86)\\License\\Current\\*\\*.log] 
TRANSFORMS-set_sourcetype = set_sourcetype_from_log_subdir

Transforms.conf

[set_sourcetype_from_log_subdir]
SOURCE_KEY = MetaData:Source
DEST_KEY = MetaData:Sourcetype
REGEX = .+\\(.+)\\[^]*
FORMAT = sourcetype::$1

Splunk Returns sourcetype as filename when index

but I want is the folder not the file name so it should return test

0 Karma
1 Solution

fredkaiser
Path Finder

found the issue was to do with are Props.conf

Props.conf

[source::C:\Program Files (x86)\\Current\\*\\*.log] 

should be

[source::...\\Current\\*\\*.log]

everything else was right.

View solution in original post

0 Karma

fredkaiser
Path Finder

found the issue was to do with are Props.conf

Props.conf

[source::C:\Program Files (x86)\\Current\\*\\*.log] 

should be

[source::...\\Current\\*\\*.log]

everything else was right.

0 Karma

MuS
SplunkTrust
SplunkTrust

Hi fredkeiser,

Your regex is missing the double escaped backslashes and you can test it with Splunk's internal regex functions:

splunk cmd pcregextest test_str="C:\Program Files (x86)\LIC\Current\test\filename.log" mregex=".+\\(.+)\\[^\\]*"
returns:

Original Pattern: '.+\(.+)\[^\]*'
Expanded Pattern: '.+\(.+)\[^\]*'
ERROR: Regex: unmatched parentheses

But if you double escape the backslashes it works:

splunk cmd pcregextest test_str="C:\Program Files (x86)\LIC\Current\test\filename.log" mregex=".+\\\(.+)\\\[^\\\]+"
returns:

Original Pattern: '.+\\(.+)\\[^\\]+'
Expanded Pattern: '.+\\(.+)\\[^\\]+'
Regex compiled successfully. Capture group count = 1. Named capturing groups = 0.
SUCCESS - match against: 'C:\Program Files (x86)\LIC\Current\test\filename.log'

#### Capturing group data ##### 
Group |            Name | Value
--------------------------------------
    1 |                 | test

Hope this helps ...

cheers, MuS

0 Karma

fredkaiser
Path Finder

I'll try that as well and still returns the file name as the sourcetype. even when you test your regex here http://www.regexr.com/ it shows it should work. But for some reason it doesn't work with Splunk

0 Karma

MuS
SplunkTrust
SplunkTrust

Ahh, sorry my bad ! I'll update the answer ....

0 Karma

MuS
SplunkTrust
SplunkTrust

update done

0 Karma

fredkaiser
Path Finder

Thanks for the help MuS

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

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