|
|
|
|
|
SELECT |
|
maintenance_expires_at NOTNULL::bool AS is_maint_mode, |
|
alerts.status |
|
FROM |
|
services svc |
|
JOIN alerts ON alerts.service_id = svc.id |
|
WHERE |
|
alerts.id = $1 |
|
FOR UPDATE; |
|
|
|
|
|
|
|
UPDATE |
|
escalation_policy_state |
|
SET |
|
force_escalation = TRUE |
|
WHERE |
|
alert_id = $1 |
|
AND (last_escalation <= $2::timestamptz |
|
OR last_escalation IS NULL) |
|
RETURNING |
|
TRUE; |
|
|
|
|
|
|
|
SELECT |
|
EXISTS ( |
|
SELECT |
|
1 |
|
FROM |
|
escalation_policy_state |
|
WHERE |
|
alert_id = $1) AS has_ep_state; |
|
|
|
|
|
|
|
SELECT |
|
alert_id, |
|
noise_reason |
|
FROM |
|
alert_feedback |
|
WHERE |
|
alert_id = ANY ($1::int[]); |
|
|
|
|
|
|
|
INSERT INTO alert_feedback(alert_id, noise_reason) |
|
VALUES ($1, $2) |
|
ON CONFLICT (alert_id) |
|
DO UPDATE SET |
|
noise_reason = $2 |
|
WHERE |
|
alert_feedback.alert_id = $1; |
|
|
|
|
|
|
|
INSERT INTO alert_feedback(alert_id, noise_reason) |
|
VALUES (unnest(@alert_ids::bigint[]), @noise_reason) |
|
ON CONFLICT (alert_id) |
|
DO UPDATE SET |
|
noise_reason = excluded.noise_reason |
|
WHERE |
|
alert_feedback.alert_id = excluded.alert_id |
|
RETURNING |
|
alert_id; |
|
|
|
|
|
|
|
SELECT |
|
metadata |
|
FROM |
|
alert_data |
|
WHERE |
|
alert_id = $1; |
|
|
|
|
|
|
|
SELECT |
|
alert_id, |
|
metadata |
|
FROM |
|
alert_data |
|
WHERE |
|
alert_id = ANY (@alert_ids::bigint[]); |
|
|
|
|
|
|
|
INSERT INTO alert_data(alert_id, metadata) |
|
SELECT |
|
a.id, |
|
$2 |
|
FROM |
|
alerts a |
|
WHERE |
|
a.id = $1 |
|
AND a.status != 'closed' |
|
AND (a.service_id = $3 |
|
OR $3 IS NULL) |
|
ON CONFLICT (alert_id) |
|
DO UPDATE SET |
|
metadata = $2 |
|
WHERE |
|
alert_data.alert_id = $1; |
|
|
|
|
|
|
|
SELECT |
|
EXISTS ( |
|
SELECT |
|
1 |
|
FROM |
|
escalation_policy_steps step |
|
JOIN services svc ON step.escalation_policy_id = svc.escalation_policy_id |
|
WHERE |
|
svc.id = @service_id); |
|
|
|
|
|
|
|
SELECT |
|
1 |
|
FROM |
|
services |
|
WHERE |
|
id = @service_id |
|
FOR UPDATE; |
|
|
|
|
|
|
|
SELECT |
|
1 |
|
FROM |
|
alerts a |
|
JOIN services s ON a.service_id = s.id |
|
WHERE |
|
a.id = ANY (@alert_ids::bigint[]) |
|
FOR UPDATE; |
|
|
|
|
|
|
|
SELECT |
|
a.status |
|
FROM |
|
alerts a |
|
JOIN services svc ON svc.id = a.service_id |
|
WHERE |
|
a.id = @id::bigint |
|
FOR UPDATE; |
|
|
|
|
|
|
|
SELECT |
|
escalation_policy_id |
|
FROM |
|
alerts a |
|
JOIN services svc ON svc.id = a.service_id |
|
WHERE |
|
a.id = @id::bigint; |
|
|
|
|