如果特定容器文件夹未在 24 小时内更新,则 Azure Blob 容器警报

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

我想找到一种方法来在 blob 容器中的特定文件夹未在 24 小时内更新时发送警报。我尝试通过门户设置警报,但我似乎只能找到基于整个 blob 容器入口的指标警报。有没有办法在容器内的文件夹上指定 Ingress?

我想通过门户中的“警报”选项卡来执行此操作,但如果我必须求助于编写代码,我也可以采用这种方式。

这是我迄今为止尝试过的图片:

似乎没有开箱即用的解决方案来监视 Azure 警报中 Azure 存储容器中的文件夹。

根据您的要求,您希望在文件夹中超过 24 小时没有修改时发送警报。所以我们可以只获取该文件夹中的最新修改时间并与当前时间进行比较。您可以在下面尝试这个 powershell :

$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 "
}

您可以每 30 分钟创建一个 runbook in Azure automation as a scheduled task i,e 运行 这个脚本来实现您的要求。

希望对您有所帮助。