Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.3.115 #4139

Merged
merged 8 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev/helm-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ env:
value: "False"
- name: FEATURE_PROMETHEUS_EXPORTER_ENABLED
value: "True"
# enabled to be able to test docker.host.internal in the webhook e2e tests
- name: DANGEROUS_WEBHOOKS_ENABLED
value: "True"
image:
repository: localhost:63628/oncall/engine
tag: dev
Expand Down
4 changes: 2 additions & 2 deletions docs/sources/oncall-api-reference/escalation_policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ The above command returns JSON structured in the following way:
| ---------------------------------- | :--------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `escalation_chain_id` | Yes | Each escalation policy is assigned to a specific escalation chain. |
| `position` | Optional | Escalation policies execute one after another starting from `position=0`. `Position=-1` will put the escalation policy to the end of the list. A new escalation policy created with a position of an existing escalation policy will move the old one (and all following) down in the list. |
| `type` | Yes | One of: `wait`, `notify_persons`, `notify_person_next_each_time`, `notify_on_call_from_schedule`, `notify_user_group`, `trigger_action`, `resolve`, `notify_whole_channel`, `notify_if_time_from_to`. |
| `type` | Yes | One of: `wait`, `notify_persons`, `notify_person_next_each_time`, `notify_on_call_from_schedule`, `notify_user_group`, `trigger_webhook`, `resolve`, `notify_whole_channel`, `notify_if_time_from_to`. |
| `important` | Optional | Default is `false`. Will assign "important" to personal notification rules if `true`. This can be used to distinguish alerts on which you want to be notified immediately by phone. Applicable for types `notify_persons`, `notify_team_members`, `notify_on_call_from_schedule`, and `notify_user_group`. |
| `duration` | If type = `wait` | The duration, in seconds, when type `wait` is chosen. Valid values are: `60`, `300`, `900`, `1800`, `3600`. |
| `action_to_trigger` | If type = `trigger_action` | ID of a webhook. |
| `action_to_trigger` | If type = `trigger_webhook` | ID of a webhook. |
| `group_to_notify` | If type = `notify_user_group` | ID of a `User Group`. |
| `persons_to_notify` | If type = `notify_persons` | List of user IDs. |
| `persons_to_notify_next_each_time` | If type = `notify_person_next_each_time` | List of user IDs. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,62 +42,6 @@ def build_raw_escalation_snapshot(self) -> dict:
"""
Builds new escalation chain in a json serializable format (dict).
Use this method to prepare escalation chain data for saving to alert group before start new escalation.

Example result:
{
'channel_filter_snapshot': {
'id': 1,
'notify_in_slack': True,
'str_for_clients': 'default',
'notify_in_telegram': True
},
'escalation_chain_snapshot': {
'id': 1,
'name': 'Test'
},
'escalation_policies_snapshots': [
{
'id': 1,
'step': 14,
'order': 0,
'to_time': None,
'from_time': None,
'num_alerts_in_window': None,
'num_minutes_in_window': None,
'wait_delay': None,
'notify_schedule': None,
'notify_to_group': None,
'notify_to_team_members': None,
'passed_last_time': None,
'escalation_counter': 0,
'last_notified_user': None,
'custom_button_trigger': None,
'notify_to_users_queue': [1,2,3]
},
{
'id': 2,
'step': 0,
'order': 1,
'to_time': None,
'from_time': None,
'num_alerts_in_window': None,
'num_minutes_in_window': None,
'wait_delay': '00:05:00',
'notify_schedule': None,
'notify_to_group': None,
'notify_to_team_members': None,
'passed_last_time': None,
'escalation_counter': 0,
'last_notified_user': None,
'custom_button_trigger': None,
'notify_to_users_queue': []
},
],
'slack_channel_id': 'SLACK_CHANNEL_ID',
'last_active_escalation_policy_order': None,
'pause_escalation': False,
'next_step_eta': '2021-10-18T10:28:28.890369Z
}
"""
data = {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework import serializers

from apps.alerts.models.custom_button import CustomButton
from apps.alerts.models.escalation_policy import EscalationPolicy
from apps.schedules.models import OnCallSchedule
from apps.user_management.models import User
Expand Down Expand Up @@ -58,7 +57,6 @@ class EscalationPolicySnapshotSerializer(serializers.ModelSerializer):
)
escalation_counter = serializers.IntegerField(default=0)
passed_last_time = serializers.DateTimeField(allow_null=True, default=None)
custom_button_trigger = PrimaryKeyRelatedFieldWithNoneValue(allow_null=True, queryset=CustomButton.objects)
custom_webhook = PrimaryKeyRelatedFieldWithNoneValue(allow_null=True, queryset=Webhook.objects, default=None)
notify_schedule = PrimaryKeyRelatedFieldWithNoneValue(allow_null=True, queryset=OnCallSchedule.objects)
num_alerts_in_window = serializers.IntegerField(allow_null=True, default=None)
Expand All @@ -79,7 +77,6 @@ class Meta:
"to_time",
"num_alerts_in_window",
"num_minutes_in_window",
"custom_button_trigger",
"custom_webhook",
"notify_schedule",
"notify_to_group",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from apps.alerts.models.alert_group_log_record import AlertGroupLogRecord
from apps.alerts.models.escalation_policy import EscalationPolicy
from apps.alerts.tasks import (
custom_button_result,
custom_webhook_result,
notify_all_task,
notify_group_task,
Expand All @@ -37,7 +36,6 @@ class EscalationPolicySnapshot:
"to_time",
"num_alerts_in_window",
"num_minutes_in_window",
"custom_button_trigger",
"custom_webhook",
"notify_schedule",
"notify_to_group",
Expand Down Expand Up @@ -66,7 +64,6 @@ def __init__(
to_time,
num_alerts_in_window,
num_minutes_in_window,
custom_button_trigger,
custom_webhook,
notify_schedule,
notify_to_group,
Expand All @@ -85,7 +82,6 @@ def __init__(
self.to_time = to_time
self.num_alerts_in_window = num_alerts_in_window
self.num_minutes_in_window = num_minutes_in_window
self.custom_button_trigger = custom_button_trigger
self.custom_webhook = custom_webhook
self.notify_schedule = notify_schedule
self.notify_to_group = notify_to_group
Expand Down Expand Up @@ -131,7 +127,6 @@ def execute(self, alert_group: "AlertGroup", reason) -> StepExecutionResultData:
EscalationPolicy.STEP_NOTIFY_TEAM_MEMBERS_IMPORTANT: self._escalation_step_notify_team_members,
EscalationPolicy.STEP_NOTIFY_SCHEDULE: self._escalation_step_notify_on_call_schedule,
EscalationPolicy.STEP_NOTIFY_SCHEDULE_IMPORTANT: self._escalation_step_notify_on_call_schedule,
EscalationPolicy.STEP_TRIGGER_CUSTOM_BUTTON: self._escalation_step_trigger_custom_button,
EscalationPolicy.STEP_TRIGGER_CUSTOM_WEBHOOK: self._escalation_step_trigger_custom_webhook,
EscalationPolicy.STEP_NOTIFY_USERS_QUEUE: self._escalation_step_notify_users_queue,
EscalationPolicy.STEP_NOTIFY_IF_TIME: self._escalation_step_notify_if_time,
Expand Down Expand Up @@ -474,29 +469,6 @@ def _escalation_step_notify_if_num_alerts_in_time_window(
return self._get_result_tuple(pause_escalation=True)
return None

def _escalation_step_trigger_custom_button(self, alert_group: "AlertGroup", _reason: str) -> None:
tasks = []
custom_button = self.custom_button_trigger
if custom_button is not None:
custom_button_task = custom_button_result.signature(
(custom_button.pk, alert_group.pk),
{
"escalation_policy_pk": self.id,
},
immutable=True,
)
tasks.append(custom_button_task)
else:
log_record = AlertGroupLogRecord(
type=AlertGroupLogRecord.TYPE_ESCALATION_FAILED,
alert_group=alert_group,
escalation_policy=self.escalation_policy,
escalation_error_code=AlertGroupLogRecord.ERROR_ESCALATION_TRIGGER_CUSTOM_BUTTON_STEP_IS_NOT_CONFIGURED,
escalation_policy_step=self.step,
)
log_record.save()
self._execute_tasks(tasks)

def _escalation_step_trigger_custom_webhook(self, alert_group: "AlertGroup", _reason: str) -> None:
tasks = []
webhook = self.custom_webhook
Expand All @@ -514,7 +486,7 @@ def _escalation_step_trigger_custom_webhook(self, alert_group: "AlertGroup", _re
type=AlertGroupLogRecord.TYPE_ESCALATION_FAILED,
alert_group=alert_group,
escalation_policy=self.escalation_policy,
escalation_error_code=AlertGroupLogRecord.ERROR_ESCALATION_TRIGGER_CUSTOM_BUTTON_STEP_IS_NOT_CONFIGURED,
escalation_error_code=AlertGroupLogRecord.ERROR_ESCALATION_TRIGGER_WEBHOOK_STEP_IS_NOT_CONFIGURED,
escalation_policy_step=self.step,
)
log_record.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,18 +554,7 @@ def _render_escalation_step_plan_from_escalation_policy_snapshot(
# notification_plan_dict structure - {timedelta: [{"user_id": user.pk, "plan_lines": []}]
for timedelta, notification_plan in notification_plan_dict.items():
escalation_plan_dict.setdefault(timedelta, []).extend(notification_plan)
elif escalation_policy_snapshot.step == EscalationPolicy.STEP_TRIGGER_CUSTOM_BUTTON:
if future_step:
custom_button = escalation_policy_snapshot.custom_button_trigger
if custom_button is not None:
plan_line = f"trigger outgoing webhook `{custom_button.name}`"
else:
plan_line = (
f'escalation step "{escalation_policy_snapshot.step_display}", '
f"but outgoing webhook is unspecified. Skipping"
)
plan = {"plan_lines": [plan_line]}
escalation_plan_dict.setdefault(timedelta, []).append(plan)
# TODO: should we add logic here for new webhooks?
elif escalation_policy_snapshot.step == EscalationPolicy.STEP_NOTIFY_IF_TIME:
if future_step:
if escalation_policy_snapshot.from_time is not None and escalation_policy_snapshot.to_time is not None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.10 on 2024-03-07 15:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('alerts', '0049_alter_alertgrouplogrecord_action_source'),
]

operations = [
migrations.AlterField(
model_name='alertgrouplogrecord',
name='type',
field=models.IntegerField(choices=[(0, 'Acknowledged'), (1, 'Unacknowledged'), (2, 'Invite'), (3, 'Stop invitation'), (4, 'Re-invite'), (5, 'Escalation triggered'), (6, 'Invitation triggered'), (16, 'Escalation finished'), (7, 'Silenced'), (15, 'Unsilenced'), (8, 'Attached'), (9, 'Unattached'), (10, 'Custom webhook triggered'), (11, 'Unacknowledged by timeout'), (12, 'Failed attachment'), (13, 'Incident resolved'), (14, 'Incident unresolved'), (17, 'Escalation failed'), (18, 'Acknowledge reminder triggered'), (19, 'Wiped'), (20, 'Deleted'), (21, 'Incident registered'), (22, 'A route is assigned to the incident'), (23, 'Trigger direct paging escalation'), (24, 'Unpage a user'), (25, 'Restricted')]),
),
]
14 changes: 7 additions & 7 deletions engine/apps/alerts/models/alert_group_log_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AlertGroupLogRecord(models.Model):
TYPE_SILENCE,
TYPE_ATTACHED,
TYPE_UNATTACHED,
TYPE_CUSTOM_BUTTON_TRIGGERED,
TYPE_CUSTOM_WEBHOOK_TRIGGERED,
TYPE_AUTO_UN_ACK,
TYPE_FAILED_ATTACHMENT,
TYPE_RESOLVED,
Expand Down Expand Up @@ -77,7 +77,7 @@ class AlertGroupLogRecord(models.Model):
TYPE_SILENCE,
TYPE_ATTACHED,
TYPE_UNATTACHED,
TYPE_CUSTOM_BUTTON_TRIGGERED,
TYPE_CUSTOM_WEBHOOK_TRIGGERED,
TYPE_FAILED_ATTACHMENT,
TYPE_RESOLVED,
TYPE_UN_RESOLVED,
Expand All @@ -98,7 +98,7 @@ class AlertGroupLogRecord(models.Model):
(TYPE_UN_SILENCE, "Unsilenced"),
(TYPE_ATTACHED, "Attached"),
(TYPE_UNATTACHED, "Unattached"),
(TYPE_CUSTOM_BUTTON_TRIGGERED, "Custom button triggered"),
(TYPE_CUSTOM_WEBHOOK_TRIGGERED, "Custom webhook triggered"),
(TYPE_AUTO_UN_ACK, "Unacknowledged by timeout"),
(TYPE_FAILED_ATTACHMENT, "Failed attachment"),
(TYPE_RESOLVED, "Incident resolved"),
Expand Down Expand Up @@ -127,7 +127,7 @@ class AlertGroupLogRecord(models.Model):
TYPE_UN_SILENCE: "un_silence",
TYPE_ATTACHED: "attach",
TYPE_UNATTACHED: "un_attach",
TYPE_CUSTOM_BUTTON_TRIGGERED: "custom_button_triggered",
TYPE_CUSTOM_WEBHOOK_TRIGGERED: "custom_webhook_triggered",
TYPE_AUTO_UN_ACK: "auto_un_acknowledge",
TYPE_FAILED_ATTACHMENT: "fail_attach",
TYPE_RESOLVED: "resolve",
Expand Down Expand Up @@ -155,7 +155,7 @@ class AlertGroupLogRecord(models.Model):
ERROR_ESCALATION_NOTIFY_GROUP_STEP_IS_NOT_CONFIGURED,
ERROR_ESCALATION_USER_GROUP_IS_EMPTY,
ERROR_ESCALATION_USER_GROUP_DOES_NOT_EXIST,
ERROR_ESCALATION_TRIGGER_CUSTOM_BUTTON_STEP_IS_NOT_CONFIGURED,
ERROR_ESCALATION_TRIGGER_WEBHOOK_STEP_IS_NOT_CONFIGURED,
ERROR_ESCALATION_NOTIFY_IN_SLACK,
ERROR_ESCALATION_NOTIFY_IF_NUM_ALERTS_IN_WINDOW_STEP_IS_NOT_CONFIGURED,
ERROR_ESCALATION_TRIGGER_CUSTOM_WEBHOOK_ERROR,
Expand Down Expand Up @@ -471,7 +471,7 @@ def rendered_log_line_action(self, for_slack=False, html=False, substitute_autho
f"{self.dependent_alert_group.long_verbose_name} has been unattached from this alert"
f"{f' by {author_name}' if author_name else ''}"
)
elif self.type == AlertGroupLogRecord.TYPE_CUSTOM_BUTTON_TRIGGERED:
elif self.type == AlertGroupLogRecord.TYPE_CUSTOM_WEBHOOK_TRIGGERED:
webhook_name = ""
trigger = None
if step_specific_info is not None:
Expand Down Expand Up @@ -529,7 +529,7 @@ def rendered_log_line_action(self, for_slack=False, html=False, substitute_autho
result += 'skipped escalation step "Notify Team Members" because it is not configured'
elif (
self.escalation_error_code
== AlertGroupLogRecord.ERROR_ESCALATION_TRIGGER_CUSTOM_BUTTON_STEP_IS_NOT_CONFIGURED
== AlertGroupLogRecord.ERROR_ESCALATION_TRIGGER_WEBHOOK_STEP_IS_NOT_CONFIGURED
):
result += 'skipped escalation step "Trigger Outgoing Webhook" because it is not configured'
elif self.escalation_error_code == AlertGroupLogRecord.ERROR_ESCALATION_TRIGGER_CUSTOM_WEBHOOK_ERROR:
Expand Down
Loading
Loading