-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathincident_and_milestone_durations.liquid
46 lines (33 loc) · 1.87 KB
/
incident_and_milestone_durations.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{% comment %}
Description: Return the current total duration of the incident. Add this to other runbook steps to include the duration in your messaging.
Runbook Step:'Notify channel with a custom message' or 'Notify incident channel with a custom message'
Conditions to trigger: Milestone changes, Time since Milestone or whatever is useful for the desired outcome.
{% endcomment %}
{% assign started = incident.milestones | where: "type", "started" | first %}
{% assign started_at = started.occurred_at | date: "%s" %}
{% assign resolved = incident.milestones | where: "type", "resolved" | first %}
{% if resolved %}
{% assign resolved_at_or_now = resolved.occurred_at | date: "%s" %}
{% else %}
{% assign resolved_at_or_now = "now" | date: "%s" %}
{% endif %}
{% assign SECONDS_PER_MINUTE = 60 %}
{% assign SECONDS_PER_HOUR = SECONDS_PER_MINUTE | times: 60 %}
{% assign SECONDS_PER_DAY = SECONDS_PER_HOUR | times: 24 %}
{% assign remainder = resolved_at_or_now | minus: started_at | modulo: SECONDS_PER_DAY %}
{% assign days = resolved_at_or_now | minus: started_at | divided_by: SECONDS_PER_DAY | floor %}
{% assign hours = remainder | divided_by: SECONDS_PER_HOUR | floor %}
{% assign remainder = remainder | modulo: SECONDS_PER_HOUR %}
{% assign minutes = remainder | divided_by: SECONDS_PER_MINUTE | floor %}
{% assign seconds = remainder | modulo: SECONDS_PER_MINUTE %}
This incident has been active for {{ days }}d {{ hours }}h {{ minutes }}m {{ seconds }}s
{% comment %}
Description: Return the and type, duration for each milestone.
Runbook Step:'Notify channel with a custom message' or 'Notify incident channel with a custom message'
Conditions to trigger: Milestone is 'Resolved'
{% endcomment %}
{% for milestone in incident.milestones %}
Type: {{ milestone.type }}
Duration: {{ milestone.duration }}
####################
{% endfor %}