Exemple #1
0
 def test_execute(self, mock_hook):
     operator = StackdriverUpsertNotificationChannelOperator(
         task_id=TEST_TASK_ID,
         channels=json.dumps({"channels": [TEST_NOTIFICATION_CHANNEL_1, TEST_NOTIFICATION_CHANNEL_2]}),
     )
     operator.execute(None)
     mock_hook.return_value.upsert_channel.assert_called_once_with(
         channels=json.dumps({"channels": [TEST_NOTIFICATION_CHANNEL_1, TEST_NOTIFICATION_CHANNEL_2]}),
         project_id=None,
         retry=DEFAULT,
         timeout=DEFAULT,
         metadata=None,
     )
        "channel_name": "#channel"
    },
    "type_": "slack",
}

with models.DAG(
        'example_stackdriver',
        schedule_interval='@once',  # Override to match your needs
        start_date=days_ago(1),
        tags=['example'],
) as dag:
    # [START howto_operator_gcp_stackdriver_upsert_notification_channel]
    create_notification_channel = StackdriverUpsertNotificationChannelOperator(
        task_id='create-notification-channel',
        channels=json.dumps({
            "channels":
            [TEST_NOTIFICATION_CHANNEL_1, TEST_NOTIFICATION_CHANNEL_2]
        }),
    )
    # [END howto_operator_gcp_stackdriver_upsert_notification_channel]

    # [START howto_operator_gcp_stackdriver_enable_notification_channel]
    enable_notification_channel = StackdriverEnableNotificationChannelsOperator(
        task_id='enable-notification-channel', filter_='type="slack"')
    # [END howto_operator_gcp_stackdriver_enable_notification_channel]

    # [START howto_operator_gcp_stackdriver_disable_notification_channel]
    disable_notification_channel = StackdriverDisableNotificationChannelsOperator(
        task_id='disable-notification-channel',
        filter_='displayName="channel1"')
    # [END howto_operator_gcp_stackdriver_disable_notification_channel]