Splunk Search

How to have field populate once

Mary666
Communicator

Hello Splunk Community, 

I have encountered a easy, yet tricky situation. I was told chart command works just like stats, so far I have all the data I need. However, the issue I have is with one field. I need to populate the setting field for the data. I get the setting field to populate, but it shows up 3 different times for each drive - I only need it to show one time. 


 

index="123" sourcekind="Disk Space" count="% Space" dev_team=XYZ  drive="C:" OR drive="E:" OR drive="F:"  | chart values(setting) as setting  sparkline(avg(NET),15m) as NET_value,  latest(NET) as Free over server by drive

 

 

Data I receive:

serversetting:C:setting:E:setting:FFree:C:Free:E:Free:F:Net_Value:C:Net_Value:E:Net_Value:F:
123456TestingTestingTesing23.0024.0034.00\\\

 

Desired results:

serversettingFree:C:Free:EFree:FNet_Value:C:NetValue:E:Net_Value:F
123456Testing23:0024:0034.00\\\



Labels (1)
0 Karma
1 Solution

renjith_nair
Legend

Since the field names are dynamic, try this method

index="123" sourcekind="Disk Space" count="% Space" dev_team=XYZ  drive="C:" OR drive="E:" OR drive="F:"  | chart values(setting) as setting  sparkline(avg(NET),15m) as NET_value,  latest(NET) as Free over server by drive
|eval settings=null()
|foreach settings:* [eval settings=if(isnull(settings),'<<FIELD>>',settings)]|fields - settings:*

 

---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

renjith_nair
Legend

Since the field names are dynamic, try this method

index="123" sourcekind="Disk Space" count="% Space" dev_team=XYZ  drive="C:" OR drive="E:" OR drive="F:"  | chart values(setting) as setting  sparkline(avg(NET),15m) as NET_value,  latest(NET) as Free over server by drive
|eval settings=null()
|foreach settings:* [eval settings=if(isnull(settings),'<<FIELD>>',settings)]|fields - settings:*

 

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

Mary666
Communicator

@renjith_nair  Thanks so much for your help. I would like to know though why you used is null for the eval function and if there is an other way of doing the for each without the null?

|foreach settings:* [eval settings=if(isnull(settings),'<<FIELD>>',settings)]|fields - settings:*

Please advise. 

0 Karma

renjith_nair
Legend

sure. I just initialized the value with null and you can use any value there. It's just for checking that we are storing the value only once i.e when it's empty since all other values are same.

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...