Use Logic App to monitor Application Gateway Backend Health
Problem statement:
While Azure Application Gateway probes backend health and reports the status, it does not log failed health probe requests. These logs if stored can help you to diagnose problems with the backend.
Even more, if the backend is failing intermittently, it would be difficult to diagnose without the failure logs.
Solution:
Trigger an Azure Logic App whenever there is an alert for Unhealthy Backend Host count from Metrics and use the Azure Application Gateway Backend Health REST API to the ingest logs into a custom table in Log Analytics workspace.
Please find below steps to configure the above flow:
- Create Logic App in Consumption Plan
- Add a Managed Identity for the Logic App
- Use Manual Trigger.
- The following steps are used in logic App
- Initialize the variables – Affected Resources, Final Response , Response Body, Sub ID, App Gateway name and Location (the header value in response incase we get 201/202, will explain this down the line).
- Add action ‘HTTP’ to send the HTTP request for backend health API , use Managed Identity for authentication.
Note - Azure Application Gateway Backend Health REST API will run asynchronously with 202 response code. Among the header values, you will see:
Location: https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Network/locations/{region}/operationResults/{operation-id}?api-version=2023-09-01To check the status of the asynchronous operation, send another request to that URL:
GET https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Network/locations/{region}/operationResults/{operation-id}?api-version=2023-09-01 - If the response is 200, get set final response as yes and set the response body from the response.
- If the response is 202, you must send the request again with the header value in ‘location’ until you get 200 as explained above in the Note.
- Once you get the proper response, we must use ‘parse JSON’ action to format and fetch required information from the response.
Note - You can create a schema by using a sample response. - There might be multiple backends which are failing, so start for loop for each unhealthy backend
- Send the details to log analytics workspace custom table using “Send Data” action which uses log analytics connector.
- Send the details to log analytics workspace custom table using “Send Data” action which uses log analytics connector.
The below JSON can be used in code view to get started:
Save and then edit the following to make the Logic App working.
- Update authentication in all HTTP action to Managed Identity of logic app.
- Delete the Send data and add again. This will help to create a log Analytics connector by giving the Log analytics workspace ID and key.
- Either add all the log details in header of send data as below screenshot or edit the logic app in code view to copy paste the Header value from the above sample JSON.
Configure Azure monitor Alert to trigger the Logic App
Configure alert for signal unhealthy host count,
In the actions, create action group and select Action type as logic app, select the logic app created.
Enable automatically resolve , else it will be triggered multiple times.
The logs generated would look like below:
Published on:
Learn moreWe can help you with Use Logic App to monitor Application Gateway Backend Health
If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.
Related posts
Routing options for VMs from Private Subnets
Virtual Machines deployed in Azure used to have Default Outbound Internet Access. Until today, this allows virtual machines to connect to...
Secure, High-Performance Networking for Data-Intensive Kubernetes Workloads
The intersection of Generative AI and cloud computing has been transforming how organizations build and manage their infrastructure. The deman...
Network Connectivity for RISE with SAP S/4HANA Cloud Private Edition on Azure
In this article, we will explore different ways to connect to RISE with SAP S/4HANA Cloud Private Edition deployment on Azure, guiding yo...
Optimize Azure Landing Zone with Azure Virtual Network Manager IP Address Management
Optimize Azure Landing Zone with Azure Virtual Network Manager IP Address Management What you will learn from this blog This blog explores how...
ExpressRoute Metro is now generally available!!
We are excited to announce general availability of ExpressRoute Metro, a new private connectivity architecture designed to enhance network res...
ExpressRoute guided configuration of multi-site circuits and connections is generally available
ExpressRoute guided experience for configuring multi-site resiliency circuits and connections is generally available in Azure public cloud. Th...
Manage NSG association on Subnets via Azure Policy
In this blog article, we will cover how to deny the creation of a subnet in a Virtual Network if the subnet does not have a Network Sec...
Effortless Private Endpoint Management in Azure Landing Zones: A Streamlined and Compliant Approach
1. Challenge In Azure Landing Zones, the network infrastructure, including components like VNET Gateways and ExpressRoute circuits, is part of...
Unlocking Secure VM Connectivity with Azure Bastion
In today’s digital landscape, where security breaches are an unfortunate reality, safeguarding sensitive data and infrastructure has become mo...
Use cases of Advanced Network Observability for your Azure Kubernetes Service clusters
Introduction Advanced Network Observability is the inaugural feature of the Advanced Container Networking Services (ACNS) suite bringing...