@@ -58,14 +58,10 @@ client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
58
58
# Client Secret
59
59
client_secret = " xxxxxxxxxxxxxx"
60
60
subscription_id = " xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
61
- credentials = ServicePrincipalCredentials(
62
- client_id = client_id,
63
- secret = client_secret,
64
- tenant = tenant_id
65
- )
66
61
location = " West Europe"
67
62
location_small_case = " westeurope"
68
-
63
+ # path to the Azure Resource Manager template json from the previous section
64
+ azure_resource_template_path = " xxxxxxxxx/template.json" ;
69
65
70
66
deployment_name = ' e2eexample'
71
67
resource_group_name = deployment_name + " resourcegroup"
@@ -98,8 +94,7 @@ resource_client.resource_groups.create_or_update(
98
94
99
95
print (' Step 2: create a blob storage, a container in the storage account, an event hub, an azure data explorer cluster, and database by using an Azure Resource Manager template.' )
100
96
# Read the Azure Resource Manager template
101
- template_path = os.path.join(os.path.dirname(__file__ ), ' template.json' )
102
- with open (template_path, ' r' ) as template_file_fd:
97
+ with open (azure_resource_template_path, ' r' ) as template_file_fd:
103
98
template = json.load(template_file_fd)
104
99
105
100
parameters = {
@@ -117,6 +112,7 @@ deployment_properties = {
117
112
' parameters' : parameters
118
113
}
119
114
115
+ # Returns an instance of LROPoller, see https://docs.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
120
116
poller = resource_client.deployments.create_or_update(
121
117
resource_group_name,
122
118
deployment_name,
@@ -143,7 +139,7 @@ event_client.event_subscriptions.create_or_update(storage_resource_id, event_gri
143
139
})
144
140
145
141
146
- print (' Step 4: create a table and column mapping in Azure Data Explorer database.' )
142
+ print (' Step 4: create a table (with three columns, EventTime, EventId, and EventSummary) and column mapping in Azure Data Explorer database.' )
147
143
kusto_uri = " https://{} .{} .kusto.windows.net" .format(kusto_cluster_name, location_small_case)
148
144
database_name = kusto_database_name
149
145
kusto_connection_string_builder = KustoConnectionStringBuilder.with_aad_application_key_authentication(connection_string = kusto_uri, aad_app_id = client_id, app_key = client_secret, authority_id = tenant_id)
@@ -156,10 +152,10 @@ create_column_mapping_command = ".create table " + kusto_table_name + " ingestio
156
152
kusto_client.execute_mgmt(database_name, create_column_mapping_command)
157
153
158
154
159
- print (' Step 5: add data connection.' )
155
+ print (' Step 5: add a event grid data connection. Azure Data Explorer will automatically ingest the data when new blobs are created .' )
160
156
kusto_management_client = KustoManagementClient(credentials, subscription_id)
161
157
data_connections = kusto_management_client.data_connections
162
- # Returns an instance of LROPoller, check https://docs.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
158
+ # Returns an instance of LROPoller, see https://docs.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
163
159
poller = data_connections.create_or_update(resource_group_name = resource_group_name, cluster_name = kusto_cluster_name, database_name = kusto_database_name, data_connection_name = kusto_data_connection_name,
164
160
parameters = EventGridDataConnection(storage_account_resource_id = storage_resource_id,
165
161
event_hub_resource_id = event_hub_resource_id, consumer_group = " $Default" , location = location, table_name = kusto_table_name, mapping_rule_name = kusto_column_mapping_name, data_format = " csv" ))
@@ -201,7 +197,9 @@ print(response.primary_results[0].rows_count)
201
197
To delete the resource group and clean up resources, use the following command:
202
198
203
199
``` python
204
- resource_client.resource_groups.delete(resource_group_name = resource_group_name)
200
+ # Returns an instance of LROPoller, see https://docs.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
201
+ poller = resource_client.resource_groups.delete(resource_group_name = resource_group_name)
202
+ poller.wait()
205
203
```
206
204
207
205
## Next steps
0 commit comments