Sunday, June 12, 2022

Azure Monitor Alert - Azure Function App

 1. Create a Windows Virtual Machine

2. Search for Function App and create a function by clicking on Create button.

3. Select the appropriate subscription, unique name of function and resource group, and RunTime stack as PowerShell Core and click on Review and Create.

4. Once the function is created then select Function from the left panel and select HTTP Trigger. Provide the name of the Function and click on Create button

5. Once the function is created then click on Code and Test, it will have some PowerShell Script so let's replace the existing script with the below code and click on the Save button.

  1. using namespace System.Net
  3. param($Request, $TriggerMetadata)
  5. $Request | ConvertTo-Json | Write-Output

6. Search for Monitor service and select Alert and create an alert rule for the virtual machine( assuming that you already have a virtual machine) resource.

7. Select the condition for the Metrics signal type and select Network Out Total. Select the threshold value as per your choice( I am selecting 1KB and granularity as 1 min and frequency as 1 min).

8. Create an action group with the valid subscription and resource group.No need to select the Notification as of now.

9. Select the action as Azure function and select your azure function and also select Yes for  Enable the common alert schema option and click on the Review + Create button. It will ask for the alert rule name so provide the name and click on Create button.

10. Once the Alert rule is created then you can notice in the Azure function something gets triggered.



Post a Comment