Setup Alertmanager in Microsft Azure (WebApp) using Azure CLI

suryabhansv

Suryabhan Singh Vaghela

Posted on July 25, 2022

Setup Alertmanager in Microsft Azure (WebApp) using Azure CLI

Goal :

  • Create Alertmanager WebApp in Microsoft Azure using Azure CLI

Pre-Requisite :

Resource will Create :

  • App Service plan
  • Storage account
  • App Service

Script

$ResourceGroupName      = "suryarg"
$LocationName           = "eastus2"
$ACRName                = "suryacr"
$ACRUrl                 = "$ACRName.azurecr.io"

$AppServicePlan         = "suryaasp"
$AppServicePlanSku      = "S1"
$StorageAccountName     = "suryastorageaccountsa"
$StorageAccountSku      = "Standard_ZRS"
$StorageAccountShare    = "suryasalertmanager"
$WebAppName             = "suryawaalertmanager"
Enter fullscreen mode Exit fullscreen mode
#Create App Service Plan
az appservice plan create --resource-group $ResourceGroupName --name $AppServicePlan --is-linux --sku $AppServicePlanSku    

#Create a Storage Account
az storage account create --resource-group $ResourceGroupName --name $StorageAccountName --kind StorageV2 --sku $StorageAccountSku

#Create an Storage Account File Share
az storage share-rm create --resource-group $ResourceGroupName --storage-account $StorageAccountName --name $StorageAccountShare --access-tier "TransactionOptimized" --quota 64

#Create an Webapp for alertmanager
az webapp create --resource-group $ResourceGroupName --name $WebAppName --plan $AppServicePlan -i "$ACRUrl/alertmanager:SuryaLatest"
Enter fullscreen mode Exit fullscreen mode
#Create Storage Mount for alertmanager WebApp
$storageaccountkey  =   $(az storage account keys list --resource-group $ResourceGroupName --account-name $StorageAccountName --query [0].value -o tsv)

az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "config" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/etc/alertmanager/"
az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "data" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/data"
az webapp config storage-account add --resource-group $ResourceGroupName --name $WebAppName --custom-id "alertmanager" --storage-type "AzureFiles" --share-name $StorageAccountShare --account-name $StorageAccountName --access-key $storageaccountkey  --mount-path "/config"

Enter fullscreen mode Exit fullscreen mode
#Set an Environment Variable for alertmanager WebApp
az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings WEBSITES_PORT=9093

#Set an Startup Commmand for alertmanager WebApp
az webapp config set --name $WebAppName --resource-group $ResourceGroupName --startup-file `
"--config.file=/etc/alertmanager/config.yml --storage.path=/alertmanager --cluster.advertise-address=0.0.0.0:9093"
Enter fullscreen mode Exit fullscreen mode
  • config.yml (Upload this file in suryasalertmanager Storage Account Share)
global:
  # The smarthost and SMTP sender used for mail notifications.
  resolve_timeout: 5m
  smtp_smarthost: 'localhost:25'
  smtp_from: 'alertmanager@example.org'
  smtp_auth_username: 'alertmanager'
  smtp_auth_password: 'password'
  smtp_require_tls: true


route:
  receiver: default
  group_by:
  - DiskUsage
  - WindowsMemoryUsage
  routes:
  - receiver: email-high
    match_re:
      alertname: '(DiskSpaceUsageAbove90%|critical_node_cpu_usage)'
      severity: '(critical)'
    continue: true

  - receiver: email-low
    match_re:
      alertname: '(DiskSpaceUsageAbove60%)'
      severity: '(warning)'
    continue: true
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 12h


inhibit_rules:
- source_match:
    severity: critical
  target_match:
    severity: warning
  equal:
  - DiskUsage
  - WindowsMemoryUsage

receivers:
- name: email-high
  email_configs:
  - send_resolved: true
    to: 'suryaalertmanager@high.com'


- name: email-low
  email_configs:
  - send_resolved: true
    to: 'suryaalertmanager@low.com'
Enter fullscreen mode Exit fullscreen mode

alertmanager
alertmanager

Output :

alertmanager
alertmanager
alertmanager
alertmanager

💖 💪 🙅 🚩
suryabhansv
Suryabhan Singh Vaghela

Posted on July 25, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related