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
Get Updates on the Splunk Community!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...