SQL Server Agent Job Notify multiple operators on

2020-08-09 05:23发布

I have a Job setup in SQL Server 2008 which sends a notification email to one operator when the job fails.

Question: Is it possible to setup a notification email being sent to multiple operators for that specific job?

I believe a possible workaround for this is to create lots of alerts for the database for each given severity but I was hoping that there was a more concise way to do this. If I were to go this route, what severity errors would likely be triggered from a failed job? (I don't think I would require all 25 for something like that)

Can this be done through sql command to add more operators to notify on failure? Through the UI you are only able to choose a single operator it seems.

6条回答
可以哭但决不认输i
2楼-- · 2020-08-09 05:35

Question: Is it possible to setup a notification email being sent to multiple operators for that specific job?

I don't believe this is possible.

Certainly looking at the structure of [msdb].[dbo].[sysjobs] the various operator_id columns are in this table itself which would support the idea that 1 to many is not possible.

But some alternatives

  1. You could create a new operator with the semi colon delimited list of email addresses. Looking at the definition of sysoperators this is good for strings that can fit in nvarchar(100)
  2. if you need to exceed that you could probably set up an email distribution group on exchange or whatever.
查看更多
做自己的国王
3楼-- · 2020-08-09 05:40

So this is what I came up with as a workaround if the intention is that multiple people in your organization should be notified if a job fails and a different group of multiple people for successes.

You will notice the Steps 1-3 are the normal tasks that the schedule job is uses for as you would do for your task. There can as many steps as needed before these but the last step (Step 3) of the process need to break “On Success” and “On Failure” to go into separate emails. Also all “On Failures” need to continue to your “Failure Email” as highlighted below. So the Failure group gets there emails and the job will still fail for the historical records.

1.1

You will see the option to change the direction of the “On success action” and “On Failure action” in the Advanced tab of the Job steps.

2

Failure Email Step -General Property

3

Failure Email Step -Advance Property

4

Success Email Step -General Property

5

Success Email Step -Advance Property

6

For others in need help. Notify multiple operators with difference results

查看更多
三岁会撩人
4楼-- · 2020-08-09 05:44

If the intention is that multiple people in your organization should be notified if a job fails, you can change the email address of the operator to include multiple mailboxes by separating each mailbox with a semicolon.

I'm assuming your notified operator is called JobWatcher:

EXECUTE msdb.dbo.sp_update_operator
  @name = N'JobWatcher',
  @email_address = N'person1@company.org;person2@company.org';

Now person1@company.org and person2@company.org will receive mail when the job fails.

查看更多
ゆ 、 Hurt°
5楼-- · 2020-08-09 05:47

The simplest method i use to notify multiple "OPERATORS" on "JOB FAILURE" is to:

In SSMS>SQL Server Agent>Operators create a new OPERATOR or EDIT existing and add additional email addresses separated by ; in "E-mail name:" box.

查看更多
劫难
6楼-- · 2020-08-09 05:48

The best practice would be to create a group on your mail server, send the notifications to the group and then control the number of recipients from the mail server.

查看更多
Lonely孤独者°
7楼-- · 2020-08-09 05:50

Please use below script to increase the character length of email address. USE mdsdb GO ALTER TABLE sysoperators ALTER column email_address NVARCHAR(2000);

查看更多
登录 后发表回答