Google Cloud Monitoring Operators

Note

The Stackdriver* classes in the stackdriver modules are deprecated aliases for the CloudMonitoring* classes documented below, and will be removed after March 31, 2027.

Prerequisite Tasks

To use these operators, you must do a few things:

CloudMonitoringListAlertPoliciesOperator

Use the CloudMonitoringListAlertPoliciesOperator 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.

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

list_alert_policies = CloudMonitoringListAlertPoliciesOperator(
    task_id="list-alert-policies",
    filter_=f'(displayName="{ALERT_1_NAME}" OR displayName="{ALERT_2_NAME}")',
)

CloudMonitoringEnableAlertPoliciesOperator

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

Using the operator

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

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

enable_alert_policy = CloudMonitoringEnableAlertPoliciesOperator(
    task_id="enable-alert-policies",
    filter_=f'(displayName="{ALERT_1_NAME}" OR displayName="{ALERT_2_NAME}")',
)

CloudMonitoringDisableAlertPoliciesOperator

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

Using the operator

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

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

disable_alert_policy = CloudMonitoringDisableAlertPoliciesOperator(
    task_id="disable-alert-policies",
    filter_=f'displayName="{ALERT_1_NAME}"',
)

CloudMonitoringUpsertAlertOperator

Use the CloudMonitoringUpsertAlertOperator to upsert Alert Policies identified by given filter JSON string. If the alert with the given 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 create or update alert policies. If project id is missing it will be retrieved from Google Cloud connection used.

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

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

CloudMonitoringDeleteAlertOperator

Use the CloudMonitoringDeleteAlertOperator 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>

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

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

CloudMonitoringListNotificationChannelsOperator

Use the CloudMonitoringListNotificationChannelsOperator 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 notification channels. If project id is missing it will be retrieved from Google Cloud connection used.

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

list_notification_channel = CloudMonitoringListNotificationChannelsOperator(
    task_id="list-notification-channel",
    filter_=f'(displayName="{CHANNEL_1_NAME}" OR displayName="{CHANNEL_2_NAME}")',
)

CloudMonitoringEnableNotificationChannelsOperator

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

Using the operator

You can use this operator with or without project id to enable notification channels. If project id is missing it will be retrieved from Google Cloud connection used.

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

enable_notification_channel = CloudMonitoringEnableNotificationChannelsOperator(
    task_id="enable-notification-channel",
    filter_=f'(displayName="{CHANNEL_1_NAME}" OR displayName="{CHANNEL_2_NAME}")',
)

CloudMonitoringDisableNotificationChannelsOperator

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

Using the operator

You can use this operator with or without project id to disable notification channels. If project id is missing it will be retrieved from Google Cloud connection used.

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

disable_notification_channel = CloudMonitoringDisableNotificationChannelsOperator(
    task_id="disable-notification-channel", filter_=f'displayName="{CHANNEL_1_NAME}"'
)

CloudMonitoringUpsertNotificationChannelOperator

Use the CloudMonitoringUpsertNotificationChannelOperator to upsert Notification Channels identified by given channel JSON string. If the channel with the given 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 create or update notification channels. If project id is missing it will be retrieved from Google Cloud connection used.

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

create_notification_channel = CloudMonitoringUpsertNotificationChannelOperator(
    task_id="create-notification-channel",
    channels=json.dumps({"channels": [TEST_NOTIFICATION_CHANNEL_1, TEST_NOTIFICATION_CHANNEL_2]}),
)

CloudMonitoringDeleteNotificationChannelOperator

Use the CloudMonitoringDeleteNotificationChannelOperator to delete a Notification Channel identified by given name.

Using the operator

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

You can use this operator with or without project id to delete a notification channel. If project id is missing it will be retrieved from Google Cloud connection used.

tests/system/google/cloud/cloud_monitoring/example_cloud_monitoring.py[source]

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

Was this entry helpful?