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.
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
How it works:
🌟 Did this answer help you? If so, please consider:
Your feedback encourages the volunteers in this community to continue contributing
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 )
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:
Your feedback encourages the volunteers in this community to continue contributing.