I have an NSG that I need to monitor for any changes to the inbound or outbound rules. I've tried the pre-canned NSG update/modify alert type, but that doesn't seem to capture NSG rules updates. From the activity log, I can see my changes to individual NSG
rules and create an alert for that specific rule, but that doesn't help me monitor all of the rules at once, or any new rules that are created.
I found an ARM template online that will alert me on ANY NSG rule changes, but I only want to alert for one specific NSG. I exported the JSON for an alert I created to monitor one specific rule, and tried to blend the two templates together to make something
that will work for what I need, but I'm not having much luck.
Here's the template that alerts for ANY NSG rule changes:
{"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {"activityLogAlertName": {"type": "string","metadata": {"description": "Unique name (within the Resource Group) for the Activity log alert."
}
},"activityLogAlertEnabled": {"type": "bool","defaultValue": true,"metadata": {"description": "Indicates whether or not the alert is enabled."
}
},"actionGroupResourceId": {"type": "string","metadata": {"description": "Resource Id for the Action group."
}
}
},"resources": [
{"type": "Microsoft.Insights/activityLogAlerts","apiVersion": "2017-04-01","name": "[parameters('activityLogAlertName')]", "location": "Global","properties": {"enabled": "[parameters('activityLogAlertEnabled')]","scopes": ["[subscription().id]"
], "condition": {"allOf": [
{"field": "category","equals": "Administrative"
},
{"field": "operationName","equals": "Microsoft.Network/networkSecurityGroups/securityRules/write"
},
{"field": "resourceType","equals": "Microsoft.Network/networkSecurityGroups/securityRules"
}
]
},"actions": {"actionGroups":
[
{"actionGroupId": "[parameters('actionGroupResourceId')]"
}
]
}
}
}
]
}
And here's the template that alerts for one specific NSG rule:
{"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {"activityLogAlertName": {"type": "string","metadata": {"description": "Unique name (within the Resource Group) for the Activity log alert."
}
},"activityLogAlertEnabled": {"type": "bool","defaultValue": true,"metadata": {"description": "Indicates whether or not the alert is enabled."
}
},"actionGroupResourceId": {"type": "string","metadata": {"description": "Resource Id for the Action group."
}
}
},"resources": [
{"type": "Microsoft.Insights/activityLogAlerts","apiVersion": "2017-04-01","name": "[parameters('activityLogAlertName')]", "location": "Global","properties": {"enabled": "[parameters('activityLogAlertEnabled')]","scopes": ["[subscription().id]"
], "condition": {"allOf": [
{"containsAny": null,"equals": "Administrative","field": "category"
},
{"containsAny": null,"equals": "/subscriptions/<removed>/resourceGroups/RG_Test/providers/Microsoft.Network/networkSecurityGroups/NSG_TEST/securityRules/NSG_TEST_RULE","field": "resourceId"
},
{"containsAny": null,"equals": "Microsoft.Network/networkSecurityGroups/securityRules/write","field": "operationName"
},
{"containsAny": null,"equals": "informational","field": "level"
},
{"containsAny": null,"equals": "Succeeded","field": "status"
}
]
},"actions": {"actionGroups":
[
{"actionGroupId": "[parameters('actionGroupResourceId')]"
}
]
}
}
}
]
}
Could someone help me put together an ARM template that will alert me for any inbound or outbound rule changes (new, modify, delete) for one specific NSG?