Created
July 8, 2019 14:55
-
-
Save alexeldeib/5096dea875500592c743cc517180bfd2 to your computer and use it in GitHub Desktop.
Log Analytics Python SDK Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from azure.common.credentials import ServicePrincipalCredentials | |
from azure import loganalytics | |
TENANT_ID = '' | |
CLIENT_ID = '' | |
KEY = '' # Client Secret | |
WORKSPACE_ID = '' # from the log analytics workspace | |
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) | |
workspace_id = WORKSPACE_ID | |
body = loganalytics.models.QueryBody(query = "union * | take 1") # the query | |
query_results = client.query(workspace_id, body) # type: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/loganalytics/azure-loganalytics/azure/loganalytics/models/query_results.py | |
table = query_results.tables[0] # https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/loganalytics/azure-loganalytics/azure/loganalytics/models/table.py | |
columns = table.columns | |
rows = table.rows # [][] of arbitrary data | |
print(columns) # VERY noisy | |
print(rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment