Last active
December 28, 2017 06:16
-
-
Save tejaswidatla/164e528d8a5b83687a5f892c9b41d9d6 to your computer and use it in GitHub Desktop.
Find Active node on which services are running in a cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE [dbo].[Active_Node_Alert] | |
AS | |
BEGIN | |
SET NOCOUNT ON | |
DECLARE @node VARCHAR(20) | |
DECLARE @var_subject varchar(100) | |
DECLARE @active_node VARCHAR(20) | |
SELECT @node = node FROM tbl_active_node WHERE status ='Active' | |
SELECT @active_node= convert(VARCHAR(20), (select SERVERPROPERTY('computernamephysicalnetbios'))) | |
IF @node<>@active_node | |
BEGIN | |
UPDATE tbl_active_node SET STATUS='ACTIVE' where node=@active_node | |
UPDATE tbl_active_node SET STATUS='PASSIVE' where node<>@active_node | |
UPDATE tbl_active_node SET lastupdated=GETDATE() | |
-- Sending mail about the change of the active node | |
SET @var_subject = 'Active Node changed for ' + @@SERVERNAME + ' from ' +RTRIM(LTRIM(@node))+' to '+RTRIM(LTRIM(@active_node)) | |
EXEC msdb.dbo.sp_send_dbmail | |
@recipients = 'MPDSupportPagers@horizon-bcbsnj.com', | |
@subject = @var_subject, | |
@query='select RTRIM(LTRIM(node)) as ActiveNode, RTRIM(LTRIM(LastUpdated)) as LastUpdated from master.dbo.tbl_active_node where status=''active''' | |
EXEC msdb.dbo.sysmail_start_sp | |
EXEC msdb.dbo.sysmail_help_queue_sp @queue_type = 'mail' | |
END | |
SET NOCOUNT OFF | |
END | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node status lastupdated | |
NodeA ACTIVE 17:00.9 | |
NodeB PASSIVE 17:00.9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment