DEV Community

Cover image for Setup Alertmanager in Microsft Azure (WebApp) using Azure CLI
Suryabhan Singh Vaghela
Suryabhan Singh Vaghela

Posted on

1 1

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay