Getting Data In

Multiple sourcetypes in a search?

PHRaymond
Explorer

Just curious, can this search parameter be streamlined at all?

sourcetype=typeone OR sourcetype=typetwo OR sourcetype=typethree OR sourcetype=typefour

I'm just looking for something more elegant, so this isn't critical by any means. I was hoping for something like:

sourcetype=(typeone,typetwo,typethree,typefour)

but no love. Any thoughts?

Thank you.

1 Solution

dwaddle
SplunkTrust
SplunkTrust

There isn't anything directly like that in the search language. For a small set of sourcetypes (or any other field), an OR between each is the best approach. You can encapsulate this inside of a macro to make for less typing.

For a larger set (large enough to be willing to maintain a lookup table), you can emulate this using inputlookup and a subsearch. For example, define a lookup table in $SPLUNK_HOME/etc/system/lookups called many_sourcetypes.csv as follows:

sourcetype
typeone
typetwo
typethree
.
.
.
typefiftyseven

Then, in your search --

[ | inputlookup many_sourcetypes.csv | fields sourcetype ] ...

View solution in original post

mux
Explorer

You can also use tags on the sourcetypes.

tag=yourtagname yousearchhere

and it will search all the sourcetypes with that tag name.

0 Karma

dwaddle
SplunkTrust
SplunkTrust

There isn't anything directly like that in the search language. For a small set of sourcetypes (or any other field), an OR between each is the best approach. You can encapsulate this inside of a macro to make for less typing.

For a larger set (large enough to be willing to maintain a lookup table), you can emulate this using inputlookup and a subsearch. For example, define a lookup table in $SPLUNK_HOME/etc/system/lookups called many_sourcetypes.csv as follows:

sourcetype
typeone
typetwo
typethree
.
.
.
typefiftyseven

Then, in your search --

[ | inputlookup many_sourcetypes.csv | fields sourcetype ] ...

PHRaymond
Explorer

That's pretty much what I figured. Thank you!

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...