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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...