Splunk Search

confusion with @ symbol

palisetty
Communicator

I know that '@' rounds off to the nearest time. For example, if we have 9:37, shouldn't it round off to 10 instead of 9?

Tags (1)
0 Karma
1 Solution

niketn
Legend

@palisetty again I will recommend you to read about Time Modifiers and snap to time in the Splunk Documentation: https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SearchTimeModifiers#Specify_a_sn...

One of the easiest place to try out an learn about (1) Time Modifiers (2) snap to time and (3) offset is the Advance dialog option within the Time Range Picker provided in the Splunk UI.

For example if current date is 01/02/2020, then -1d@d resolves to 01/01/2020 12:00:00.000 AM. You can always split this and read as minus one day ( i.e. for -1d ) and snap-to the beginning of the day (i.e. for @d ).

alt text

To further add the concept of offset, you can make the next level of adjustment by adding/subtracting offset to this time.

For example -0d@d-1s or simply @d-1s will snap to the beginning of the day yesterday but also subtract 1 second ensuring instead of 12:00 AM for today it will be 11:59:59 for yesterday i.e. 01/01/2020 11:59:59.000 where as -0d@d is 01/02/2019 12:00:00.000.

Hope the above makes sense. Do try out the time modifiers in the Time Range input in Splunk to understand and practice the concept.

You can also try out the following run anywhere example where you need to add the Time Modifier to using relative_time() evaluation function to generate EPOCH time which is converted to string time of format YYYY-MM-DD HH:MM:SS using fieldformat command.

| makeresults
| fields - _time
| eval Time=relative_time(now(),"-1d@d")
| fieldformat Time=strftime(Time,"%Y/%m/%d %H:%M:%S")

If today is 01/02/2020 then following is the output of "-1d@d" in relative_time() function:

Time
2020/01/01 00:00:00
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@palisetty again I will recommend you to read about Time Modifiers and snap to time in the Splunk Documentation: https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SearchTimeModifiers#Specify_a_sn...

One of the easiest place to try out an learn about (1) Time Modifiers (2) snap to time and (3) offset is the Advance dialog option within the Time Range Picker provided in the Splunk UI.

For example if current date is 01/02/2020, then -1d@d resolves to 01/01/2020 12:00:00.000 AM. You can always split this and read as minus one day ( i.e. for -1d ) and snap-to the beginning of the day (i.e. for @d ).

alt text

To further add the concept of offset, you can make the next level of adjustment by adding/subtracting offset to this time.

For example -0d@d-1s or simply @d-1s will snap to the beginning of the day yesterday but also subtract 1 second ensuring instead of 12:00 AM for today it will be 11:59:59 for yesterday i.e. 01/01/2020 11:59:59.000 where as -0d@d is 01/02/2019 12:00:00.000.

Hope the above makes sense. Do try out the time modifiers in the Time Range input in Splunk to understand and practice the concept.

You can also try out the following run anywhere example where you need to add the Time Modifier to using relative_time() evaluation function to generate EPOCH time which is converted to string time of format YYYY-MM-DD HH:MM:SS using fieldformat command.

| makeresults
| fields - _time
| eval Time=relative_time(now(),"-1d@d")
| fieldformat Time=strftime(Time,"%Y/%m/%d %H:%M:%S")

If today is 01/02/2020 then following is the output of "-1d@d" in relative_time() function:

Time
2020/01/01 00:00:00
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

soumyasaha25
Contributor

have a look here, splunk has round, ceil, floor functions that you can use along with eval command to perform rounding.

eg:   ...| eval n=ceil(1.9)

returns n=2

0 Karma

niketn
Legend

@soumyasaha25 I think you missed the question, query was for snapping the time modifier. What you have provided is evaluation ceiling() function for numeric fields not Splunk Time format.

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

palisetty
Communicator

Thank You @soumyasaha25 I am not up to your level, I am just preparing for Fundamental 1 exam.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @palisetty,
@ seems that you around the time period to the unit you add after @:
in other words, -h@h seems the full hout from 00 minute to 59 minute, -h@m arount to the full minute, so at 9.37 seems from 8.37.00.

In your example if you want to take logs at 9.37 from 8.00 to 9.00 you can use earliest=-h@h latest=@h.
At 9.37 you cannot round to 10.00 because it's a future time.

Ciao.
Giuseppe

0 Karma

palisetty
Communicator

@gcusello we will go step by step, please be patient with me.
-h@h means? is it a previous hour?
for example, my current time is 4:56 what would -h@h constitute to?

a week ago @vnravikumar helped me understand -d@d means yesterday, -100d@d is like previous 100 days from today.

I am still stuck with time though.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @palisetty,
No problem, ask what you need and take your times!
So -h@h is the past hour (from 0 to 59 minutes), @h is the start of the present hour.
In your example if you want to take logs at 9.37 from 8.00 to 8.59 you can use earliest=-h@h latest=@h.

Ciao.
Giuseppe

niketn
Legend

@gcusello for snapping to 8:59 the correct time modifier will have snap-to as well as offset i.e.

@h-1s which snaps to 08:59:59, just @h will snap to 09:00:00

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

gcusello
SplunkTrust
SplunkTrust

Hi @palisetty,
As I said at 9.37 from 8.00 to 8.59 you can use earliest=-h@h latest=@h, because you use -h@h and @h for earliest and latest so you can fix the time period in this way, you don't need to use @h-1s for latest.

Ciao.
Giuseppe

palisetty
Communicator

@gcusello So, you are saying, for the example of 9:37, if I say -h@h. @h will be 9 and -h will be from 8:00 to 8:59.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @palisetty,
As I said: -h@h is the past hour (at 9.39 it means 8.00), @h is the start of the present hour (at 9.39 it means 9.00).
Ciao.
Giuseppe

palisetty
Communicator

Perfect. Thank you. @gcusello you are one of the best mentors

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...