Splunk Search

Conditional field alias / rename

tmarlette
Motivator

I'm attempting to rename a field of windows data that will be put into a datamodel, however There seems to be a catch. While the sourcetype remains the same for both CPU and Memory, the field 'Value' using perfmon data is consistent.

Here are my two searches, 1 for CPU 1 for memory.

CPU:

index=perfmon tag=process_perf sourcetype="Perfmon:Process counter="% Processor Time"

Memory

 index=perfmon tag=process_perf sourcetype="Perfmon:Process counter="Private Bytes"

With both of these searches, the field Value has the values for each perfmon counter. What i'm trying to do is rename the Value field IFthe counter field is cpu specific. So something like IF counter="% Processor Time" THEN | rename Value as process_cpu. This is to make it generic so I can do the same thing for linux machines with my linux data.

I've looked at EVAL and match but I didn't see a way to recognize a field value, and then change another fields value. Any suggestions are appreciated.

Tags (2)
0 Karma
1 Solution

mayurr98
Super Champion

Try something like this if you want process_cpu field to have only Values of counter="% Processor Time"

<your_base_search> | eval process_cpu=case(counter="% Processor Time",Value)

Let me know if this helps you!

View solution in original post

mayurr98
Super Champion

Try something like this if you want process_cpu field to have only Values of counter="% Processor Time"

<your_base_search> | eval process_cpu=case(counter="% Processor Time",Value)

Let me know if this helps you!

micahkemp
Champion

Maybe:

| eval process_cpu=if(counter="% Processor Time", Value, NULL), Value=if(counter="% Processor Time", NULL, Value)
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 ...