Forum Discussion
cdreeetz
Nov 06, 2023Copper Contributor
How to setup a Log Analytics Workspace in a Fabric Notebook
I am using azure-monitor-query to automate some logs we need but can't get the workspace to work in the notebook with service principal credentials. The service principal has read access to the log analytics workspace.
credential = ClientSecretCredential(
tenant_id= 'tenant_id',
client_id= "client_id",
client_secret= "client_secret")
client = LogsQueryClient(credential)
log_workspace_id = "workspace_id"
query = """AppRequests | take 5"""
start_time=datetime(2021, 7, 2, tzinfo=timezone.utc)
end_time=datetime(2021, 7, 4, tzinfo=timezone.utc)
try:
response = client.query_workspace(
workspace_id = log_workspace_id,
query=query,
timespan=(start_time, end_time)
)
if response.status == LogsQueryStatus.PARTIAL:
error = response.partial_error
data = response.partial_data
print(error)
elif response.status == LogsQueryStatus.SUCCESS:
data = response.tables
for table in data:
df = pd.DataFrame(data=table.rows, columns=table.columns)
print(df)
except HttpResponseError as err:
print("something fatal happened")
print(err)
something fatal happened (PathNotFoundError) The requested path does not exist Code: PathNotFoundError Message: The requested path does not exist
No RepliesBe the first to reply