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"
#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'
Output :
Top comments (0)