DEV Community

Dave Rendon ☁️
Dave Rendon ☁️

Posted on • Updated on

⚡ Leverage Serverless Microsoft Azure Functions and Azure Alerts to ensure application availability

Table Of Contents


Hello Folks!

On this article we will review how to effectively make use of Azure Functions and Azure alerts to ensure application availability. I will demonstrate how to leverage Azure Functions and Azure Alerts to enable an automated failover for a Virtual Machine on Azure.

While Azure Functions are intended for processing data, integrating systems, working with the internet-of-things (IoT), and building simple APIs and microservices, this approach is to validate the potential capabilities of serverless components.


While you can build redundancies at the virtual machine (VM), datacenter, and regional levels based on your business needs, in this case I had a very unlikely situation in which an organization was trying to use Azure Site Recovery to replicate the Kemp Virtual LoadMaster to a secondary region, however the mobility service Agentfrom the Azure Site Recovery to enable the replica wasn’t compatible with the Kemp load balancer for Azure.

01-Leverage Serverless Microsoft Azure Functions and Azure Alerts to ensure application availability-dave-rendon

This multinational professional services company that provides services in strategy, consulting, digital, technology and operations wanted to perform a Disaster Recovery solution for all their services living on a specific Azure US Region and try to minimize RPO/RTO by enabling Azure Site Recovery to a second US Region.

Given the limitations to install the mobility service agent on the Virtual Machine to enable the replica job, there are 2 potential solutions:

  1. Enable the LoadMaster GEO to distribute traffic across 2 Azure regions and then leverage 2 LoadMasters in HA mode to distribute traffic to the local servers and applications
  2. Leverage Serverless Microsoft Azure Functions and Azure Alerts to monitor the VM running on the primary site and in the case of a potential failure use the Azure Function to spin up the Infrastructure resources on the secondary region.

For the sake of this discussion I will demonstrate you how to leverage Serverless Microsoft Azure Functions and Azure Alerts and I suggest you to take a look on how to Azure Functions to start/stop resources.

With this approach you could enable a proactive monitoring and enable real time healthchecks on the primary Virtual Machine(VM), so that if the VM fails the healthcheck then you can trigger the Azure Function to start the VM on the second region

02-Leverage Serverless Microsoft Azure Functions and Azure Alerts to ensure application availability-dave-rendon

Leverage Serverless Microsoft Azure Functions to automate resource deployment via Azure Resource Manager


I assume you have the following:

  1. Active Azure Subscription.
  2. ARM Template(.json file) of your resource(s)

Steps to leverage Serverless Microsoft Azure Functions to automate resource deployment via Azure Resource Manager

  1. Provision Azure Function
  2. Configure Azure Function
  3. Configure Alerts on the resource:

Provision Azure Function

  • Go to the Azure Portal and create a new resource from Template:

Alt Text

Alt Text

Alt Text

Alt Text

  • Then click save

Alt Text

  • Now provide the parameters for your Azure Function as shown below:

Alt Text

TIP. "Azure Functions comes in two main flavors, consumption and dedicated. The difference between the two is important, choosing one over the other not only dictates the behavior of your application but also how you’re billed. The consumption plan is our “serverless” model, your code reacts to events, effectively scales out to meet whatever load you’re seeing, scales down when code isn’t running, and you’re billed only for what you use. Plus, all of this happens without you thinking about what Microsoft Azure is doing behind the scenes.

The dedicated plan on the other hand, involves renting control of a virtual machine. This control means you can do whatever you like on that machine. It’s always available and might make more sense financially if you have a function which needs to run 24/7."

  • Once provisioned you should see the Azure Function as below:

Alt Text

Configure Azure Function

  • Now click on create a new Function and select the HTTP Trigger type:

Alt Text

  • Now provide the name and authorization level for your Function and click create:

Alt Text

You should see the code below:

module.exports = async function(context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    if ( || (req.body && {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + ( ||
    } else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"

For the purpose of the demonstration just copy the code below which will redirect to the ARM template to provision the resources. In this case the Azure Function will redirect to the json that will be provisioned.

module.exports = function(context, req){
    var url = "";
    context.res =  {
        status: 302,
        headers: {
            Location: url
  • Now click Save and Run. For testing purposes you can get the URL from the Azure Function and execute it on your browser:

Alt Text

Alt Text

URL example:
  • Once you navigate to this url you should be redirected to the ARM deployment:

Alt Text

Configure alerts on the resource

  • Go to the Resource in this case the LoadMaster is living on a virtual machine, then scroll down on the main options blade and select Alerts, then click on "New alert rule" :

Alt Text

  • In order to create a rule you need to select the resource target, then validate a condition to trigger the alert and then define the actions you want to enable. Click Add under Condition:

Alt Text

  • Then choose the Percentage CPU metric

Alt Text

  • Now configure the alert logic. In this case we want to ensure that the resource is up and running so set the threshold to static and select the operator "less than", aggregation type "Average" and Value = 1

Alt Text

  • This will ensure that the alert will be triggered whenever the percentage cpu is less than 1 percent.

  • Now click on "Create action group" under Actions as shown below:

Alt Text

  • Provide the parameters for the action group as below:

Alt Text

  • Now associate the Azure Function to the Alert:

Alt Text

  • Now click OK twice.


  1. Ensure that the Resource in this case the VM is up and running
  2. Ensure that the alert is enabled
  3. Ensure that the Azure Function is enabled.

Test Process

  1. Stop the VM
  2. Review the Azure Function Live Metrics - you should see a incoming request
  3. Optionally execute manually the trigger on the Function.

See also

Top comments (0)