Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created June 14, 2019 06:58
Show Gist options
  • Save chgeuer/bab9fadb808ddfbceb0d647ccf4e570e to your computer and use it in GitHub Desktop.
Save chgeuer/bab9fadb808ddfbceb0d647ccf4e570e to your computer and use it in GitHub Desktop.
#!/bin/bash
resource="https://api.loganalytics.io/"
aadTenant="chgeuerfte.onmicrosoft.com"
SAMPLE_SP_APPID="465ffd36-4473-47ff-8107-6c478c074adf"
SAMPLE_SP_KEY="..."
access_token="$(curl \
--silent \
--request POST \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_id=${SAMPLE_SP_APPID}" \
--data-urlencode "client_secret=${SAMPLE_SP_KEY}" \
--data-urlencode "resource=${resource}" \
"https://login.microsoftonline.com/${aadTenant}/oauth2/token" | \
jq -r ".access_token")"
workspace_name="chgeuer123"
curl \
-X POST \
"https://api.loganalytics.io/v1/workspaces/${workspace_name}/query" \
--header "Authorization: Bearer ${access_token}" \
--header "Content-Type: application/json" \
-d '{"query": "AzureActivity | summarize count() by Category"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment