forked from bulentgucuk/DBA-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCreate SQL Server Alerts.sql
236 lines (191 loc) · 10.3 KB
/
Create SQL Server Alerts.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
USE [msdb]
GO
DECLARE @Enabled TINYINT
DECLARE @NotificationMethod TINYINT
DECLARE @NotificationMessage NVARCHAR(512)
DECLARE @WMINamespace NVARCHAR(512)
DECLARE @Operator NVARCHAR(128);
SELECT @Enabled = 1
SELECT @Operator = N'CI DBA Alerts'
SELECT @NotificationMethod = 1 -- Email
--SELECT @NotificationMethod = 2 -- Pager
/****** Object: Alert [DBAdmin: (017) Insufficient Resources Error] Script Date: 08/23/2008 22:22:37 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (017) Insufficient Resources Error',
@message_id=0,
@severity=17,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (017) Insufficient Resources Error', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (018) Nonfatal Internal Software Error] Script Date: 08/23/2008 22:22:37 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (018) Nonfatal Internal Software Error',
@message_id=0,
@severity=18,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (018) Nonfatal Internal Software Error', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (019) Fatal Error in Resource] Script Date: 08/23/2008 22:22:37 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (019) Fatal Error in Resource',
@message_id=0,
@severity=19,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (019) Fatal Error in Resource', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (020) Fatal Error In Current Process] Script Date: 08/23/2008 22:22:37 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (020) Fatal Error In Current Process',
@message_id=0,
@severity=20,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (020) Fatal Error In Current Process', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (021) Fatal Error In Database Processes] Script Date: 08/23/2008 22:22:37 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (021) Fatal Error In Database Processes',
@message_id=0,
@severity=21,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (021) Fatal Error In Database Processes', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (022) Fatal Error: Table Integrity Suspect] Script Date: 08/23/2008 22:22:38 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (022) Fatal Error: Table Integrity Suspect',
@message_id=0,
@severity=22,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (022) Fatal Error: Table Integrity Suspect', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (023) Fatal Database Integrity Error] Script Date: 08/23/2008 22:22:38 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (023) Fatal Database Integrity Error',
@message_id=0,
@severity=23,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (023) Fatal Database Integrity Error', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (024) Fatal Hardware Error] Script Date: 08/23/2008 22:22:38 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (024) Fatal Hardware Error',
@message_id=0,
@severity=24,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (024) Fatal Hardware Error', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: (025) Fatal Error] Script Date: 08/23/2008 22:22:38 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: (025) Fatal Error',
@message_id=0,
@severity=25,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: (025) Fatal Error', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: SQL Server Shutdown Request] Script Date: 08/23/2008 22:22:38 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: SQL Server Shutdown Request',
@message_id=6006,
@severity=0,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: SQL Server Shutdown Request', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: SQL Server Startup] Script Date: 10/19/2010 07:33:39 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: SQL Server Startup',
@message_id=0,
@severity=1,
@enabled=1,
@delay_between_responses=60,
@include_event_description_in=0,
@event_description_keyword=N'DBAdmin: SQL Has Started',
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: SQL Server Startup', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: System Shutdown Request] Script Date: 08/23/2008 22:22:39 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: System Shutdown Request',
@message_id=17147,
@severity=0,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: System Shutdown Request', @operator_name = @Operator, @notification_method=@NotificationMethod
/****** Object: Alert [DBAdmin: Transaction Log Full] Script Date: 08/23/2008 22:22:39 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: Transaction Log Full',
@message_id=9002,
@severity=0,
@enabled=@Enabled,
@delay_between_responses=300,
@include_event_description_in=2,
@category_name=N'[Uncategorized]',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DBAdmin: Transaction Log Full', @operator_name = @Operator, @notification_method=@NotificationMethod
IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = N'DB Mirroring: Mirror failover')
EXEC msdb.dbo.sp_delete_alert @name=N'DB Mirroring: Mirror failover'
SET @NotificationMessage= @@SERVERNAME + N' has had a mirrored database failover'
SET @WMINamespace = N'\\.\root\Microsoft\SqlServer\ServerEvents\' + CAST( ServerProperty('InstanceName') AS nvarchar)
/****** Object: Alert [DB Mirroring: Mirror failover] Script Date: 07/12/2011 09:55:57 ******/
EXEC msdb.dbo.sp_add_alert @name=N'DB Mirroring: Mirror failover',
@message_id=0,
@severity=0,
@enabled=1,
@delay_between_responses=10,
@include_event_description_in=3,
@notification_message=@NotificationMessage,
@category_name=N'[Uncategorized]',
@wmi_namespace=@WMINamespace,
@wmi_query=N'SELECT * FROM DATABASE_MIRRORING_STATE_CHANGE WHERE State = 7 OR State = 8',
@job_id=N'00000000-0000-0000-0000-000000000000'
EXEC sp_add_notification @alert_name=N'DB Mirroring: Mirror failover', @operator_name = @Operator, @notification_method=@NotificationMethod
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: Error Number 823',
@message_id=823,
@severity=0,
@enabled=1,
@delay_between_responses=60,
@include_event_description_in=1;
EXEC msdb.dbo.sp_add_notification @alert_name=N'DBAdmin: Error Number 823',
@operator_name=@Operator, @notification_method = 1;
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: Error Number 824',
@message_id=824,
@severity=0,
@enabled=1,
@delay_between_responses=60,
@include_event_description_in=1;
EXEC msdb.dbo.sp_add_notification @alert_name=N'DBAdmin: Error Number 824',
@operator_name=@Operator, @notification_method = 1;
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: Error Number 825',
@message_id=825,
@severity=0,
@enabled=1,
@delay_between_responses=60,
@include_event_description_in=1;
EXEC msdb.dbo.sp_add_notification @alert_name=N'DBAdmin: Error Number 825',
@operator_name=@Operator, @notification_method = 1;
EXEC msdb.dbo.sp_add_alert @name=N'DBAdmin: Error Number 833',
@message_id=833,
@severity=0,
@enabled=1,
@delay_between_responses=60,
@include_event_description_in=1;
EXEC msdb.dbo.sp_add_notification @alert_name=N'DBAdmin: Error Number 833',
@operator_name=@Operator, @notification_method = 1;