Splunk Search

Using stats and table command

Vig95
Engager

Hi,

I am new to splunk, could you please help me with below SPL, I am trying to use stats and table command

We have 4 entries for same incident, I need to pick earliest time.

Index="monitoring" sourcetype="tool" incident_id=INC* | stats earliest(_time) as early | table "mc_host" "incident_id" "early" | convert ctime(early)

 

I am getting error if execute.

 

 

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Vig95,

the solution is the one hinted by @isoutamo because after a stats command you have only the fields used in the stats command itself, so you have to declare (using e.g. values or earliest) all the fields you need in the following table, that couldn't be necessary if the fields from the stats command are already in the order you want:

index="monitoring" sourcetype="tool" incident_id=INC* 
| stats earliest(_time) as early BY mc_host incident_id
| convert ctime(early)

Ciao.

giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Vig95,

the solution is the one hinted by @isoutamo because after a stats command you have only the fields used in the stats command itself, so you have to declare (using e.g. values or earliest) all the fields you need in the following table, that couldn't be necessary if the fields from the stats command are already in the order you want:

index="monitoring" sourcetype="tool" incident_id=INC* 
| stats earliest(_time) as early BY mc_host incident_id
| convert ctime(early)

Ciao.

giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Vig95 ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

you probably want to see it by inc? If so you could try

Index="monitoring" sourcetype="tool" incident_id=INC* 
| stats min(_time) as _time values(mc_host) as mc_host by incident_id
| table "mc_host" "incident_id" _time

r. Ismo 

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...