Coder Social home page Coder Social logo

globalbao / terraform-azurerm-monitor Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 5.0 11 KB

Terraform module for managing Azure Monitor metric alerts - by @JesseLoudon

Home Page: https://jloudon.com

License: MIT License

HCL 100.00%
terraform-module azurerm azure-monitor-metrics azurerm-monitor gitops azure-action-group azure-governance hcl terraform

terraform-azurerm-monitor's Introduction

AzureRM Monitor - Terraform parent module

Terraform resources/variables

See child module READMEs

Example usage to call child modules

terraform {
  required_version = "~> 0.13.0"
  required_providers {
    azurerm = "~> 2.25.0"
  }
}

provider "azurerm" {
  features {
  }
}

module "azmonitor-action-groups" {
  source = "git::ssh://git@https://github.com/globalbao/terraform-azurerm-monitor//modules/AzMonitor-ActionGroups?ref=v1.0"

  tags = {
    Application = "Azure Monitor Alerts"
    CostCentre  = "123"
    Environment = "dev"
    ManagedBy   = "Jesse Loudon"
    Owner       = "Jesse Loudon"
    Support     = "[email protected]"
  }

  actionGroups = {
    "group1" = {
      actionGroupName      = "AlertEscalationGroup"
      actionGroupShortName = "alertesc"
      actionGroupRGName    = "AzMonitorAlertGroups"
      actionGroupEnabled   = "true"
      actionGroupEmailReceiver = [
        {
          name                    = "jloudon"
          email_address           = "[email protected]"
          use_common_alert_schema = "true"
        }
      ]
    },
    "group2" = {
      actionGroupName      = "AlertOperationsGroup"
      actionGroupShortName = "alertops"
      actionGroupRGName    = "AzMonitorAlertGroups"
      actionGroupEnabled   = "true"
      actionGroupEmailReceiver = [
        {
          name                    = "jloudon"
          email_address           = "[email protected]"
          use_common_alert_schema = "true"
        }
      ]
    }
  }
}

module "azmonitor-metric-alerts" {
  source = "git::ssh://git@https://github.com/globalbao/terraform-azurerm-monitor//modules/AzMonitor-MetricAlerts?ref=v1.0"

  tags = {
    Application = "Azure Monitor Alerts"
    CostCentre  = "123"
    Environment = "dev"
    ManagedBy   = "Jesse Loudon"
    Owner       = "Jesse Loudon"
    Support     = "[email protected]"
  }

  alertScope = {
    "resource1" = {
      resourceName  = "azmonloadbalancer1"
      resourceGroup = "DevResources"
      resourceType  = "Microsoft.Network/loadBalancers"
    },
    "resource2" = {
      resourceName  = "azmonappgateway1"
      resourceGroup = "DevResources"
      resourceType  = "Microsoft.Network/appGateway"
    },
    "resource3" = {
      resourceName  = "azmonsqldb1"
      resourceGroup = "DevResources"
      resourceType  = "Microsoft.Sql/servers/databases"
    }
  }

  metricAlerts = {
    "alert1" = {
      alertName              = "azmonloadbalancer1-DipAvailability"
      alertResourceGroupName = "DevResources"
      alertScopes = [
        module.azmonitor-metric-alerts.alert-scope["0"].resource1.resources[0].id
      ]
      alertDescription            = "Average Load Balancer health probe status per time duration"
      alertEnabled                = "true"
      alertAutoMitigate           = "true"
      alertFrequency              = "PT15M"
      alertWindowSize             = "PT1H"
      alertSeverity               = "2"
      alertTargetResourceType     = "Microsoft.Network/loadBalancers"
      alertTargetResourceLoc      = "australiaeast"
      dynCriteriaMetricNamespace  = "Microsoft.Network/loadBalancers"
      dynCriteriaMetricName       = "DipAvailability"
      dynCriteriaAggregation      = "Average"
      dynCriteriaOperator         = "LessThan"
      dynCriteriaAlertSensitivity = "Medium"
      dynCriteriaDimensions = [
        {
          name     = "ProtocolType"
          operator = "Include"
          values   = "*"
        },
        {
          name     = "FrontendIPAddress"
          operator = "Include"
          values   = "*"
        },
        {
          name     = "BackendIPAddress"
          operator = "Include"
          values   = "*"
        },
      ]
      actionGroupID = module.azmonitor-action-groups.ag["0"].group1.id
    },
    "alert2" = {
      alertName              = "azmonloadbalancer1-VipAvailability"
      alertResourceGroupName = "DevResources"
      alertScopes = [
        module.azmonitor-metric-alerts.alert-scope["0"].resource1.resources[0].id
      ]
      alertDescription            = "Average Load Balancer data path availability per time duration"
      alertEnabled                = "true"
      alertAutoMitigate           = "true"
      alertFrequency              = "PT15M"
      alertWindowSize             = "PT1H"
      alertSeverity               = "2"
      alertTargetResourceType     = "Microsoft.Network/loadBalancers"
      alertTargetResourceLoc      = "australiaeast"
      dynCriteriaMetricNamespace  = "Microsoft.Network/loadBalancers"
      dynCriteriaMetricName       = "VipAvailability"
      dynCriteriaAggregation      = "Average"
      dynCriteriaOperator         = "LessThan"
      dynCriteriaAlertSensitivity = "Medium"
      dynCriteriaDimensions = [
        {
          name     = "FrontendPort"
          operator = "Include"
          values   = "*"
        },
        {
          name     = "FrontendIPAddress"
          operator = "Include"
          values   = "*"
        },
      ]
      actionGroupID = module.azmonitor-action-groups.ag["0"].group2.id
    },
    "alert3" = {
      alertName              = "azmonappgateway1-UnhealthyHostcount"
      alertResourceGroupName = "DevResources"
      alertScopes = [
        module.azmonitor-metric-alerts.alert-scope["0"].resource2.resources[0].id
      ]
      alertDescription            = "Current UnhealthyHostcount of the Application Gateway"
      alertEnabled                = "true"
      alertAutoMitigate           = "true"
      alertFrequency              = "PT15M"
      alertWindowSize             = "PT1H"
      alertSeverity               = "2"
      alertTargetResourceType     = "Microsoft.Network/applicationGateways"
      alertTargetResourceLoc      = "australiaeast"
      dynCriteriaMetricNamespace  = "Microsoft.Network/applicationGateways"
      dynCriteriaMetricName       = "UnhealthyHostcount"
      dynCriteriaAggregation      = "Average"
      dynCriteriaOperator         = "GreaterThan"
      dynCriteriaAlertSensitivity = "Medium"
      dynCriteriaDimensions = [
        {
          name     = "BackendSettingsPool"
          operator = "Include"
          values   = "*"
        }
      ]
      actionGroupID = module.azmonitor-action-groups.ag["0"].group1.id
    },
    "alert4" = {
      alertName              = "azmonappgateway1-FailedRequests"
      alertResourceGroupName = "DevResources"
      alertScopes = [
        module.azmonitor-metric-alerts.alert-scope["0"].resource2.resources[0].id
      ]
      alertDescription            = "Count of failed requests that Application Gateway has served"
      alertEnabled                = "true"
      alertAutoMitigate           = "true"
      alertFrequency              = "PT15M"
      alertWindowSize             = "PT1H"
      alertSeverity               = "2"
      alertTargetResourceType     = "Microsoft.Network/applicationGateways"
      alertTargetResourceLoc      = "australiaeast"
      dynCriteriaMetricNamespace  = "Microsoft.Network/applicationGateways"
      dynCriteriaMetricName       = "FailedRequests"
      dynCriteriaAggregation      = "Total"
      dynCriteriaOperator         = "GreaterThan"
      dynCriteriaAlertSensitivity = "Medium"
      dynCriteriaDimensions = [
        {
          name     = "BackendSettingsPool"
          operator = "Include"
          values   = "*"
        }
      ]
      actionGroupID = module.azmonitor-action-groups.ag["0"].group1.id
    }
  }

  metricAlerts-noDimensions = {
    "alert1" = {
      alertName              = "azmonsqldb1-avg_cpu_percent"
      alertResourceGroupName = "DevResources"
      alertScopes = [
        module.azmonitor-metric-alerts.alert-scope["0"].resource3.resources[0].id
      ]
      alertDescription            = "Average CPU percentage"
      alertEnabled                = "true"
      alertAutoMitigate           = "true"
      alertFrequency              = "PT15M"
      alertWindowSize             = "PT1H"
      alertSeverity               = "3"
      alertTargetResourceType     = "Microsoft.Sql/managedInstances"
      alertTargetResourceLoc      = "australiaeast"
      dynCriteriaMetricNamespace  = "Microsoft.Sql/managedInstances"
      dynCriteriaMetricName       = "avg_cpu_percent"
      dynCriteriaAggregation      = "Average"
      dynCriteriaOperator         = "GreaterThan"
      dynCriteriaAlertSensitivity = "Medium"
      actionGroupID               = module.azmonitor-action-groups.ag["0"].group2.id
    }
  }
}

Modifying this repository

  • If changes are made to .tf files it's best practice to use terraform fmt and terrform validate afterwards.
terraform fmt -recursive
terraform validate

terraform-azurerm-monitor's People

Contributors

jesseloudon avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.