Setup Blackbox Exporter in Microsft Azure (WebApp) using Azure CLI
Tags: azure, monitoring, tutorial, beginners
Published: 2022-08-10 09:54:17

**Goal :**

- Create Blackbox Exporter WebApp in Microsoft Azure using Azure CLI

**Pre-Requisite :** 

- [Deploying Blackbox Exporter Image to Azure Container Registry Using Azure CLI](https://dev.to/suryabhansv/deploying-blackbox-exporter-image-to-azure-container-registry-using-azure-cli-5dii)

**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	= "suryasblackboxexporter"
$WebAppName				= "suryawablackboxexporter"
```



```
#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 blackboxexporter
az webapp create --resource-group $ResourceGroupName --name $WebAppName --plan $AppServicePlan -i "$ACRUrl/blackbox-exporter:SuryaLatest"
```

```
#Create Storage Mount for blackboxexporter 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 "/config/"
```



```
#Set an Environment Variable for blackboxexporter WebApp
az webapp config appsettings set --resource-group $ResourceGroupName --name $WebAppName --settings WEBSITES_PORT=9115

#Set an Startup Commmand for blackboxexporter WebApp
az webapp config set --name $WebAppName --resource-group $ResourceGroupName --startup-file `
"--config.file=/config/blackbox.yml"
```

* blackbox.yml (Upload this file in **suryasblackboxexporter** Storage Account Share)

```
modules:
  http_2xx:
    prober: http
  http_post_2xx:
    prober: http
    http:
      method: POST
  tcp_connect:
    prober: tcp
  pop3s_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^+OK"
      tls: true
      tls_config:
        insecure_skip_verify: false
  grpc:
    prober: grpc
    grpc:
      tls: true
      preferred_ip_protocol: "ip4"
  grpc_plain:
    prober: grpc
    grpc:
      tls: false
      service: "service1"
  ssh_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^SSH-2.0-"
      - send: "SSH-2.0-blackbox-ssh-check"
  irc_banner:
    prober: tcp
    tcp:
      query_response:
      - send: "NICK prober"
      - send: "USER prober prober prober :prober"
      - expect: "PING :([^ ]+)"
        send: "PONG ${1}"
      - expect: "^:[^ ]+ 001"
  icmp:
    prober: icmp
  icmp_ttl5:
    prober: icmp
    timeout: 5s
    icmp:
      ttl: 5
```


![blackboxexporter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/prx8ne5wl2z5lgmf678u.png)
  

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


**Output :**


![blackboxexporter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bg2dsrdaguru2za5w8z.png)
![blackboxexporter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s810l1yn7wsgi0bibgv2.png)
![blackboxexporter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ux4e38rtmkmmw1zqxd3j.png)
![blackboxexporter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8mvbye00g7zbfngfydrl.png)
![blackboxexporter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7dgrj2cojzav50w7jd6.png)