Splunk Search

Comparing field values(time) with Real Time and display the result

nnimbe
Path Finder

Hi,

One of the field value in splunk is 12/28/2016 15:13:10, i just wanted to compare with realtime and display the results if the value of that field is greater than 24 hours(last 1 day), please let me know how to acheive the same

example:time=12/28/2016 15:13:10, if it is >24hrs(last 1 day) with realtime then display the result

0 Karma
1 Solution

niketn
Legend

@nnimbe...Based on whether your time field is string time or epoch time you would require first eval to convert to epoch time or else not require the first eval with strptime:

<YourBaseSearch>
| eval time=strptime(time,"%m/%d/%Y %H:%M:%S")
| eval duration=(now()-time)/60
| search duration>24

Following is run anywhere example:

| makeresults
| eval time="12/28/2016 15:13:10"
| eval time=strptime(time,"%m/%d/%Y %H:%M:%S")
| eval duration=(now()-time)/60
| search duration>24

You should also explain the scenario to provide some context around your question. The query will perform better if you can perform query filter based on date upfront rather than later.

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

View solution in original post

nnimbe
Path Finder

Thanks @niketnilay , it worked, meanwhile one more query

I am just using metadata command to check the number of hosts and sourcetype, if any new host or sourcetype is added to splunk i want to get alert, how to achieve this using search command (without uploading the csv file and comparing that...i am not looking for this option)

0 Karma

niketn
Legend

@nnimbe...Based on whether your time field is string time or epoch time you would require first eval to convert to epoch time or else not require the first eval with strptime:

<YourBaseSearch>
| eval time=strptime(time,"%m/%d/%Y %H:%M:%S")
| eval duration=(now()-time)/60
| search duration>24

Following is run anywhere example:

| makeresults
| eval time="12/28/2016 15:13:10"
| eval time=strptime(time,"%m/%d/%Y %H:%M:%S")
| eval duration=(now()-time)/60
| search duration>24

You should also explain the scenario to provide some context around your question. The query will perform better if you can perform query filter based on date upfront rather than later.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...