snowflake.core.alert.AlertCollectionΒΆ
- class snowflake.core.alert.AlertCollection(schema: SchemaResource)ΒΆ
Bases:
SchemaObjectCollectionParent
[AlertResource
]Represents the collection operations on the Snowflake Alert resource.
With this collection, you can create, update, iterate through, and fetch alerts that you have access to in the current context.
Attributes
- databaseΒΆ
- rootΒΆ
Methods
- create(alert: str, *, clone_alert: str | Clone, mode: CreateMode = CreateMode.error_if_exists) AlertResource ΒΆ
- create(alert: Alert, *, clone_alert: None, mode: CreateMode = CreateMode.error_if_exists) AlertResource
Create an alert in Snowflake.
There are two ways to create an alert: by cloning or by building from scratch.
Cloning an existing alert
- Parameters:
alert (str) β The new alertβs name
clone_alert (str or Clone object) β The name of alert to be cloned, or a
Clone
object which would contain the name of the alert with support to clone at a specific time.mode (CreateMode, optional) β
One of the following enum values:
CreateMode.error_if_exists
: Throw ansnowflake.core.exceptions.ConflictError
if the alert already exists in Snowflake. Equivalent to SQLcreate alert <name> ...
.CreateMode.or_replace
: Replace if the alert already exists in Snowflake. Equivalent to SQLcreate or replace alert <name> ...
.CreateMode.if_not_exists
: Do nothing if the alert already exists in Snowflake. Equivalent to SQLcreate alert <name> if not exists...
Default is
CreateMode.error_if_exists
.
Examples
Cloning an alert instance:
>>> alerts = schema.alerts >>> alerts.create( ... new_alert_name, ... clone_alert=alert_name_to_be_cloned, ... mode=CreateMode.if_not_exists, ... )
Creating an alert from scratch
- Parameters:
alert (Alert) β The details of
Alert
object, together withAlert
βs properties: name, schedule, condition, action ; comment, warehouse are optional.mode (CreateMode, optional) β
One of the following enum values:
CreateMode.error_if_exists
: Throw ansnowflake.core.exceptions.ConflictError
if the alert already exists in Snowflake. Equivalent to SQLcreate alert <name> ...
.CreateMode.or_replace
: Replace if the alert already exists in Snowflake. Equivalent to SQLcreate or replace alert <name> ...
.CreateMode.if_not_exists
: Do nothing if the alert already exists in Snowflake. Equivalent to SQLcreate alert <name> if not exists...
Default is
CreateMode.error_if_exists
.
Examples
Creating an alert instance:
>>> alerts.create( ... Alert( ... name="my_alert", ... warehouse="my_warehouse", ... schedule="MinutesSchedule(minutes=1)", ... condition="SELECT COUNT(*) FROM my_table > 100", ... action="DROP TABLE my_table", ... ), ... mode=CreateMode.if_not_exists, ... )
- items() ItemsView[str, T] ΒΆ
- iter(*, like: Annotated[str, Strict(strict=True)] | None = None, starts_with: Annotated[str, Strict(strict=True)] | None = None, show_limit: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1), Le(le=10000)])] | None = None, from_name: Annotated[str, Strict(strict=True)] | None = None) Iterator[Alert] ΒΆ
Iterate through
Alert
objects from Snowflake, filtering on any optional βlikeβ pattern.- Parameters:
like (str, optional) β A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).
starts_with (str, optional) β String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.
show_limit (int, optional) β Limit of the maximum number of rows returned by iter(). The default is
None
, which behaves equivalently to show_limit=10000. This value must be between1
and10000
.from_name (str, optional) β Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.
Examples
Showing all alerts that you have access to see:
>>> alerts = alert_collection.iter()
Showing information of the exact alert you want to see:
>>> alerts = alert_collection.iter(like="your-alert-name")
Showing alerts starting with βyour-alert-name-β:
>>> alerts = alert_collection.iter(like="your-alert-name-%")
Using a for loop to retrieve information from iterator:
>>> for alert in alerts: >>> print(alert.name, alert.condition, alert.action)
- keys() KeysView[str] ΒΆ
- values() ValuesView[T] ΒΆ