Search code examples
azureazure-blob-storageazure-container-serviceazure-alerts

Azure Blob Container Alert if specific container folder is not updated in 24hrs


I am wanting to find a way to send an alert if a specific folder in a blob container is not updated within 24 hours. I have tried setting up an alert through the portal, but I can only seem to find Metric alerts based on Ingress of the entire blob container. Is there a way to specify Ingress on a folder within the container?

I am wanting to do this through the Alerts tab in the portal, but if I have to resort to writing code I can go that route also.

Here is a picture of what I have tried so far: Blob Container Ingress Alert


Solution

  • Seems there is no out-of-box solution to monitor a folder in Azure storage container in Azure alert.

    Based on your requirement, you want to send an alert if there is no modification in a folder over 24 hours. So we can just get the latest modification time in this folder and compare to the current time. You can try this powershell below :

    $storageAccount = "<your storage account>"
    $resourceGroup = "<your resource group name>"
    $containerName = "<container name>"
    $folderName = "<folder name>"
    $storage = Get-AzStorageAccount -name $storageAccount -ResourceGroupName $resourceGroup
    
    $lastModifyTimeInFolder = (Get-AzStorageBlob -Prefix $folderName -Container $containerName -Context $storage.Context | Sort-Object -Property LastModified -Descending)[0].LastModified
    $now = Get-Date
    
    
    if($lastModifyTimeInFolder.CompareTo($now.AddHours(-24)) -ge 0){
    echo "modified within 24hs"
    }else {
    #if last $lastModifyTimeInFolder less than current time minus 24 hours, you can trigger your own alert based on your logic here 
    echo "modified exceeded 24hs "
    }
    

    You can create a runbook in Azure automation as a scheduled task i,e run this script each 30 mins to implement your requirement.

    Hope it helps.