电子厂SQL Server Alert发送告警邮件丢失了之原委

最近猝发现我们配备在数据库方面的报警(Alert),当错误日志里出现谬误时,并无是每个错误日志都见面发送邮件出来。如下所示,设置了报警“SQL
Server Severity Event 14”

 

USE
[msdb]

GO

 

 

IF
NOT EXISTS(SELECT 1 FROM msdb.dbo.syscategories WHERE NAME=’DBA_MONITORING’ AND category_class=2)

BEGIN

 

EXEC
msdb.dbo.sp_add_category

    @class=N’ALERT’,

    @type=N’NONE’,

    @name=N’DBA_MONITORING’ ;

 

END

GO

 

IF
EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N’SQL Server Severity Event
14′)

 

    EXEC msdb.dbo.sp_delete_alert @name=N’SQL Server Severity Event
14′

GO

 

 

EXEC
msdb.dbo.sp_add_alert @name=N’SQL Server Severity Event
14′,

       
@message_id=0,

       
@severity=14,

       
@enabled=1,

       
@delay_between_responses=60,

       
@include_event_description_in=1,

       
@category_name=N’DBA_MONITORING’,

       
@job_id=N’00000000-0000-0000-0000-000000000000′

GO

 

 

EXEC
msdb.dbo.sp_add_notification @alert_name=N’SQL Server Severity Event
14′,
@operator_name=N’YourSQLDba_Operator’, @notification_method
= 1

GO

 

 

下一场自己尝试用sa登录(sa已经让剥夺)了三破,但是我单接了同样查封邮件。特意查看了转sp_add_alert的法定文档,才理解出现这缘故,是因参数@delay_between_responses的值设置由,通过安装该值,可以防以在少日内再次发送一些不需之电子邮件。如齐所示,一分钟内,即使不当日志里出现了大气类似之荒谬,也单独见面发送一封报警邮件。其实只是是为了削减发送告警的频率,如果你想当错误日志里涌出这个级别的告警时,都须发送告警邮件,可以用那价设置为0。但是有时,如果设置为0,你见面吸纳多样之邮件。其实这有些题目,只是为原先从未专门注意这参数而已。存粹属于没有根本了解这些成效罢了。

 

 

 

电子厂 1

 

 

 

@delay_between_responses
=

] delay_between_responses

The
wait period, in seconds, between responses to the alert.
delay_between_responsesis int, with a default of 0, which
means there is no waiting between responses (each occurrence of the
alert generates a response). The response can be in either or both of
these forms:

·        
 

·        
One
or more notifications sent through e-mail or pager.

·        
 

·        
A
job to execute.

·        
By
setting this value, it is possible to prevent, for example, unwanted
e-mail messages from being sent when an alert repeatedly occurs in a
short period of time.

 

@delay_between_responses
=] delay_between_responses

警报响应期间的等候时
(以秒为单位)。delay_between_responsesis int, 默认值为 0,
这意味着在应期间没有等待
(每次出现警报都见面转响应)。响应得以是以偏下简单种样式被的一个,
或者都是:

通过电子邮件或寻呼机发送的一个或多单通知。

倘若实践之课业。

由此安装此值,
可以防例如, 在缺少日内又发生警报时发送不需之电子邮件。

 

 

参考资料:

 

https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-add-alert-transact-sql

相关文章