Getting Data In

How do I configure my sourcetype to deal with a log that creates events with fixed field lengths?

andrewtrobec
Motivator

Hello all,

I have a structured log that doesn't contain a headers but contains fields with a fixed lengths. Here is a simplified example that considers 4 fields with names exit_code, id, description, and timestamp:

3 40023452 This is the description that gets trunca 2019-31-10 11:01:00
3 40016468 Shorter description no truncation        2019-31-10 11:02:00
3 40045418                                          2019-31-10 11:03:00

The samples above shows that all fields are fixed length even when they don't have values:

  • exit_code is always 1 character from columns 1 to 2
  • id is always 8 characters from columns 3 to 11
  • description is always 40 characters from columns 12 to 52
  • timestamp is always 19 characters from columns 53 to 72

With this in mind, is there any way in props.conf to specify the column ranges that define the fields? If not, is there a combination of props.conf and transforms.conf that will allow me to do this, maybe using regular expressions?

Any suggestions would be greatly appreciated!

Thank you and best regards,

Andrew

0 Karma

richgalloway
SplunkTrust
SplunkTrust

This regex works with your sample data. Test it in search to verify it works.

(?<exit_code>\d+)\s+(?<id>\d+)\s(?<description>.{40})\s(?<timestamp>.*)

Put it into your transforms.conf like this:

[foo]
REGEX = (\d+)\s+(\d+)\s(.{40})\s(*)
FORMAT = exit_code::$1 id::$2 description::$3 timestamp::$4

---
If this reply helps you, Karma would be appreciated.
0 Karma

andrewtrobec
Motivator

@richgalloway Thanks Rich! Follow-up questions: must the stanza in trasforms.conf have the same name as the stanza in props.conf? Also. must I update props.conf with some sort of parameter so that it refers to transforms.conf?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The props and transforms stanza names do not have to match and usually don't.
Reference the transform from props like this:

[mysourcetype]
TRANSFORMS-sometext = foo
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

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, ...