Splunk Search

How to extract sourcetype using rex?

splunkuseradmin
Path Finder

Hi everyone,

I have 40 source type with different names so I was wondering if i can extract sourcetype using rex.

abcd2-vooo-abcd05.org.example.com

thanks

1 Solution

woodcock
Esteemed Legend

You are doing it wrong and you are thinking about fixing it wrong. You are bringing these in with the NIX TA and you have not configured it correctly (optimally) so Splunk is guessing at what to use for values for sourcetype. Don't feel bad; there is no documentation on exactly how to do this so we will document it here. The main problem is that you have enabled one of the monitor stanzas but did not set sourcetypes (the default settings do not either). The "normal" way to do this is to put sourcetype=foo underneath the monitor stanza, but in the case of this TA, there are so many different types of files that match each monitor stanza, that the only way to do this would be to break each monitor stanza into many others. Most people take this route, but this is somewhat untidy. What I like to do instead, is put lines like this into props.conf and deploy them in the local directory of the TA to the Forwarders (NOT the Indexers):

[source::...maillog]
sourcetype = maillog
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...httpd_access.log*]
sourcetype = httpd_access
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...syslog*]
sourcetype = syslog
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...cron]
sourcetype = cron
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...rhsm.log]
sourcetype = rhsm

[source::...rhsmcertd.log]
sourcetype = rhsmcertd
#SHOULD_LINEMERGE = false
#EVENT_BREAKER_ENABLE = true

View solution in original post

0 Karma

woodcock
Esteemed Legend

You are doing it wrong and you are thinking about fixing it wrong. You are bringing these in with the NIX TA and you have not configured it correctly (optimally) so Splunk is guessing at what to use for values for sourcetype. Don't feel bad; there is no documentation on exactly how to do this so we will document it here. The main problem is that you have enabled one of the monitor stanzas but did not set sourcetypes (the default settings do not either). The "normal" way to do this is to put sourcetype=foo underneath the monitor stanza, but in the case of this TA, there are so many different types of files that match each monitor stanza, that the only way to do this would be to break each monitor stanza into many others. Most people take this route, but this is somewhat untidy. What I like to do instead, is put lines like this into props.conf and deploy them in the local directory of the TA to the Forwarders (NOT the Indexers):

[source::...maillog]
sourcetype = maillog
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...httpd_access.log*]
sourcetype = httpd_access
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...syslog*]
sourcetype = syslog
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...cron]
sourcetype = cron
SHOULD_LINEMERGE = false
EVENT_BREAKER_ENABLE = true

[source::...rhsm.log]
sourcetype = rhsm

[source::...rhsmcertd.log]
sourcetype = rhsmcertd
#SHOULD_LINEMERGE = false
#EVENT_BREAKER_ENABLE = true
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...