Giter Site home page Giter Site logo

azure-alert-dashboard-terraform's Introduction

Example: Setup Azure Dashboard and Alerts with Terraform

This is an example to show how Infrastructure as Code (IaC) can be used to create Azure Dashboards and Alerts.

The full example contains a azure pipeline definition so it can be executed as a pipeline in Azure DevOps. If used, a Service Connection in Azure DevOps needs to be created with the name MySubscription.

Dashboard

Complete flow of execution

azure-pipelines

  1. Create Resource Group and Storage Account to save Terraform State file.
  2. Initialize Terraform with backend in Azure
  3. Set some environment variables
  4. Do Terraform Plan
  5. Do Terraform Apply

Terraform

  1. Create an App Service and a SQL Database to have something to show in the Dashboard.
  2. Create the Dashboard (more info below)
  3. Create an Action Group that we be used to send Alerts to
  4. Create an Alert (more info below)

Dashboard

Terraform resource azurerm_dashboard is used to define a dashboard. Because the definition of a dashboard is done in json and can be rather large, a template file is used, dashboard-template.tpl, to store the dashboard definition.

Variables can be injected from the Terraform resource into the template file.

main.tf
resource "azurerm_dashboard" "dashboard" {
    ...
  dashboard_properties = templatefile("dashboard-template.tpl",
    {
      appservice_name  = azurerm_app_service.app_service.name
      ...
  })
}

dashboard-template.tpl
"metrics": [
    {
    "resourceMetadata": {
        "id": "${appservice_id}"
    },
    "name": "BytesReceived",
    "aggregationType": 1,
    "metricVisualization": {
        "displayName": "Data In",
        "resourceDisplayName": "${appservice_name}"
    }
    }
],
       

More information how the Dashboard Json in structured can be found here: Programmatically create Azure Dashboards.

Alerts

Terraform resource azurerm_monitor_metric_alert is used to define an alert.

TIP: Create the alert in the Azure Portal and export the ARM Template. Look into that template to find the right values that should be set in the Terraform resource.

Then create a monitor action group azurerm_monitor_action_group where the definition how the alert, if triggered, should be broadcasted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.