Splunk Search

Create more efficient "IF"statement that looks at the last 30 days

UMDTERPS
Communicator
| eval nessus = if(like(nessus, "%2019") AND relative_time(now(), "-30d@d") < strptime(nessus,"%m/%d/%Y"), 1, 0)

Above is my current IF statement I use on a daily report. The IF statement looks at the nessus field that has time, checks for 2019 (but within 30days), and gives the the field nessus a 1 if it finds a date less than 30 days (or 0 when it's more than 30 days). BUT the only problem is it only looks at 2019. I can change it to 2020, but the scan results will be zero because there won't be any scans immediately in 2020 (tomorrow). Many of my current dashboard panels will be blank tomorrow if I change it to 2020.

Is there a way to change my IF statement SPL from "2019" to something I don't have to keep changing at the end of the year? (something that will look at 2019, 2020, 2021, etc)

Thanks!

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

If you're only interested in the last 30 days, why check the year at all?

| eval nessus = if(strptime(nessus, "%m/%d/%y") > relative_time(now(), "-30d@d"), 1, 0)
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

If you're only interested in the last 30 days, why check the year at all?

| eval nessus = if(strptime(nessus, "%m/%d/%y") > relative_time(now(), "-30d@d"), 1, 0)
---
If this reply helps you, Karma would be appreciated.
0 Karma

UMDTERPS
Communicator

That works! Thanks! =0)

I see that strptime returns NULL for all malformed values. NULL compared to any number returns false from your eval statement. That's why we used the "If(like)" statement, because we were not sure.

0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...