Tutorial: Configure a log analytics workspace
In this tutorial, you learn how to:
- Configure a log analytics workspace for your audit and sign-in logs
- Run queries using the Kusto Query Language (KQL)
- Create an alert rule that sends alerts when a specific account is used
- Create a custom workbook using the quickstart template
- Add a query to an existing workbook template
Prerequisites
An Azure subscription with at least one P1 licensed admin. If you don't have an Azure subscription, you can sign up for a free trial.
An Azure Active Directory (Azure AD) tenant.
A user who's a Global Administrator or Security Administrator for the Azure AD tenant.
Familiarize yourself with these articles:
Configure a workspace
This procedure outlines how to configure a log analytics workspace for your audit and sign-in logs. Configuring a log analytics workspace consists of two main steps:
- Creating a log analytics workspace
- Setting diagnostic settings
To configure a workspace:
Sign in to the Azure portal as a global administrator.
Search for log analytics workspaces.
On the log analytics workspaces page, click Add.
On the Create Log Analytics workspace page, perform the following steps:
Select your subscription.
Select a resource group.
In the Name textbox, type a name (e.g.: MytestWorkspace1).
Select your region.
Click Review + Create.
Click Create and wait for the deployment to be succeeded. You may need to refresh the page to see the new workspace.
Search for Azure Active Directory.
In Monitoring section, click Diagnostic setting.
On the Diagnostic settings page, click Add diagnostic setting.
On the Diagnostic setting page, perform the following steps:
Under Category details, select AuditLogs and SigninLogs.
Under Destination details, select Send to Log Analytics, and then select your new log analytics workspace.
Click Save.
Run queries
This procedure shows how to run queries using the Kusto Query Language (KQL).
To run a query:
Sign in to the Azure portal as a global administrator.
Search for Azure Active Directory.
In the Monitoring section, click Logs.
On the Logs page, click Get Started.
In the *Search textbox, type your query.
Click Run.
KQL query examples
Take 10 random entries from the input data:
SigninLogs | take 10
Look at the sign-ins where the Conditional Access was a success
SigninLogs | where ConditionalAccessStatus == "success" | project UserDisplayName, ConditionalAccessStatus
Count how many successes there have been
SigninLogs | where ConditionalAccessStatus == "success" | project UserDisplayName, ConditionalAccessStatus | count
Aggregate count of successful sign-ins by user by day:
SigninLogs | where ConditionalAccessStatus == "success" | summarize SuccessfulSign-ins = count() by UserDisplayName, bin(TimeGenerated, 1d)
View how many times a user does a certain operation in specific time period:
AuditLogs | where TimeGenerated > ago(30d) | where OperationName contains "Add member to role" | summarize count() by OperationName, Identity
Pivot the results on operation name
AuditLogs | where TimeGenerated > ago(30d) | where OperationName contains "Add member to role" | project OperationName, Identity | evaluate pivot(OperationName)
Merge together Audit and Sign in Logs using an inner join:
AuditLogs |where OperationName contains "Add User" |extend UserPrincipalName = tostring(TargetResources[0].userPrincipalName) | |project TimeGenerated, UserPrincipalName |join kind = inner (SigninLogs) on UserPrincipalName |summarize arg_min(TimeGenerated, *) by UserPrincipalName |extend SigninDate = TimeGenerated
View number of signs ins by client app type:
SigninLogs | summarize count() by ClientAppUsed
Count the sign ins by day:
SigninLogs | summarize NumberOfEntries=count() by bin(TimeGenerated, 1d)
Take 5 random entries and project the columns you wish to see in the results:
SigninLogs | take 5 | project ClientAppUsed, Identity, ConditionalAccessStatus, Status, TimeGenerated
Take the top 5 in descending order and project the columns you wish to see
SigninLogs | take 5 | project ClientAppUsed, Identity, ConditionalAccessStatus, Status, TimeGenerated
Create a new column by combining the values to two other columns:
SigninLogs | limit 10 | extend RiskUser = strcat(RiskDetail, "-", Identity) | project RiskUser, ClientAppUsed
Create an alert rule
This procedure shows how to send alerts when the breakglass account is used.
To create an alert rule:
Sign in to the Azure portal as a global administrator.
Search for Azure Active Directory.
In the Monitoring section, click Logs.
On the Logs page, click Get Started.
In the Search textbox, type:
SigninLogs |where UserDisplayName contains "BreakGlass" | project UserDisplayName
Click Run.
In the toolbar, click New alert rule.
On the Create alert rule page, verify that the scope is correct.
Under Condition, click: Whenever the average custom log search is greater than
logic undefined
countOn the Configure signal logic page, in the Alert logic section, perform the following steps:
As Based on, select Number of results.
As Operator, select Greater than.
As Threshold value, select 0.
On the Configure signal logic page, in the Evaluated based on section, perform the following steps:
As Period (in minutes), select 5.
As Frequency (in minutes), select 5.
Click Done.
Under Action group, click Select action group.
On the Select an action group to attach to this alert rule, click Create action group.
On the Create action group page, perform the following steps:
In the Action group name textbox, type My action group.
In the Display name textbox, type My action.
Click Review + create.
Click Create.
Under Customize action, perform the following steps:
Select Email subject.
In the Subject line textbox, type:
Breakglass account has been used
Under Alert rule details, perform the following steps:
In the Alert rule name textbox, type:
Breakglass account
In the Description textbox, type:
Your emergency access account has been used
Click Create alert rule.
Create a custom workbook
This procedure shows how to create a new workbook using the quickstart template.
Sign in to the Azure portal as a global administrator.
Search for Azure Active Directory.
In the Monitoring section, click Workbooks.
In the Quickstart section, click Empty.
Click Add.
Click Add text.
In the textbox, type:
# Client apps used in the past week
, and then click Done Editing.In the new workbook, click Add, and then click Add query.
In the query textbox, type:
SigninLogs | where TimeGenerated > ago(7d) | project TimeGenerated, UserDisplayName, ClientAppUsed | summarize count() by ClientAppUsed
Click Run Query.
In the toolbar, under Visualization, click Pie chart.
Click Done Editing.
Add a query to a workbook template
This procedure shows how to add a query to an existing workbook template. The example is based on a query that shows the distribution of conditional access success to failures.
Sign in to the Azure portal as a global administrator.
Search for Azure Active Directory.
In the Monitoring section, click Workbooks.
In the conditional access section, click Conditional Access Insights and Reporting.
In the toolbar, click Edit.
In the toolbar, click the three dots, then Add, and then Add query.
In the query textbox, type:
SigninLogs | where TimeGenerated > ago(20d) | where ConditionalAccessPolicies != "[]" | summarize dcount(UserDisplayName) by bin(TimeGenerated, 1d), ConditionalAccessStatus
Click Run Query.
Click Time Range, and then select Set in query.
Click Visualization, and then select Bar chart.
Click Advanced Settings, as chart title, type
Conditional Access status over the last 20 days
, and then click Done Editing.
Next steps
Advance to the next article to learn how to manage device identities by using the Azure portal.
Feedback
Submit and view feedback for