Getting Data In

sourcetypes best practice

Branden
Builder

I'm thinking about adding certain application server logs to our Splunk environment. At first, it seemed simple: I would make a file named "appsrv.log" be indexed as sourcetype "appsrv" (or something like that).

The problem is our test host contains several codelines/environments, which means it may have several different, but similarly named appsrv.log files. In a Splunk query, it may be difficult to distinguish which appsrv.log file the results come from unless the user looks at the path of the file itself in the search results. Given how long the path can be, this can be rather annoying.

I'm wondering if it would be better to give a different sourcetype to each codeline. For example: qa-appsrv, test-appsrv, dmo-appsrv.

Does this go against best practice? I'm wondering if anyone has any thoughts on this approach.

Thanks!

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

you may wish instead to create lookup tables against the path of the file, or add a custom indexed field indicating the environment. the lookup table approach is more flexible. basically, you create a CSV that maps the name/path of the file to the "codeline", using wildcard matches if necessary. The file would be something like:

source,codeline
/var/log/blah/*,blah
/var/log/qa/*,qa
/log/some/other/path/appsrv.log,test

the props

[appsrv]
LOOKUP-codeline = sourcecodeline source OUTPUT codeline

and the transforms

[sourcecodeline]
filename = mysourcetocodelinefile.csv
match_type = WILDCARD(source)

if set as an automatic lookup, users will be able to search on the codeline, e.g., using sourcetype=appsrv codeline=qa or similar.

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

you may wish instead to create lookup tables against the path of the file, or add a custom indexed field indicating the environment. the lookup table approach is more flexible. basically, you create a CSV that maps the name/path of the file to the "codeline", using wildcard matches if necessary. The file would be something like:

source,codeline
/var/log/blah/*,blah
/var/log/qa/*,qa
/log/some/other/path/appsrv.log,test

the props

[appsrv]
LOOKUP-codeline = sourcecodeline source OUTPUT codeline

and the transforms

[sourcecodeline]
filename = mysourcetocodelinefile.csv
match_type = WILDCARD(source)

if set as an automatic lookup, users will be able to search on the codeline, e.g., using sourcetype=appsrv codeline=qa or similar.

Branden
Builder

Just tried it. Works great, thanks again! Out of curiosity, where do you typically store your CSVs?

0 Karma

Branden
Builder

Aaah! Good idea, thanks! I like the CSV approach. I think I will give that a try.

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

And you could also set "codeline" in the inputs.conf as an indexed field, by adding: _meta = codeline::qa (for example) to the input stanza for the qa codeline files.

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!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...