Esplora dati di Azure è un servizio di esplorazione dati rapido e a scalabilità elevata per dati di log e di telemetria. In questo articolo si apprenderà come aggiungere entità cluster per Azure Esplora dati usando C#, Python o un modello di Azure Resource Manager (ARM).
I prerequisiti variano in base al metodo usato per aggiungere l'entità. Scegliere la scheda pertinente per il metodo preferito.
Eseguire il codice seguente per aggiungere un'entità cluster:
var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
var clientSecret = "PlaceholderClientSecret"; //Client Secret
var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var credentials = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret);
var kustoManagementClient = new KustoManagementClient(credentials) { SubscriptionId = subscriptionId };
var resourceGroupName = "testrg";
//The cluster that is created as part of the Prerequisites
var clusterName = "mykustocluster";
var clusterPrincipalAssignmentName = "mykustoclusterprincipalassignment";
var principalId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //User email, application ID, or security group name
var role = "AllDatabasesAdmin"; //AllDatabasesAdmin or AllDatabasesViewer
var tenantIdForPrincipal = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var principalType = "App"; //User, App, or Group
var clusterPrincipalAssignmentData = new ClusterPrincipalAssignment(
principalId: principalId, role: role, principalType: principalType, tenantId: tenantIdForPrincipal
);
await kustoManagementClient.ClusterPrincipalAssignments.CreateOrUpdateAsync(
resourceGroupName, clusterName, clusterPrincipalAssignmentName, clusterPrincipalAssignmentData
);
Impostazione |
Valore consigliato |
Descrizione campo |
TenantId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
ID tenant. Noto anche come ID directory. |
subscriptionId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
L'ID sottoscrizione usato per la creazione di risorse. |
clientId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
L'ID client dell'applicazione che può accedere alle risorse nel tenant. |
clientSecret |
SegnapostoClientSecret |
Il segreto client dell'applicazione che può accedere alle risorse nel tenant. |
resourceGroupName |
testrg |
Nome del gruppo di risorse contenente il cluster. |
clusterName |
mykustocluster |
Nome del cluster. |
principalAssignmentName |
clusterPrincipalAssignment1 |
Nome della risorsa dell'entità cluster. |
principalId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
ID principale, che può essere indirizzo di posta elettronica utente, ID applicazione o nome gruppo di sicurezza. |
ruolo |
AllDatabasesAdmin |
Ruolo dell'entità cluster, che può essere "AllDatabasesAdmin", "AllDatabasesMonitor" o "AllDatabasesViewer". |
tenantIdForPrincipal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
ID tenant dell'entità. |
principalType |
App |
Tipo dell'entità, che può essere 'User', 'App' o 'Group' |
Eseguire il codice seguente per aggiungere un'entità cluster:
from azure.mgmt.kusto import KustoManagementClient
from azure.mgmt.kusto.models import ClusterPrincipalAssignment
from azure.common.credentials import ServicePrincipalCredentials
#Directory (tenant) ID
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Application ID
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Client Secret
client_secret = "xxxxxxxxxxxxxx"
subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=client_secret,
tenant=tenant_id
)
kusto_management_client = KustoManagementClient(credentials, subscription_id)
resource_group_name = "testrg"
#The cluster that is created as part of the Prerequisites
cluster_name = "mykustocluster"
principal_assignment_name = "clusterPrincipalAssignment1"
#User email, application ID, or security group name
principal_id = "xxxxxxxx"
#AllDatabasesAdmin, AllDatabasesMonitor or AllDatabasesViewer
role = "AllDatabasesAdmin"
tenant_id_for_principal = tenantId
#User, App, or Group
principal_type = "App"
#Returns an instance of LROPoller, check https://learn.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
poller = kusto_management_client.cluster_principal_assignments.create_or_update(resource_group_name=resource_group_name, cluster_name=cluster_name, principal_assignment_name= principal_assignment_name, parameters=ClusterPrincipalAssignment(principal_id=principal_id, role=role, tenant_id=tenant_id_for_principal, principal_type=principal_type))
Impostazione |
Valore consigliato |
Descrizione campo |
tenant_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
ID tenant. Noto anche come ID directory. |
subscription_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
L'ID sottoscrizione usato per la creazione di risorse. |
client_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
L'ID client dell'applicazione che può accedere alle risorse nel tenant. |
client_secret |
xxxxxxxxxxxxxx |
Il segreto client dell'applicazione che può accedere alle risorse nel tenant. |
resource_group_name |
testrg |
Nome del gruppo di risorse contenente il cluster. |
cluster_name |
mykustocluster |
Nome del cluster. |
principal_assignment_name |
clusterPrincipalAssignment1 |
Nome della risorsa dell'entità cluster. |
principal_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
ID principale, che può essere indirizzo di posta elettronica utente, ID applicazione o nome gruppo di sicurezza. |
ruolo |
AllDatabasesAdmin |
Ruolo dell'entità cluster, che può essere "AllDatabasesAdmin", "AllDatabasesMonitor" o "AllDatabasesViewer". |
tenant_id_for_principal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxx |
ID tenant dell'entità. |
principal_type |
App |
Tipo dell'entità, che può essere 'User', 'App' o 'Group' |
Nell'esempio seguente viene illustrato un modello di Resource Manager di Azure per l'aggiunta di un'entità cluster. È possibile modificare e distribuire il modello nella portale di Azure usando il modulo.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterPrincipalAssignmentName": {
"type": "string",
"defaultValue": "principalAssignment1",
"metadata": {
"description": "Specifies the name of the principal assignment"
}
},
"clusterName": {
"type": "string",
"defaultValue": "mykustocluster",
"metadata": {
"description": "Specifies the name of the cluster"
}
},
"principalIdForCluster": {
"type": "string",
"metadata": {
"description": "Specifies the principal id. It can be user email, application (client) ID, security group name"
}
},
"roleForClusterPrincipal": {
"type": "string",
"defaultValue": "AllDatabasesViewer",
"metadata": {
"description": "Specifies the cluster principal role. It can be 'AllDatabasesAdmin', 'AllDatabasesMonitor' or 'AllDatabasesViewer'"
}
},
"tenantIdForClusterPrincipal": {
"type": "string",
"metadata": {
"description": "Specifies the tenantId of the principal"
}
},
"principalTypeForCluster": {
"type": "string",
"defaultValue": "User",
"metadata": {
"description": "Specifies the principal type. It can be 'User', 'App', 'Group'"
}
}
},
"variables": {
},
"resources": [{
"type": "Microsoft.Kusto/Clusters/principalAssignments",
"apiVersion": "2019-11-09",
"name": "[concat(parameters('clusterName'), '/', parameters('clusterPrincipalAssignmentName'))]",
"properties": {
"principalId": "[parameters('principalIdForCluster')]",
"role": "[parameters('roleForClusterPrincipal')]",
"tenantId": "[parameters('tenantIdForClusterPrincipal')]",
"principalType": "[parameters('principalTypeForCluster')]"
}
}
]
}