How to setup an email alert for high Active Message count for Azure Service Bus Queue
Tags: azure, serverless, beginners
Published: 2020-10-13 02:12:09

>This post assumes that you have an Azure service bus namespace >setup with a Queue. Here is the official documentation for >instructions.

>I am going to use a service bus namespace AlertDemoServiceBus which >has a queue named Orders.

Lets start!

Login to you account and navigate to the service bus namespace.

Click on Alerts and New Alert Rule

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/p2avmjtsv0iowjkezs9v.png)

This should open a new alert rule page. Here, we select the resource, which is our service bus namespace. 

If have only 1 service queue, then it should auto-populate.
Now, we have to set the condition for alert rule.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5yak5kkoor8buvutd33p.png)

On click of select condition link, we get a new window in which we can setup the logic. 

We can setup alert on various signals as shown below but here we will using “Count of active messages in a Queue/Topics”

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uic3c6umv5la2676uyep.png)

Once we select the base signal, on the next page we can configure the logic as below.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8xcbrnj9zz0sir3vp1rb.png)

Here I am setting alert on Orders Entity with threshold as 1000 active message and the condition will be checked every 5 mins.

Next would be the part where we setup actual Alert email when the condition is met. We have to create an Alert Group to achieve that. 

This takes us through a wizard.
First step would be to name it. I am creating an alert with a name HighCntAlert

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zntyoz1g524fo2ikpkrl.png)

The next part would be setup notification.
Lets give it a name.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/m6d5w7azd6kx0se7gjj4.png)

And provide an email address to receive an alert

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nhz73flp2y56dm269b94.png)

>As we can notice here, we can also request for an SMS or voice message but it attracts extra charges.

Once its setup, we can click review and create. It should create an alert group with email as a notification option for us.
Give it a name and severity Level and enable it upon creation to start receiving alerts immediately .

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0nftncm3wt5owkevy4g0.png)

This should trigger a confirmation email.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/byfr2pynsq12z67mhl8h.png)

Once its ready, we should be able to see it under “Manage Alert Rules” menu.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v30ms7ak80cwcv73db52.png)

We are all setup!!
Now, when the queue count goes to 1000 as per our condition, Azure will create an alert. We can see this alert by navigating to “Alert” menu on the namespace.

>We have to wait for 5 mins for azure to trigger the condition as >we had configured in our rule above

After 5 mins, we can see an alert for Sev 2 raised for our queue in Alerts section of our service bus namespace.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n2s1sv56p0q1z4bofxbe.png)

And an email sent to our registered email address from azure-noreply@microsoft.com

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fwm7dyhdqmr8xtau0v6i.png)

In the details, notice the alert state.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/l6np0ybois2336s3seof.png)

Once the queue count goes down, the state automatically changes to Resolved

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1hxyyfvijiyo1z9g5xqz.png)

and we also get an email notification about this progress.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/o8wbak0x8xyxwcojifjt.png)

Hope this was helpful. I gladly appreciate your comments and feedback.

THANK YOU!!