Skip to content

Commit

Permalink
Initial policy template
Browse files Browse the repository at this point in the history
  • Loading branch information
arjenhuitema committed Aug 2, 2024
1 parent b28baef commit 6ccad82
Show file tree
Hide file tree
Showing 4 changed files with 1,571 additions and 0 deletions.
285 changes: 285 additions & 0 deletions tooling/generate-templates/policy/activity-administrative.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
{
"type": "Microsoft.Authorization/policyDefinitions",
"apiVersion": "2021-06-01",
"name": "##POLICY_NAME##",
"properties": {
"policyType": "Custom",
"mode": "All",
"displayName": "##POLICY_DISPLAY_NAME##",
"description": "##POLICY_DESCRIPTION##",
"metadata": {
"version": "1.0.0-preview",
"category": "##POLICY_CATEGORY##",
"preview": true,
"source": "https://github.com/Azure/azure-monitor-baseline-alerts/",
"alzCloudEnvironments": [
"AzureCloud"
],
"_deployed_by_amba": "True"
},
"parameters": {
"enabled": {
"type": "String",
"metadata": {
"displayName": "Alert State",
"description": "Alert state for the alert"
},
"allowedValues": [
"true",
"false"
],
"defaultValue": "true"
},
"alertResourceGroupName": {
"type": "String",
"metadata": {
"displayName": "Resource Group Name",
"description": "Resource group the alert is placed in"
},
"defaultValue": "rg-amba-monitoring-001"
},
"alertResourceGroupTags": {
"type": "Object",
"metadata": {
"displayName": "Resource Group Tags",
"description": "Tags on the Resource group the alert is placed in"
},
"defaultValue": {
"Project": "amba-monitoring"
}
},
"alertResourceGroupLocation": {
"type": "String",
"metadata": {
"displayName": "Resource Group Location",
"description": "Location of the Resource group the alert is placed in"
},
"defaultValue": "centralus"
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Effect of the policy"
},
"allowedValues": [
"deployIfNotExists",
"disabled"
],
"defaultValue": "deployIfNotExists"
},
"MonitorDisableTagName": {
"type": "String",
"metadata": {
"displayName": "ALZ Monitoring disabled tag name",
"description": "Tag name to disable monitoring. Set to true if monitoring should be disabled"
},
"defaultValue": "MonitorDisable"
},
"MonitorDisableTagValues": {
"type": "Array",
"metadata": {
"displayName": "ALZ Monitoring disabled tag values(s)",
"description": "Tag value(s) used to disable monitoring at the resource level. Set to true if monitoring should be disabled."
},
"defaultValue": [
"true",
"Test",
"Dev",
"Sandbox"
]
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "##RESOURCE_TYPE##"
},
{
"field": "[[concat('tags[', parameters('MonitorDisableTagName'), ']')]",
"notIn": "[[parameters('MonitorDisableTagValues')]"
}
]
},
"then": {
"effect": "[[parameters('effect')]",
"details": {
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"type": "Microsoft.Insights/activityLogAlerts",
"name": "##ALERT_NAME##",
"existenceScope": "resourceGroup",
"resourceGroupName": "[[parameters('alertResourceGroupName')]",
"deploymentScope": "subscription",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Insights/ActivityLogAlerts/enabled",
"equals": "[[parameters('enabled')]"
},
{
"count": {
"field": "Microsoft.Insights/ActivityLogAlerts/condition.allOf[*]",
"where": {
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Insights/ActivityLogAlerts/condition.allOf[*].field",
"equals": "category"
},
{
"field": "Microsoft.Insights/ActivityLogAlerts/condition.allOf[*].equals",
"equals": "Administrative"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Insights/ActivityLogAlerts/condition.allOf[*].field",
"equals": "operationName"
},
{
"field": "Microsoft.Insights/ActivityLogAlerts/condition.allOf[*].equals",
"equals": "##OPERATION_NAME##"
}
]
}
]
}
},
"equals": 2
}
]
},
"deployment": {
"location": "northeurope",
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertResourceGroupName": {
"type": "string"
},
"alertResourceGroupTags": {
"type": "object"
},
"alertResourceGroupLocation": {
"type": "string"
},
"enabled": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2020-10-01",
"name": "[[parameters('alertResourceGroupName')]",
"location": "[[parameters('alertResourceGroupLocation')]",
"tags": "[[parameters('alertResourceGroupTags')]"
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "##ALERT_NAME##",
"resourceGroup": "[[parameters('alertResourceGroupName')]",
"dependsOn": [
"[[concat('Microsoft.Resources/resourceGroups/', parameters('alertResourceGroupName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"enabled": {
"type": "string"
},
"alertResourceGroupName": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "microsoft.insights/activityLogAlerts",
"apiVersion": "2020-10-01",
"name": "##ALERT_NAME##",
"location": "global",
"tags": {
"_deployed_by_amba": true
},
"properties": {
"description": "##ALERT_DESCRIPTION##",
"enabled": "[[parameters('enabled')]",
"scopes": [
"[[subscription().id]"
],
"condition": {
"allOf": [
{
"field": "category",
"equals": "Administrative"
},
{
"field": "operationName",
"equals": "##OPERATION_NAME##"
},
{
"field": "status",
"containsAny": [
"succeeded"
]
}
]
},
"parameters": {
"enabled": {
"value": "[[parameters('enabled')]"
}
}
}
}
]
},
"parameters": {
"enabled": {
"value": "[[parameters('enabled')]"
},
"alertResourceGroupName": {
"value": "[[parameters('alertResourceGroupName')]"
}
}
}
}
]
},
"parameters": {
"enabled": {
"value": "[[parameters('enabled')]"
},
"alertResourceGroupName": {
"value": "[[parameters('alertResourceGroupName')]"
},
"alertResourceGroupTags": {
"value": "[[parameters('alertResourceGroupTags')]"
},
"alertResourceGroupLocation": {
"value": "[[parameters('alertResourceGroupLocation')]"
}
}
}
}
}
}
}
}
}
Loading

0 comments on commit 6ccad82

Please sign in to comment.