Google Cloud Stackdriver Operators

StackdriverListAlertPoliciesOperator

Use the StackdriverListAlertPoliciesOperator to fetch all the Alert Policies identified by given filter.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

list_alert_policies = StackdriverListAlertPoliciesOperator(
    task_id='list-alert-policies',
)

StackdriverEnableAlertPoliciesOperator

Use the StackdriverEnableAlertPoliciesOperator to enable Alert Policies identified by given filter.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

enable_alert_policy = StackdriverEnableAlertPoliciesOperator(
    task_id='enable-alert-policies',
    filter_='(displayName="test alert 1" OR displayName="test alert 2")',
)

StackdriverDisableAlertPoliciesOperator

Use the StackdriverDisableAlertPoliciesOperator to disable Alert Policies identified by given filter.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

disable_alert_policy = StackdriverDisableAlertPoliciesOperator(
    task_id='disable-alert-policies',
    filter_='displayName="test alert 1"',
)

StackdriverUpsertAlertOperator

Use the StackdriverUpsertAlertOperator to upsert Alert Policies identified by given filter JSON string. If the alert with the give name already exists, then the operator updates the existing policy otherwise creates a new one.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

create_alert_policy = StackdriverUpsertAlertOperator(
    task_id='create-alert-policies',
    alerts=json.dumps({"policies": [TEST_ALERT_POLICY_1, TEST_ALERT_POLICY_2]}),
)

StackdriverDeleteAlertOperator

Use the StackdriverDeleteAlertOperator to delete an Alert Policy identified by given name.

Using the operator

The name of the alert to be deleted should be given in the format projects/<PROJECT_NAME>/alertPolicies/<ALERT_NAME>

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

delete_alert_policy = StackdriverDeleteAlertOperator(
    task_id='delete-alert-policy',
    name="{{ task_instance.xcom_pull('list-alert-policies')[0]['name'] }}",
)

StackdriverListNotificationChannelsOperator

Use the StackdriverListNotificationChannelsOperator to fetch all the Notification Channels identified by given filter.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

list_notification_channel = StackdriverListNotificationChannelsOperator(
    task_id='list-notification-channel', filter_='type="slack"'
)

StackdriverEnableNotificationChannelsOperator

Use the StackdriverEnableNotificationChannelsOperator to enable Notification Channels identified by given filter.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

enable_notification_channel = StackdriverEnableNotificationChannelsOperator(
    task_id='enable-notification-channel', filter_='type="slack"'
)

StackdriverDisableNotificationChannelsOperator

Use the StackdriverDisableNotificationChannelsOperator to disable Notification Channels identified by given filter.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

disable_notification_channel = StackdriverDisableNotificationChannelsOperator(
    task_id='disable-notification-channel', filter_='displayName="channel1"'
)

StackdriverUpsertNotificationChannelOperator

Use the StackdriverUpsertNotificationChannelOperator to upsert Notification Channels identified by given channel JSON string. If the channel with the give name already exists, then the operator updates the existing channel otherwise creates a new one.

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

disable_notification_channel = StackdriverDisableNotificationChannelsOperator(
    task_id='disable-notification-channel', filter_='displayName="channel1"'
)

StackdriverDeleteNotificationChannelOperator

The name of the alert to be deleted should be given in the format projects/<PROJECT_NAME>/notificationChannels/<CHANNEL_NAME>

Using the operator

You can use this operator with or without project id to fetch all the alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

airflow/providers/google/cloud/example_dags/example_stackdriver.pyView Source

delete_notification_channel = StackdriverDeleteNotificationChannelOperator(
    task_id='delete-notification-channel',
    name="{{ task_instance.xcom_pull('list-notification-channel')[0]['name'] }}",
)

Was this entry helpful?