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] ¶