Monitoring Splunk

How to find difference of date in same table as another column?

nikhil29
Loves-to-Learn Everything

I have 1 table having current date when in maintenance and another is last date when it started and looking new value with difference of 2 date without Join.

2022-12-26_18h49_56.png

Labels (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

There is surely more than one approach to this. I'd probably firstly split the date between two different fields

<your search>
| eval maintenance_date=if(role_status="MAINTENANCE_MODE",date,null())
| eval start_date=if(role_status="STARTED",date,null())

Then you can join several rows (depending on your use case it might be with transaction or some stats) and have separate fields on which you can easily calculate difference.

0 Karma

pstout2
Loves-to-Learn

You want to use the delta search command. First, invert the sort order otherwise your maintenance mode entry will have nothing against which it can compare.

This assumes the dates in epoch time as your example suggests.

Then,  use the delta command a=on the date field. Remember, because you inverted the order these numbers will now be negative.

Finally, search for anything older than 2 days (86400s * 2) and not 0. 

Here's a straw man search:

| index=<your_index> sourcetype=<your_sourcetype>
| sort - date
| delta date AS date_diff
| search date_diff < 172800 AND date_diff != 0

 

0 Karma

nikhil29
Loves-to-Learn Everything

I tried your work around but i want services is in maintenance mode from how many days when it was STARTED and then it went to MAINTENANCE_MODE that time difference.

But here first column reflecting blank and days calculating wrong as well

It would be really appreciate if someone can help me please

2023-01-02_18h32_13.png

0 Karma

nikhil29
Loves-to-Learn Everything

I have one more doubt how splunk will and  calculate the date difference if it will sort properly like Maintenance Started alternative.

please see the blow screenshot and help me.

2023-01-02_14h49_41.png

0 Karma

nikhil29
Loves-to-Learn Everything

will not sort alternative*

0 Karma

nikhil29
Loves-to-Learn Everything

Actually I want to know from how long role is in maintenance mode like from last 2 days or more than that.

0 Karma

nikhil29
Loves-to-Learn Everything

Would someone please help me ?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...