Splunk Search

How to get an output containing all host details along with their last update times?

Sangeeta_1
Explorer

How to get an output containing all host details of all time along with their last update times? 

Below search is taking huge time, how to get this optimized for faster search -

index=*| fields host, _time 
| stats max(_time) as last_update_time by host
| eval t=now()
| eval days_since_last_update=tonumber(strftime((t-last_update_time),"%d"))-1 
| where days_since_last_update>30
| eval last_update_time=strftime(last_update_time, "%Y-%m-%d %H:%M:%S") 
| table last_update_time host days_since_last_update

 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

This should be fast enough

| tstats max(_time) AS _time WHERE index=* BY host
| where relative_time(now(), "-30d") > _time
| reltime
| rename reltime as since_last_update
| eval last_update_time = strftime(_time, "%F %T")
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Sangeeta_1 ,

please try this:

| tstats count latest(_time) AS _time WHERE index=* BY host
| table host -time

Ciao.

Giuseppe

Sangeeta_1
Explorer

Thanks @gcusello for the help. But I am getting future dates like below, but the search was for the last time when I am getting any event w.r.t all the host. I have selected date range as all time. Can you please suggest here?

2031-12-11 08:40:08
2025-01-11 09:05:56
2024-10-30 08:12:49
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Sangeeta_1 ,

with my search you should have the latest timestamp for each host, if you have future dates, probably you have some event not correctly parsed because it has future timestamps.

Ciao.

Giuseppe

ITWhisperer
SplunkTrust
SplunkTrust
| metadata type=hosts index=*
0 Karma

Sangeeta_1
Explorer

Hi @ITWhisperer  Thanks for your comment, but metadata contains limited to a certain time in history, like I can get the data for only last 30 days or so.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Does using alltime help?

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!

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 ...