Splunk Search

How do I create a host name from two matches with host_regex?

kevlar0
Engager

If I'm gathering data from /data/"folder"/"subfolder" and want to make the host = "folder"-"subfolder", is this possible to do with host_regex?

Obviously I can get "folder" or "subfolder" trivially, but I can't figure out a way to append both of those strings together.

0 Karma
1 Solution

lguinn2
Legend

You can easily get "folder/subfolder", but I don't know how to change the "/" to a "-" in inputs.conf

host_regex = "/data/(.*?/.*?)/"

If you really, really must have a "-", you will have to do it at parsing time on the indexer (or heavy forwarder):

props.conf

[yoursourcetypehere]
TRANSFORMS-rh = rename_host

transforms.conf

[rename_host]
SOURCE_KEY=MetaData:Host
REGEX=(.*?)/(.*)
DEST_KEY=MetaData:Host
FORMAT=host::$1-$2

View solution in original post

lguinn2
Legend

You can easily get "folder/subfolder", but I don't know how to change the "/" to a "-" in inputs.conf

host_regex = "/data/(.*?/.*?)/"

If you really, really must have a "-", you will have to do it at parsing time on the indexer (or heavy forwarder):

props.conf

[yoursourcetypehere]
TRANSFORMS-rh = rename_host

transforms.conf

[rename_host]
SOURCE_KEY=MetaData:Host
REGEX=(.*?)/(.*)
DEST_KEY=MetaData:Host
FORMAT=host::$1-$2

kevlar0
Engager

Thanks! I'd suspected I'd need to use transforms, but was hoping I could still do it with inputs.conf.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...