question

Sam-1176 avatar image
0 Votes"
Sam-1176 asked SathyamoorthyVijayakumar-MSFT answered

What type of object should the credentials parameter be for the Azure LogAnalyticsDataClient class?

As we can see in the documentation (https://docs.microsoft.com/en-us/python/api/azure-loganalytics/azure.loganalytics.log_analytics_data_client.loganalyticsdataclient?view=azure-python), the constructor receives 2 parameters: 1) credentials, 2) base_url

It writes that credentials is of type None, but giving it None will cause an exception. So what type of object should I pass for the credentials parameter?

Thanks.

azure-monitor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SathyamoorthyVijayakumar-MSFT avatar image
0 Votes"
SathyamoorthyVijayakumar-MSFT answered

If you are making use of the Service Principal You will have to pass the ServicePrincipalCredential Object - The credential object can be initialized and used as below:

 from azure.common.credentials import ServicePrincipalCredentials
 credentials = ServicePrincipalCredentials(
     client_id = CLIENT_ID,
     secret = KEY,
     tenant = TENANT_ID,
     resource = "https://api.loganalytics.io "
 )
    
 client = loganalytics.log_analytics_data_client.LogAnalyticsDataClient(credentials, base_url=None)

Alternatively, if you are looking to load the cred object of the Azure CLI Profile

    from azure.common.credentials import get_azure_cli_credentials 
    credentials, _ = get_azure_cli_credentials(resource="https://api.loganalytics.io")
    client = loganalytics.log_analytics_data_client.LogAnalyticsDataClient(credentials, base_url=None)




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.