Check! Notify the Azure cost alert to Slack via webhook

Kazumi IWANAGA (OHIRA)
3 min readAug 10, 2020

--

If you would like to notify a cost alert of Azure to Slack, this article would help you.

To prepare cost alerts notification to Slack, you should create these resources.

  • An action group with webhook receiver
  • A budget with cost alerts

See following documents to prepare these resources. But you would wonder what URI should be set the Webhook URI?

Webhook settings of action group in Azure portal

You cannot set the Slack webhook directly. Because the Slack webhook expect the schema with text , but the schema of cost alert doesn’t have the text field. So you have to convert the cost alert to Slack incoming schema.

For that, I’ll make a small function on Azure Functions. To see the sample code, it’s here.

Here is the schema of cost alert webhook notification.

I convert the schema like below. This is just a sample, see full code in here.

If you use “common alert schema”, refer the following document for the schema.

And if you would like to decorate the notification to Slack, see Slack Block Kit Builder.

Next, you hove to retrieve the Slack Incoming Webhook URL. See below for detail.

Then, deploy the Functions to Azure.

In the my sample code, you have to set a variable slackWebhookUrl in Application Settings with the Slack Incoming Webhook URL (You already would have the URL above). I prepared the ARM template, so refer the README on the top of the repository if you would like to use it.

After deployed the function to Azure, specify the function URL in the webhook URI of the action group for the cost alert.

The alert will be sent to your Slack channel.

Prologue

I tried to create ARM templates to deploy these resources. But, currently an Unauthorized error occurs in creating budget in a subscription of Pay as you go account. The creating budget is available on Enterprise Agreement scope. See the following document for detail.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Kazumi IWANAGA (OHIRA)
Kazumi IWANAGA (OHIRA)

Written by Kazumi IWANAGA (OHIRA)

Hello! :) I’m a developer, Microsoft MVP(Azure). My interests: Azure, Serverless, IaC, Container, IoT, and other many exciting things!

Responses (1)

Write a response