{"id":1012,"date":"2022-10-31T13:55:44","date_gmt":"2022-10-31T18:55:44","guid":{"rendered":"https:\/\/brentec.ca\/blog\/?p=1012"},"modified":"2022-11-21T13:56:39","modified_gmt":"2022-11-21T18:56:39","slug":"t-sql-script-showing-why-sql-server-operators-may-not-receive-notifications","status":"publish","type":"post","link":"https:\/\/brentec.ca\/blog\/2022\/10\/t-sql-script-showing-why-sql-server-operators-may-not-receive-notifications\/","title":{"rendered":"T-SQL script showing why SQL Server operators may not receive notifications"},"content":{"rendered":"<p><span style=\"font-size: 13px; letter-spacing: 1px;\"><span style=\"color: #3366ff;\"><strong>Problem<\/strong><\/span>: One or more of your operators are not getting notifications from SQL Server agent alerts or jobs.<\/span><\/p>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\"><span style=\"color: #3366ff;\"><strong>Solution<\/strong><\/span>: This could be for a number of reasons, but more than likely it is because an operator or alert is disabled, or both. Let&#8217;s use the query below and determine what is causing the underlying problem and how to resolve them.<\/span><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT so.id AS &#x5B;operator_id]\r\n, so.&#x5B;name] AS &#x5B;operator_name]\r\n, so.&#x5B;enabled] AS &#x5B;operator_enabled]\r\n, sa.id AS &#x5B;alert_id]\r\n, sa.&#x5B;name] AS &#x5B;alert_name]\r\n, sa.&#x5B;enabled] AS &#x5B;alert_enabled]\r\nFROM msdb.dbo.sysoperators so\r\nJOIN msdb.dbo.sysnotifications sn\r\nON so.id = sn.operator_id\r\nJOIN msdb.dbo.sysalerts sa\r\nON sn.alert_id = sa.id\r\nWHERE so.&#x5B;enabled] = 0\r\nOR sa.&#x5B;enabled] = 0\r\nORDER BY so.id\r\n<\/pre>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">After running the query above, your output will be similar to the following:<\/span><\/p>\n<figure id=\"attachment_1028\" aria-describedby=\"caption-attachment-1028\" style=\"width: 568px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/brentec.ca\/blog\/wp-content\/uploads\/2022\/10\/disabled-operators-and-alerts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1028 size-full\" src=\"https:\/\/brentec.ca\/blog\/wp-content\/uploads\/2022\/10\/disabled-operators-and-alerts.png\" alt=\"\" width=\"568\" height=\"157\" srcset=\"https:\/\/brentec.ca\/blog\/wp-content\/uploads\/2022\/10\/disabled-operators-and-alerts.png 568w, https:\/\/brentec.ca\/blog\/wp-content\/uploads\/2022\/10\/disabled-operators-and-alerts-300x83.png 300w\" sizes=\"(max-width: 568px) 100vw, 568px\" \/><\/a><figcaption id=\"caption-attachment-1028\" class=\"wp-caption-text\"><span style=\"font-size: 13px; letter-spacing: 1px;\"> Figure 1 &#8211; Example output from our query above.<\/span><\/figcaption><\/figure>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">Your results will vary, but what is most important to notice in the result set are the columns,\u00a0<em>operator_enabled<\/em> and\u00a0<em>alert_enabled<\/em>, more specifically, if any of those values read zero (0), i.e., <strong>disabled<\/strong>.<\/span><\/p>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">We can see from <strong>Figure 1<\/strong> that User1 is enabled, but all of the alerts for that user are disabled, therefore that user will not receive any notifications for those named alerts. User2 on the other-hand is disabled (i.e., <em>operator_enabled = 0<\/em>), and regardless if some or all of the alerts are enabled, User2 will not receive any notifications either for any alerts whatsoever.<\/span><\/p>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">So, how do we resolve disabled operators or disabled alerts via T-SQL?<\/span><\/p>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">To update any operator within SQL Server, we use the system stored procedure <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-stored-procedures\/sp-update-operator-transact-sql?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener\">sp_update_operator<\/a> within the MSDB database. An example is shown below that enables a given named operator.<\/span><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nUSE msdb\r\nGO\r\n-- replace &lt;operator&gt; with the name of one from your instance.\r\nEXECUTE dbo.sp_update_operator @name = N'&lt;operator&gt;', @enabled = 1;\r\nGO\r\n<\/pre>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">Updating an alert within SQL Server is accomplished by using the system stored procedure, <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-stored-procedures\/sp-update-alert-transact-sql?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener\">sp_update_alert<\/a>, also found within the MSDB database. Shown below is an example of how to enable a given named alert.<\/span><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nUSE MSDB\r\nGO\r\n-- replace &lt;alert name&gt; with name of one from your instance.\r\nEXECUTE dbo.sp_update_alert @name = N'&lt;alert name&gt;', @enabled = 1;\r\nGO\r\n<\/pre>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">So the next time operators within one of your SQL Server instances are not receiving notifications, use these scripts to identify and resolve the issue.<\/span><\/p>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">Here are some links to the MSDB system tables referenced earlier. <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-tables\/dbo-sysoperators-transact-sql?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener\">msdb.dbo.sysoperators<\/a>, <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-tables\/dbo-sysnotifications-transact-sql?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener\">msdb.dbo.sysnotifications<\/a>, and <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/system-tables\/dbo-sysalerts-transact-sql?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener\">msdb.dbo.sysalerts<\/a>.<\/span><\/p>\n<hr \/>\n<p><span style=\"font-size: 13px; letter-spacing: 1px;\">Did you find this useful? Did it help you solve an immediate need within your SQL Server agent estate? If so, you might want to check out <a href=\"https:\/\/brentec.ca\/sql-agent-insight\/downloads\/\" target=\"_blank\" rel=\"noopener\">SQL Agent Insight<\/a>, a product I\u2019ve been working on during spare time to assist in determining problem areas of SQL Server agent instances.<\/span><\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>Problem: One or more of your operators are not getting notifications from SQL Server agent alerts or jobs. Solution: This could be for a number of reasons, but more than likely it is because an operator or alert is disabled, or both. Let&#8217;s use the query below and determine what is causing the underlying problem &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/brentec.ca\/blog\/2022\/10\/t-sql-script-showing-why-sql-server-operators-may-not-receive-notifications\/\"> <span class=\"screen-reader-text\">T-SQL script showing why SQL Server operators may not receive notifications<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[3,56,45],"tags":[],"_links":{"self":[{"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/posts\/1012"}],"collection":[{"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/comments?post=1012"}],"version-history":[{"count":32,"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/posts\/1012\/revisions"}],"predecessor-version":[{"id":1059,"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/posts\/1012\/revisions\/1059"}],"wp:attachment":[{"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/media?parent=1012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/categories?post=1012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brentec.ca\/blog\/wp-json\/wp\/v2\/tags?post=1012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}