DEV Community

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

Posted on

Setup Blackbox Exporter in Microsft Azure (WebApp) using Azure CLI

Goal :

  • Create Blackbox Exporter 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    = "suryasblackboxexporter"
$WebAppName             = "suryawablackboxexporter"
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 blackboxexporter
az webapp create --resource-group $ResourceGroupName --name $WebAppName --plan $AppServicePlan -i "$ACRUrl/blackbox-exporter:SuryaLatest"
Enter fullscreen mode Exit fullscreen mode
#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/"
Enter fullscreen mode Exit fullscreen mode
#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"
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

blackboxexporter

Output :

blackboxexporter
blackboxexporter
blackboxexporter
blackboxexporter
blackboxexporter

Top comments (0)