Splunk Search

How to convert 18 character epoch time to format so Splunk understands without thinking events happened in future?

jhampton3rd
Explorer

I have a dashboard that shows the status of certain logs reporting to Splunk. Within this dashboard, it also shows the last time an event was sent. Most of my log sources reports in 12 character Epoch time but I do have a few that reports in 18 character epoch time. For the ones that report in 18 characters, Splunk thinks that these events are happening in the future. Is there a way to fix this so that Splunk understands the 18 characters?

The source for the dashboard is the following:

| metadata index=* type=sourcetypes | stats max(lastTime) as lastEvent by sourcetype | convert ctime(*Event) | search sourcetype!="*too_small"  | search  ( **OMITTED** )   | eval LastEventEpoch = lastEvent | eval lastEventEpoch = strptime('lastEvent', "%m/%d/%Y %H:%M:%S") | eval nowEpoch=now() | eval diff = nowEpoch - lastEventEpoch| eval diff=if(diff>0, diff, 0)  | eval status=case(diff >= 1 AND diff <=1800, "RUNNING", diff > 1801, "DOWN", diff=0, "OFFLINE/EVENT IN THE FUTURE") | sort - status| rename sourcetype AS Sourcetype, lastEvent AS "Last Seen Event", status AS Status | table Sourcetype, "Last Seen Event", Status

Thanks for your help

0 Karma
1 Solution

tmarlette
Motivator

Try using regex to peel out the first 12 digits of your time. something like this:

| rex field=_time "(?<_time>\d{12})"

View solution in original post

tmarlette
Motivator

Try using regex to peel out the first 12 digits of your time. something like this:

| rex field=_time "(?<_time>\d{12})"

jhampton3rd
Explorer

Thanks!!!! This fixed the issue!!!

0 Karma

lukejadamec
Super Champion

Instead of

eval lastEventEpoch = strptime('lastEvent', "%m/%d/%Y %H:%M:%S") 

You might try

eval lastEventEpoch = strptime('lastEvent', "%m/%d/%Y %H:%M:%S") | eval lastEventEpoch_s = strftime(lastEventEpoch, "%s") | eval  lastEventEpoch_rnd = round(lastEventEpoch_s/1000)

Then use the new field lastEventEpoch_rnd in your comparison.
In theory, the strptime will convert the string into a time. The strftime will change the time format to epoch. The round will take the time/1000 and basically remove the microseconds.

0 Karma

jhampton3rd
Explorer

Thanks for your help. Using regex to peel the first 12 characters did the trick.

0 Karma

somesoni2
Revered Legend

Can you post some sample events where you get 18 character epoch timestamp?

0 Karma

jhampton3rd
Explorer

Using regex to strip the first 12 characters fixed the issue. Thanks

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