Splunk Search

Searching on fields extracted from Source field

oliverw
New Member

I have multiple application environments on one host, and need to identify the environment based on the directory path in the source log file.

Using a regex in the search works fine, like so

sourcetype="gfstats" | rex field=source "[\w\W/]+/gf-(?<env>[^\.]+)\.log" | search env="app1"

But I would like to define the environment as a field I can use in other searches.

I added a line to props.conf:

EXTRACT-sourcefields = (?<logdir>[\w\W/]+)/gf-(?<environment>[^\.]+)\.log in source

But although I can now see the content of the environment field when I perform searches, I cannot use that field in searches.

sourcetype="gfstats" environment="app1"

returns no results. Why?

Tags (2)
0 Karma

wollinet
Path Finder

You can add the field in fields.conf

[environment] INDEXED = false INDEX_VALUE = false

Settings INDEX_VALUE to false should prevent the search to be expanded to "val" AND fname="val"

0 Karma

dwaddle
SplunkTrust
SplunkTrust

We do practically the same thing for some of our apps. For this to work via props.conf / transforms.conf you have to set up "environment" as an indexed field.

(props.conf)
[mysourcetype]
TRANSFORMS-env=environment

(transforms.conf)
[environment]
SOURCE_KEY=MetaData:Source
REGEX=/path/to/app/([^/]+)/log/.*\.log
FORMAT=environment::$1
WRITE_META=true

This works, but all of the usual caveats related to indexed fields apply. Something just as good might be achievable with eventtypes, but I've not tried it to see.

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

The reason this happens is that a query for fname="val" on an search-time extracted field fname is internally converted to a search for ("val" AND fname="val") which first searches only for events containing the token val in the raw data. Unfortunately, your extracted field is not in the raw data, so the desired events don't come back.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...

Laser Bananas and Edge Hubs: Exploring Operational Technology (OT) Data Through a ...

  OT is a different environment to traditional IT and can have interesting challenges when interfacing the ...

Event Series: Mastering AI Tokenomics and Splunk Agent Observability

Beyond the Black Box: Correlating AI Performance and Tokenomics with Splunk Agent Observability   As ...