Splunk Search

Using eval with table

asarolkar
Builder

I have a log by the name of auditlog, which logs accountNumber AND accountCreateDt

accountCreateDt = %Y-%m-%d format.

I am trying to identify Accounts that were created less than 24 hours ago by executing this search.

sourcetype="auditlog" | convert timeformat="%Y-%m-%d" mktime(accountCreateDt) as lastTime | convert mktime(_time) as c_time | eval Diff=c_time - lastTime | where Diff < 86400 | table accountNumber 

For some reason, this query is not working.

IF i replace the last query with | table Diff it works like a charm (it gives me all time difference as long as account was created less than 24 hours ago).

Am i not using eval and table correctly ?

0 Karma
1 Solution

lguinn2
Legend

It looks mostly okay, but I think you are doing it the hard way:

sourcetype=auditlog
| eval lastTime = strptime(accountCreateDt,"%Y-%m-%d")
| where lastTime > relative_time(now(), "-24h")
| table accountNumber accountCreateDt

One of the variables that you are using is _time - that is the the timestamp of the event; it will vary with each event. now() is the starting time of the search. I think that now() is what you should be using here, no matter how you choose to calculate things.

View solution in original post

lguinn2
Legend

It looks mostly okay, but I think you are doing it the hard way:

sourcetype=auditlog
| eval lastTime = strptime(accountCreateDt,"%Y-%m-%d")
| where lastTime > relative_time(now(), "-24h")
| table accountNumber accountCreateDt

One of the variables that you are using is _time - that is the the timestamp of the event; it will vary with each event. now() is the starting time of the search. I think that now() is what you should be using here, no matter how you choose to calculate things.

asarolkar
Builder

I like the idea of using now() more than _time.

Also this is a much simpler solution

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...