How can i create an Azure alert when user logs into a VM?

49 views Asked by At

I want to create an alert ie send an email as soon as anyone logs into an Azure Vm .

I have tried to create the alert but there is no "Sign In" alert.

How can i do this in Azure Portal ?

1

There are 1 answers

2
Venkat V On

How can i create an Azure alert when user logs into a VM?

To create an alert when a user logs into a VM, you can follow the steps below.

  1. Navigate to the VM > Logs and enable the logs. Once the logs are enabled, it will take some time to synchronize them.

  2. Run the below KQL query to fetch the VM Connected logs

AzureActivity
| where OperationName  == "Connect" and ActivityStatus =="Succeeded"
| extend ResourceIdParts = split(_ResourceId, "/")
| extend VMName = tostring(ResourceIdParts[8])
| project TimeGenerated, OperationName, ActivityStatus, Caller, CallerIpAddress, VMName

Output:

enter image description here

  1. Create an alert configuration as per your requirement

enter image description here

  1. Create an action group with required email.

enter image description here

  1. You will receive an alert when you connect to VM.

enter image description here

Please refer to the Stack Link I provided in my answer for a similar requirement.