Splunk Enterprise Security

Calculate MTTA for an analyst

Sai-08
New Member

Hello everyone, 

 

I need help with determining the time needed from an analyst to investigate the alert and close it . 

for more clarity I want to calculate the time spent from when the status_label field value updated from In Progress to (Closed or Resolved )

Hence that the default value of this field in New. 

I am new at splunk so please write full query and I will adjust it for my needs. 

Labels (2)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @Sai-08 ,

You can calculate the average time difference between the "In Progress" status and the "Closed" or "Resolved" status using the stats command.

Here is an example query using makeresults for sample data. Replace the makeresults part with your base search.

| makeresults count=4
| streamstats count as alert_id
| eval _time = case(
    alert_id=1, now() - 3600,
    alert_id=2, now() - 7200,
    alert_id=3, now() - 10800,
    alert_id=4, now() - 14400
    )
| eval status_label="New"
| append [| makeresults count=4 | streamstats count as alert_id | eval _time = case(alert_id=1, now() - 3000, alert_id=2, now() - 6000, alert_id=3, now() - 9000, alert_id=4, now() - 12000) | eval status_label="In Progress"]
| append [| makeresults count=4 | streamstats count as alert_id | eval _time = case(alert_id=1, now() - 600, alert_id=2, now() - 1200, alert_id=3, now() - 1800, alert_id=4, now() - 2400) | eval status_label=if(alert_id%2=0, "Closed", "Resolved")]
| sort 0 _time
``` Replace above makeresults block with your base search: index= sourcetype= status_label IN ("In Progress", "Closed", "Resolved")```
``` Ensure you have a unique identifier for each alert (e.g., alert_id)```

``` Filter for relevant status transitions```
| where status_label IN ("In Progress", "Closed", "Resolved")

``` Capture the timestamp for "In Progress" and "Closed/Resolved" statuses```
| eval in_progress_time = if(status_label="In Progress", _time, null())
| eval closed_resolved_time = if(status_label="Closed" OR status_label="Resolved", _time, null())

``` Group by alert_id and find the earliest "In Progress" time and latest "Closed/Resolved" time```
| stats earliest(in_progress_time) as start_time latest(closed_resolved_time) as end_time by alert_id

``` Filter out alerts that didn't complete the transition or where times are illogical```
| where isnotnull(start_time) AND isnotnull(end_time) AND end_time > start_time

``` Calculate the duration for each alert```
| eval duration_seconds = end_time - start_time

``` Calculate the average duration (MTTM) across all alerts```
| stats avg(duration_seconds) as mttm_seconds

``` Optional: Format the result for readability```
| eval mttm_readable = tostring(mttm_seconds, "duration")
| fields mttm_seconds mttm_readable

livehybrid_0-1743585120817.png

 

 

How it works:

  1. The search first filters events for the relevant statuses ("In Progress", "Closed", "Resolved"). You need a unique field (alert_id in the example) to identify each alert instance.
  2. It uses eval to create fields holding the timestamp (_time) only when the event matches the specific status ("In Progress" or "Closed"/"Resolved").
  3. stats groups the events by alert_id and finds the earliest time the alert was "In Progress" (start_time) and the latest time it was "Closed" or "Resolved" (end_time).
  4. It filters out any alerts that haven't reached a final state or have inconsistent timestamps.
  5. The duration_secondsis calculated for each alert.
  6. Finally, stats calculates the mean time across all valid alert durations.
  7. The result is optionally formatted into a human-readable duration string (e.g., HH:MM:SS).

🌟 Did this answer help you? If so, please consider:

  • Adding kudos to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

0 Karma

Sai-08
New Member

Hey @livehybrid ,

 

Thank you for your time, 

I tried the above query but it didn’t show any results. The unique identifier is event_id and I changed it. 

also I haver replaced with my base search which was

 

‘notable’ 

| search owner_realname= “ analyst name “ 

Please have in mind that I am looking for avg time spent on the alerts , in the past 30 days ( I use the time range ) 

0 Karma

livehybrid
SplunkTrust
SplunkTrust

H i@Sai-08 

Have you been able to identify multiple events in the `notable` response for the same event_id? Can you confirm that you can see the different statuses in the (Closed/Resolved etc)?

This is needed in order to calculate the MTTM however Im not sure the data is in the notable events you're referring to?

🌟 Did this answer help you? If so, please consider:

  • Adding kudos to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing.

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


Introducing Unified TDIR with the New Enterprise Security 8.2

Read the blog
Get Updates on the Splunk Community!

BORE at .conf25

Boss Of Regular Expression (BORE) was an interactive session run again this year at .conf25 by the brilliant ...

OpenTelemetry for Legacy Apps? Yes, You Can!

This article is a follow-up to my previous article posted on the OpenTelemetry Blog, "Your Critical Legacy App ...

UCC Framework: Discover Developer Toolkit for Building Technology Add-ons

The Next-Gen Toolkit for Splunk Technology Add-on Development The Universal Configuration Console (UCC) ...