Alerting Through Azure Logic Apps

As we know alerting is the most crucial part of any infrastructure, and it becomes even more challenging when our infrastructure grows since we cannot monitor everything every time. Every client wants to get notified by their own alerting system before their customer reaches out to them and informs “Hey this service is not working or I am not able to access XYZ service“.

Alerting helps to ensure that the system remains healthy, responsive, and secure. It’s an important part of any system that makes performance, availability, and efficiency high. An operator might need to be notified of the event that triggers the alert.

We can set up alerts in many ways, but in this blog, I will be focussing on setting up alerting through azure logic apps.

Azure provides multiple options to send an alert to the end user, maybe through email, Slack, Pagerduty, SMS, etc. In this blog, I will be explaining the way to send an alert through email, Slack, and Pagerduty.

What are alerts in Microsoft Azure?

Alerts proactively notify you when issues are found with your infrastructure or application using your monitoring data in Azure Monitor. They allow you to identify and address issues before the users of your system notice them.

Azure provides the option to send alerts through Azure Monitor Service, You can easily find the Azure Alert option under Azure monitor. The below diagram represents the flow of alerts through Azure Monitor without using the Azure Logic Apps. You can use this service to send an alert through email or Pagerduty.

Alerting in Azure without using Azure Logic Apps

Steps To Send Alert without using Azure Logic Apps

  1. First, choose a target resource that defines the scope and signals available for alerting. A target can be any Azure resource. Example targets:
  • Virtual machines.
  • Storage accounts etc.

Let’s take an example of Azure Virtual Machine.

a) Go to Alerts

2. Select Create Option where you will need to create the condition and action.

Condition is a combination of signal and logic applied to a target resource. Examples:

  • Percentage CPU > 80%

c) After creating the condition, you will need to create an action group.

An action group is a combination of actions that will be taken, once the condition becomes true. Below is the snapshot of creating the action group.

Here if you want to send the alerts through email, SMS or voice then please go to the notification and select the option according to your choice of notification.


If you want to send the alert through the below options, you can choose any one from below. Suppose you want to send the alert through PagerDuty then just enter the webhook of the same in the webhook option.

Now come to alerting through the Azure Logic app. Please select the Azure Logic app and save it if you want to send the notification using the same.

What is Azure Logic App

Azure Logic Apps are Microsoft Azure’s Integration and Workflow offering in the Cloud. Azure Logic Apps makes use of connectors, Connectors are hosted services that allow accessing events, data, and actions across numerous services, APIs, and platforms.

An example would be a connector to the Slack service if you want to send the notifications through slack.

You can see the typical architecture of alerting through azure logic apps below:

Alerting in Azure using logic apps

Why send alerts using Azure Logic Apps

We can send alerts in many different ways but sometimes sending alert through Azure Logic apps becomes a compulsion when we want to send alerts of any Azure own Service which do not support any third-party agent integration.

Another scenario can be if you want to create a ticket of Azure service alerts through a ticket management system such as ServiceNow you will find the option of choosing the Azure Logic app more conveniently, we already have a blog for this scenario which you can follow for your implementation. Please click here to visit our blog on ServiceNow Integration through the Azure Logic app.

How to Create Azure Logic App

Take a scenario of getting the alerts using the Azure Logic App for increased CPU utilization of more than 80%.

1. Search Azure Logic App and click on add.

Select the desired options then click review & Create.

2. Logic apps are created using the Azure Portal Logic App designer. Once your Logic app has been created click on the “Logic App Designer” item in the left-hand pane under the heading “Deployment Tools”. This will bring up the designer.

As can be seen from the above screenshot, the designer comes with preconfigured template triggers to get you started. In this example, we want to build a workflow using two triggers, “When an HTTP Request is received” and “condition”.

3. Select “HTTP Request is received” and paste the below schema to declare the variables and their data type, this will help you to fetch the values of different azure metrics.

{
    "properties": {
        "data": {
            "properties": {
                "context": {
                    "properties": {
                        "condition": {
                            "properties": {
                                "allOf": {
                                    "items": {
                                        "properties": {
                                            "dimensions": {
                                                "items": {
                                                    "properties": {
                                                        "name": {
                                                          "type": "string"
                                                        },
                                                        "value": {
                                                          "type": "string"
                                                        }
                                                    },
                                                    "required": [
                                                        "name",
                                                        "value"
                                                    ],
                                                    "type": "object"
                                                },
                                                "type": "array"
                                            },
                                            "metricName": {
                                                "type": "string"
                                            },
                                            "metricValue": {
                                                "type": "integer"
                                            },
                                            "operator": {
                                                "type": "string"
                                            },
                                            "threshold": {
                                                "type": "string"
                                            },
                                            "timeAggregation": {
                                                "type": "string"
                                            }
                                        },
                                        "required": [
                                            "metricName",
                                            "dimensions",
                                            "operator",
                                            "threshold",
                                            "timeAggregation",
                                            "metricValue"
                                        ],
                                        "type": "object"
                                    },
                                    "type": "array"
                                },
                                "windowSize": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        },
                        "conditionType": {
                            "type": "string"
                        },
                        "description": {
                            "type": "string"
                        },
                        "id": {
                            "type": "string"
                        },
                        "name": {
                            "type": "string"
                        },
                        "portalLink": {
                            "type": "string"
                        },
                        "resourceGroupName": {
                            "type": "string"
                        },
                        "resourceId": {
                            "type": "string"
                        },
                        "resourceName": {
                            "type": "string"
                        },
                        "resourceType": {
                            "type": "string"
                        },
                        "subscriptionId": {
                            "type": "string"
                        },
                        "timestamp": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "properties": {
                    "properties": {},
                    "type": "object"
                },
                "status": {
                    "type": "string"
                },
                "version": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "schemaId": {
            "type": "string"
        }
    },
    "type": "object"
}

Now Click on Next Step and select for each

Select all to receive all the output from the previous step, then select HTTP to post a message to slack.

Now Save and test the logic app, You should receive an alert on your slack channel.

Conclusion

In this blog we have learned about alerting and ways of sending the notification through Azure Alerts, We learned about sending alerts with or without using Azure Logic apps. I will be back with more use cases of the same till then please keep learning.

Happy Learning!!!!!!

References:https://docs.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-overview


Blog Pundit:  Bhupender rawat and Sandeep Rawat

Opstree is an End to End DevOps solution provider

Connect Us

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: