Skip to content

Instantly share code, notes, and snippets.

@hawaku
Last active March 11, 2024 10:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hawaku/068136eec7b34048a7740c2de0066de6 to your computer and use it in GitHub Desktop.
Save hawaku/068136eec7b34048a7740c2de0066de6 to your computer and use it in GitHub Desktop.
Diagnostic setting for Azure Storage
param appPrefix string = '${uniqueString(resourceGroup().id)}'
param logAnalyticsWorkspaceName string = 'log-${appPrefix}'
param storageAccountName string = 'st${appPrefix}'
param location string = resourceGroup().location
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
name: logAnalyticsWorkspaceName
location: location
properties: {
sku: {
name: 'PerGB2018'
}
retentionInDays: 30
}
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: storageAccountName
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
tier: 'Standard'
}
}
resource storageAccount_diag 'microsoft.insights/diagnosticSettings@2017-05-01-preview' = {
scope: storageAccount
name: 'diag-${storageAccountName}'
properties: {
workspaceId: logAnalyticsWorkspace.id
metrics: [
{
category: 'Transaction'
enabled: true
}
]
}
}
resource storageAccountBlob 'Microsoft.Storage/storageAccounts/blobServices@2021-02-01' = {
parent: storageAccount
name: 'default'
properties: {}
}
resource storageAccountBlob_diag 'microsoft.insights/diagnosticSettings@2017-05-01-preview' = {
scope: storageAccountBlob
name: 'diag-${storageAccountBlob.name}'
properties: {
workspaceId: logAnalyticsWorkspace.id
logs: [
{
category: 'StorageRead'
enabled: true
}
{
category: 'StorageWrite'
enabled: true
}
{
category: 'StorageDelete'
enabled: true
}
]
metrics: [
{
category: 'Transaction'
enabled: true
}
]
}
}
resource storageAccountFile 'Microsoft.Storage/storageAccounts/fileServices@2021-02-01' = {
parent: storageAccount
name: 'default'
properties: {}
}
resource storageAccountFile_diag 'microsoft.insights/diagnosticSettings@2017-05-01-preview' = {
scope: storageAccountFile
name: 'diag-${storageAccountFile.name}'
properties: {
workspaceId: logAnalyticsWorkspace.id
logs: [
{
category: 'StorageRead'
enabled: true
}
{
category: 'StorageWrite'
enabled: true
}
{
category: 'StorageDelete'
enabled: true
}
]
metrics: [
{
category: 'Transaction'
enabled: true
}
]
}
}
resource storageAccountQueue 'Microsoft.Storage/storageAccounts/queueServices@2021-02-01' = {
parent: storageAccount
name: 'default'
properties: {}
}
resource storageAccountQueue_diag 'microsoft.insights/diagnosticSettings@2017-05-01-preview' = {
scope: storageAccountQueue
name: 'diag-${storageAccountQueue.name}'
properties: {
workspaceId: logAnalyticsWorkspace.id
logs: [
{
category: 'StorageRead'
enabled: true
}
{
category: 'StorageWrite'
enabled: true
}
{
category: 'StorageDelete'
enabled: true
}
]
metrics: [
{
category: 'Transaction'
enabled: true
}
]
}
}
resource storageAccountTable 'Microsoft.Storage/storageAccounts/tableServices@2021-02-01' = {
parent: storageAccount
name: 'default'
properties: {}
}
resource storageAccountTable_diag 'microsoft.insights/diagnosticSettings@2017-05-01-preview' = {
scope: storageAccountTable
name: 'diag-${storageAccountTable.name}'
properties: {
workspaceId: logAnalyticsWorkspace.id
logs: [
{
category: 'StorageRead'
enabled: true
}
{
category: 'StorageWrite'
enabled: true
}
{
category: 'StorageDelete'
enabled: true
}
]
metrics: [
{
category: 'Transaction'
enabled: true
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment