Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Agent Job Notify multiple operators on failure

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.

like image 591
Mike Avatar asked Sep 15 '11 13:09

Mike


People also ask

How do I monitor my SQL Server Agent job?

To open the Job Activity Monitor, expand SQL Server Agent in Management Studio Object Explorer, right-click Job Activity Monitor, and click View Job Activity. You can also view job activity for the current session by using the stored procedure sp_help_jobactivity.

How do I Script Multiple SQL Agent jobs?

Select all the jobs you want to script (press the Ctrl button while clicking to select individual jobs) and then right click and select the scripting option you want. This will then create all the selected jobs as a single query.

How do I get a list of failed jobs in SQL Server?

To view these logs, perform the following steps: Open SQL Server Management Studio (SSMS) and connect to the corresponding database instance. Navigate to Management -> SQL Server Logs -> SQL job name. Find the job failure event and review the log details.


2 Answers

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.
like image 131
Martin Smith Avatar answered Sep 21 '22 08:09

Martin Smith


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'[email protected];[email protected]'; 

Now [email protected] and [email protected] will receive mail when the job fails.

like image 29
Iain Samuel McLean Elder Avatar answered Sep 20 '22 08:09

Iain Samuel McLean Elder