All Apps and Add-ons

How to remove fields dynamically from a search in Search Log Processing?

DiegoAlba
Explorer

Hello, everyone, I hope you can help me.
My table seems like this:

Name    January February    March   April   May 
Security    8          6                    5           7       
Data    66        77                    86          88      
Logs    76        56                    45          83      

I want to remove May dynamically because May hasn’t already happened
I want to remove the May column dynamically so the “field ” (fields - May) function doesn’t work because it is not dynamic. May is going to happen, what I tried to do and I was looking for is a function to do this.
If a column is null (no data) remove from the table

Can someone of you help me to solve this?

0 Karma

TISKAR
Builder

Hello,

Mr @DiegoAlba, And if you try this,

index=_internal 
| eval date_month=strftime(_time,"%Y-%m-%B")
| chart count by  date_month log_level 
| eval date_month=substr(date_month,9)
| transpose header_field=date_month column_name=log_level

This proposition can sorte the header colulmn ans eleminate the null value

You can juste copied and past this solution, if you have any problème comment this response please

Regards

0 Karma

nryabykh
Path Finder

You can try this:

% your search %
| fields Name 
    [| gentimes start=01/01/18 increment=1d 
    | eval month=strftime(starttime, "%B") 
    | dedup month 
    | stats list(month) as months 
    | nomv months
    | return $months]

But I believe, it's better to remove "May" somewhere before in your search, for example, by checking for nulls or something like that.

0 Karma

DalJeanis
Legend

That looks like the output of a chart command. The manipulation you are trying to do should PROBABLY be done BEFORE running the chart command.

If you post the actual search code, then we can help you do that.

Otherwise, the dynamic presentation of columns with English month names suffers from the problem that @cmerriman noted - they will not sort into the correct order. If you initially created the months as "2018_01 Jan", for example, you could then sort them back and if desired, reformat them back after sorting.

0 Karma

cmerriman
Super Champion

if the entire column is null, you could just do a |stats values(*) as * by Name and it'll only do the values for the fields with data. The only problem is that it will resort it alphanumerically. i'm not sure what the entire search/data looks like, but if you could have the months preceeding with 01-January, for instance, that would sort it properly, and then you could do a rename command in the end to remove the 01- if necessary.

DiegoAlba
Explorer

Hey thank you so much,!

I had the problem you talk about resorting alphanumerically, so i put 01-January as you mentioned

Thanks ;D

0 Karma

somesoni2
Revered Legend

How are you getting the columns names for months? Are you doing some sort of Year to date report?

0 Karma

DiegoAlba
Explorer

i made a chart couting by month, then i renamed them all but i had some problems of sorting so i had to put numbers.

0 Karma

niketn
Legend

@DiegoAlba is this for a report or dashboard? Would it be possible for you to share your query?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

DiegoAlba
Explorer

Thats for a report,, after exclude the column then i had some problems of sorting so i had to renama my columns as 01-january and so on...

than you so much Niketnilay ;D

0 Karma
Get Updates on the Splunk Community!

New Case Study Shows the Value of Partnering with Splunk Academic Alliance

The University of Nevada, Las Vegas (UNLV) is another premier research institution helping to shape the next ...

How to Monitor Google Kubernetes Engine (GKE)

We’ve looked at how to integrate Kubernetes environments with Splunk Observability Cloud, but what about ...

Index This | How can you make 45 using only 4?

October 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...