224 lines
9.6 KiB
Transact-SQL
224 lines
9.6 KiB
Transact-SQL
/*=============================================================================
|
|
|
|
Explication du traitement realise par le script
|
|
-------------------------------------------
|
|
1. Creation de la catégorie SQL Server Agent Alerts
|
|
2. Creation de l'opérateur DBA_operator
|
|
3. Creation de l'alerte Severité 19 Fatal Error in Resource
|
|
4. Creation de l'alerte Severité 20 Fatal Error in Current Process
|
|
5. Creation de l'alerte Severité 21 Fatal Error in Database Process
|
|
6. Creation de l'alerte Severité 22 Fatal Error Table Integrity Suspect
|
|
7. Creation de l'alerte Severité 23 Fatal Error Database Integrity Suspect
|
|
8. Creation de l'alerte Severité 24 Fatal Hardware Error
|
|
9. Creation de l'alerte Severité 25 Fatal Error
|
|
10. Création de l'alerte de l'erreur 825 Read-Retry Required
|
|
|
|
Creation : 06.06.2018 / FLA
|
|
|
|
Modifications : 17.03.2022 - FLA : Change DBA mail
|
|
|
|
=============================================================================*/
|
|
|
|
|
|
|
|
USE [msdb];
|
|
|
|
/* Add categorie for SQL Server Agent Alerts */
|
|
DECLARE @CategoryName sysname,
|
|
@OperatorName sysname,
|
|
@AlertName sysname
|
|
|
|
SET @CategoryName = N'SQL Server Agent Alerts';
|
|
SET @OperatorName = N'DBA_operator'
|
|
|
|
IF NOT EXISTS (SELECT *
|
|
FROM msdb.dbo.syscategories
|
|
WHERE category_class = 2 /*2=Alert*/
|
|
AND category_type = 3
|
|
AND name = @CategoryName)
|
|
BEGIN
|
|
EXEC dbo.sp_add_category @class = N'ALERT', @type = N'NONE', @name = @CategoryName;
|
|
END
|
|
|
|
/* Add operator DBA_operator for SQL Server Agent Alerts */
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysoperators WHERE name = N'DBA_operator')
|
|
EXEC msdb.dbo.sp_delete_operator @name=N'DBA_operator'
|
|
|
|
EXEC msdb.dbo.sp_add_operator @name=N'DBA_operator',
|
|
@enabled=1,
|
|
@weekday_pager_start_time=90000,
|
|
@weekday_pager_end_time=180000,
|
|
@saturday_pager_start_time=90000,
|
|
@saturday_pager_end_time=180000,
|
|
@sunday_pager_start_time=90000,
|
|
@sunday_pager_end_time=180000,
|
|
@pager_days=0,
|
|
@email_address=N'Gal_SE_DBA@galenica.com',
|
|
@category_name=N'[Uncategorized]'
|
|
|
|
SET @AlertName = 'DBA - Sev 19 Error: Fatal Error in Resource'
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=0,
|
|
@severity=19,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1;
|
|
|
|
|
|
SET @AlertName = 'DBA - Sev 20 Error: Fatal Error in Current Process'
|
|
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_delete_alert @name=@AlertName
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=0,
|
|
@severity=20,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1;
|
|
|
|
SET @AlertName = 'DBA - Sev 21 Error: Fatal Error in Database Process'
|
|
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_delete_alert @name=@AlertName
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=0,
|
|
@severity=21,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1;
|
|
|
|
SET @AlertName = 'DBA - Sev 22 Error: Fatal Error Table Integrity Suspect'
|
|
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_delete_alert @name=@AlertName
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=0,
|
|
@severity=22,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1;
|
|
|
|
SET @AlertName = 'DBA - Sev 23 Error: Fatal Error Database Integrity Suspect'
|
|
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_delete_alert @name=@AlertName
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=0,
|
|
@severity=23,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1;
|
|
|
|
SET @AlertName = 'DBA - Sev 24 Error: Fatal Hardware Error'
|
|
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_delete_alert @name=@AlertName
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=0,
|
|
@severity=24,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1;
|
|
|
|
SET @AlertName = 'DBA - Sev 25 Error: Fatal Error'
|
|
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_delete_alert @name=@AlertName
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=0,
|
|
@severity=25,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1;
|
|
|
|
|
|
SET @AlertName = 'DBA - Error 825: Read-Retry Required'
|
|
|
|
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_delete_alert @name=@AlertName
|
|
|
|
IF NOT EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_alert @name = @AlertName,
|
|
@message_id=825,
|
|
@severity=0,
|
|
@enabled=1,
|
|
@delay_between_responses=900,
|
|
@include_event_description_in=1,
|
|
@category_name = @CategoryName
|
|
|
|
IF NOT EXISTS(SELECT name
|
|
FROM msdb.dbo.sysalerts AS sa
|
|
INNER JOIN msdb.dbo.sysnotifications AS sn
|
|
ON sa.id = sn.alert_id
|
|
WHERE sa.name = @AlertName)
|
|
EXEC msdb.dbo.sp_add_notification @alert_name = @AlertName, @operator_name=@OperatorName, @notification_method = 1; |