Splunk Search

How to make the time readable in stats latest(_time)?

yshen
Communicator

By the following query, I can list the hosts status and when they have their status change:

 

index=snmptrapd 
| table _time Agent_Hostname alertStatus_1

 

with this query the _time values are readable as for example, 

2020-08-19 21:07:50

However, when I only want to find the latest time when a host has a certain status, by the following query,

 

index=snmptrapd 
| stats latest(_time) by Agent_Hostname alertStatus_1

 

then 

Agent_Hostname alertStatus_1 latest(_time)

l18-tempmoncritical1597896470
l20-tempmoncritical1597901380
l20-tempmonnormal1597891753

 

How can I make the field for latest(_time) still readable as before?

Labels (1)
Tags (2)
0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

Hi

_time is some kind of special that it shows it's value "correctly" without any helps. On all other time fields which has value as unix epoch you must convert those to human readable form. One way to do it is 

index=snmptrapd 
| stats latest(_time)as latestTime by Agent_Hostname alertStatus_1
| eval latestTime = strftime(latestTime, "%F %T")

You could found more about working with time fields

r. Ismo

View solution in original post

altink
Builder

can anyone advise on this ?

regards
Altin

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

_time is some kind of special that it shows it's value "correctly" without any helps. On all other time fields which has value as unix epoch you must convert those to human readable form. One way to do it is 

index=snmptrapd 
| stats latest(_time)as latestTime by Agent_Hostname alertStatus_1
| eval latestTime = strftime(latestTime, "%F %T")

You could found more about working with time fields

r. Ismo

altink
Builder

Hi

I think I am doing the same thing, but it does not work for me

 

https://community.splunk.com/t5/Dashboards-Visualizations/strftime-empties-stats-ed-field/m-p/530449...

best
Altin

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...