This custom alert utilizes the DM_DB_INDEX_PHYSICAL_STATS DMV to retrieve fragmentation information for all indexes within a database. Since this DMV only provides data specific to the current database, the script uses the sp_MSforeachdb procedure to collect information from all databases.
Note: the first script does not work for Azure SQL Databases because the sp_MSforeachdb procedure does not exist. However, the script contains another query at the bottom that can be used for Azure SQL Databases.
Set up the alert as a Custom SQL Multiple Numeric alert in DPA, resembling the following format: