Splunk Search

collect command/sourcetypes and \ character

bowesmana
SplunkTrust
SplunkTrust

Came across an interesting behaviour with collect today depending on whether you specify a sourcetype or not. If you have a field containing a \ character it will escape the \ when using a sourcetype, but not with stash.

These two searches

 

| makeresults
| eval field="App\X"
| collect index=main sourcetype="something_other_than_stash"

 

 

 

| makeresults
| eval field="App\X"
| collect index=main

 

will generate two different field values in index for 'field'

When using the first with a sourcetype, the resultant field has two \\ characters in the field value in the index.

Both examples show the raw event as App\\X, but fieldsummary shows the one including sourcetype to be App\\\\X

Anyone know why this is?

Labels (1)
Tags (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

OK, so the answer is related to KV_MODE.

With stash, default KV_MODE is none, hence no escaping of the extracted fields is done. With a specified sourcetype the default will be KV_MODE=auto, so the data will be escaped when extracted.

Thanks to firebus on the apac slack channel

Also using KV_MODE=auto_escaped works and that is specifically documented to honour escaped sequences within quoted strings

 

 

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

OK, so the answer is related to KV_MODE.

With stash, default KV_MODE is none, hence no escaping of the extracted fields is done. With a specified sourcetype the default will be KV_MODE=auto, so the data will be escaped when extracted.

Thanks to firebus on the apac slack channel

Also using KV_MODE=auto_escaped works and that is specifically documented to honour escaped sequences within quoted strings

 

 

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...