Splunk Search

Display Dates that Expire in 90 days

jordanking1992
Path Finder

Hello,

We have a field called "Certificate Expiration Date" and trying to only show items that expire 90 days or less. Have tried fieldformat with no luck.

Suggestions?

alt text

0 Karma
1 Solution

jacobpevans
Motivator

Greetings @jordanking1992,

Here's a run-anywhere example:

           | makeresults | eval CertificateExpirationDate =  "9/24/2018 10:00 PM" 
| append [ | makeresults | eval CertificateExpirationDate =  "9/24/2019 10:00 PM" ]
| append [ | makeresults | eval CertificateExpirationDate = "12/20/2019 10:00 PM" ]
| append [ | makeresults | eval CertificateExpirationDate =  "1/10/2020 10:00 PM" ]
| append [ | makeresults | eval CertificateExpirationDate =  "9/24/2020 10:00 PM" ]
| eval  CertificateExpirationDate_epoch = strptime(CertificateExpirationDate, "%m/%d/%Y %I:%M %p")
| where CertificateExpirationDate_epoch < (now() + 90*86400) AND CertificateExpirationDate_epoch > now()
| fields - CertificateExpirationDate_epoch

For your data, it will look more like this:

[your base search]
| eval  CertificateExpirationDate_epoch = strptime('Certificate Expiration Date', "%m/%d/%Y %I:%M %p")
| where CertificateExpirationDate_epoch < (now() + 90*86400)
| fields - CertificateExpirationDate_epoch

If you only want values in the future, add another check for after now()

| where CertificateExpirationDate_epoch < (now() + 90*86400) AND CertificateExpirationDate_epoch > now()
Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.

View solution in original post

jacobpevans
Motivator

Greetings @jordanking1992,

Here's a run-anywhere example:

           | makeresults | eval CertificateExpirationDate =  "9/24/2018 10:00 PM" 
| append [ | makeresults | eval CertificateExpirationDate =  "9/24/2019 10:00 PM" ]
| append [ | makeresults | eval CertificateExpirationDate = "12/20/2019 10:00 PM" ]
| append [ | makeresults | eval CertificateExpirationDate =  "1/10/2020 10:00 PM" ]
| append [ | makeresults | eval CertificateExpirationDate =  "9/24/2020 10:00 PM" ]
| eval  CertificateExpirationDate_epoch = strptime(CertificateExpirationDate, "%m/%d/%Y %I:%M %p")
| where CertificateExpirationDate_epoch < (now() + 90*86400) AND CertificateExpirationDate_epoch > now()
| fields - CertificateExpirationDate_epoch

For your data, it will look more like this:

[your base search]
| eval  CertificateExpirationDate_epoch = strptime('Certificate Expiration Date', "%m/%d/%Y %I:%M %p")
| where CertificateExpirationDate_epoch < (now() + 90*86400)
| fields - CertificateExpirationDate_epoch

If you only want values in the future, add another check for after now()

| where CertificateExpirationDate_epoch < (now() + 90*86400) AND CertificateExpirationDate_epoch > now()
Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

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