Gallery › Monitoring › Azure Community Policy
Audit configuration of metric alert rules on Batch accounts
Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0
Audit configuration of metric alert rules on Batch account to enable the required metric
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 63 lines
{
"name": "7925eb48-584b-4ef2-a45e-fcdc80df9de3",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Audit configuration of metric alert rules on Batch accounts",
"description": "Audit configuration of metric alert rules on Batch account to enable the required metric",
"metadata": {
"category": "Monitoring",
"version": "1.0.0"
},
"mode": "Indexed",
"parameters": {
"metricName": {
"type": "String",
"metadata": {
"displayName": "Metric name",
"description": "The metric name that an alert rule must be enabled on. See https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-supported-metrics#microsoftbatchbatchaccounts for a list of metrics."
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Batch/batchAccounts"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/alertRules",
"existenceScope": "Subscription",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Insights/alertRules/isEnabled",
"equals": "true"
},
{
"field": "Microsoft.Insights/alertRules/condition.dataSource.metricName",
"equals": "[parameters('metricName')]"
},
{
"field": "Microsoft.Insights/alertRules/condition.dataSource.resourceUri",
"equals": "[concat('/subscriptions/', subscription().subscriptionId, '/resourcegroups/', resourceGroup().name, '/providers/Microsoft.Batch/batchAccounts/', field('name'))]"
}
]
}
}
}
}
}
}Bylaw7925eb48-584b-4ef2-a45e-fcdc80df9de3.bylaw.ps1 · 33 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '7925eb48-584b-4ef2-a45e-fcdc80df9de3' {
Properties @{
DisplayName = 'Audit configuration of metric alert rules on Batch accounts'
Description = 'Audit configuration of metric alert rules on Batch account to enable the required metric'
Category = 'Monitoring'
Version = '1.0.0'
Mode = 'Indexed'
}
Parameter MetricName @{
Type = 'String'
DisplayName = 'Metric name'
Description = 'The metric name that an alert rule must be enabled on. See https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-supported-metrics#microsoftbatchbatchaccounts for a list of metrics.'
}
Parameter Effect @{
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Batch/batchAccounts'
AuditIfNotExists 'Microsoft.Insights/alertRules' -ExistenceScope Subscription -Effect (Param Effect) {
Require 'isEnabled, condition.dataSource.metricName, condition.dataSource.resourceUri and 1 more are as required' {
Field 'Microsoft.Insights/alertRules/isEnabled' -AllowUnknownAlias | Must -Be 'true'
Field 'Microsoft.Insights/alertRules/condition.dataSource.metricName' -AllowUnknownAlias | Must -Be (Param MetricName)
Field 'Microsoft.Insights/alertRules/condition.dataSource.resourceUri' -AllowUnknownAlias | Must -Be (Arm '[concat(''/subscriptions/'', subscription().subscriptionId, ''/resourcegroups/'', resourceGroup().name, ''/providers/Microsoft.Batch/batchAccounts/'', field(''name''))]')
}
}
}Source: policyDefinitions/Monitoring/audit-configuration-of-metric-alert-rules-on-batch-accounts/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw