PagerDuty Alert Task
Learn how to configure PagerDuty alert tasks in Synnax.
For task lifecycle management, see the Task Basics page.
Task Configuration Reference
Alert Configuration Reference
Each alert maps a Synnax status key to a PagerDuty event. At least one alert must be enabled.
How-To
Create and run an alert task
import synnax as sy
client = sy.Synnax()
# Create a status to watch
STATUS_KEY = "example-pagerduty-status"
client.statuses.set(
sy.Status(
key=STATUS_KEY,
name="Engine 1",
variant="success",
message="Engine 1 is healthy",
)
)
# Create the PagerDuty alert task
alert_task = sy.pagerduty.AlertTask(
name="Example PagerDuty Alert",
routing_key="<your-32-character-integration-key>",
auto_start=False,
alerts=[
sy.pagerduty.AlertConfig(
status=STATUS_KEY,
enabled=True,
treat_error_as_critical=True,
component="engine-1",
group="engines",
),
],
)
# Configure the task on the server
client.tasks.configure(alert_task)
# Start the task - it will watch for status changes
with alert_task.run():
# Trigger a PagerDuty incident by setting status to error
client.statuses.set(
sy.Status(
key=STATUS_KEY,
name="Engine 1",
variant="error",
message="Engine 1 is down",
description="Connection to database lost",
)
)
sy.sleep(5)
# Resolve by setting status back to success
client.statuses.set(
sy.Status(
key=STATUS_KEY,
name="Engine 1",
variant="success",
message="Engine 1 recovered",
)
)
sy.sleep(3)
# Task automatically stops when exiting the context manager