Splunk Search

Add and remove text from a field at extraction time

splunkmasterfle
Path Finder

Hi,

Is there a way to add text to a field that matches a specific pattern?

Example:

log:

2014-09-12 13:40:12,359 "GET /app/rest/1.0/payableinvoicelink/100-129880-2fc616a5-33d5-4567-9abf-71b1234a3d36 HTTP/1.1"

What I would like to have:

requestType: "GET /app/rest/1.0/payableinvoicelink/getById"

Another example:

log:
2014-09-12 13:40:12,359 "GET /app/rest/1.0/application/674536 HTTP/1.1"

What I would like to have:

requestType: "GET /app/rest/1.0/application/getById"

Is there an elegant way of achieving this?

Thanks!

0 Karma

lguinn2
Legend

A SEARCH time solution (or two)

Option 1: Use the replace command (documentation here.) This works great if you only have a few changes to make, and if you only want to do it for a single report.

Option 2: Use an automatic lookup. This allows you to create an entirely new field. You can have both the new field and the original field. A lookup table can contain thousands of values and is easier than a series of replacements. If you set up the lookup as automatic, the new field will always be present.

Use field lookups is a tutorial that uses the Splunk UI. I recommend it.

0 Karma

lguinn2
Legend

An INDEX time solution - which means that all of your data would need to be reindexed. Also, the original value would be gone...

In the Splunk manuals, there is a section called Anonymize data, which shows how to replace certain patterns in your input with "XXXX" or "####". Follow those instructions, but use "getById" (or whatever you want) instead of "XXX".

Example 1 (using transforms.conf)

[fix-application]
REGEX = (.*?)GET /app/rest/1.0/application/674536 HTTP/1.1(.*)
FORMAT = $1GET /app/rest/1.0/application/getById$2
DEST_KEY = _raw

Example 2 (using only props.conf)

SEDCMD-fix2 = s/(GET \/app\/rest\/1.0\/payableinvoicelink\/)100-129880-2fc616a5-33d5-4567-9abf-71b1234a3d36 HTTP\/1.1\/\1 getById/

Note that I had to escape the / in the second example, which makes it a bit harder to read

0 Karma

lguinn2
Legend

Ah, good point, all of this is at index time. Another answer follows for how to do it at search time.

0 Karma

splunkmasterfle
Path Finder

Does this work at index time? Meaning I have to re-import all of my data ?

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!

Unlocking Unified Insights: New Gigamon Federated Search App for Splunk

In today’s data-heavy environment, organizations are caught in a data distribution dilemma. As data volumes ...

GA: New Data Management App in Splunk Platform

Streamlining Data Management: Introducing a unified experience in Splunk Managing data at scale shouldn’t feel ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...