Setup Alertmanager in Microsft Azure (WebApp) using Azure CLI
Tags: azure, monitoring, tutorial, codenewbie
Published: 2022-07-25 12:41:45

**Goal :**

- Create Alertmanager WebApp in Microsoft Azure using Azure CLI

**Pre-Requisite :** 

- [Deploying Alertmanager Image to Azure Container Registry Using Azure CLI](https://dev.to/suryabhansv/deploying-alertmanager-image-to-azure-container-registry-using-azure-cli-1mlb)

**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"
```



```
#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"
```

```
#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"

```



```
#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"
```

* 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'
```


![alertmanager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7fumk1zlkct86s4mmtgr.png)
![alertmanager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwa9bktb6pxukukwtn2n.png)


> * [Example file config.yml (Documentation)](https://raw.githubusercontent.com/prometheus/alertmanager/main/doc/examples/simple.yml)


**Output :**


![alertmanager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sh9n7rjhek90qnle44kp.png)
![alertmanager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxqqe354jsedslxx4o79.png)
![alertmanager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/829gebjnc0z3f00jfxs0.png)
![alertmanager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4z3uz7k1vwkid7t7t7q7.png)