Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_replmonitoralerts

  No additional text.


Syntax
create procedure sys.sp_replmonitoralerts
(
    @mode tinyint = 0 -- 0 = create, 1 = delete
)
as
begin
    set nocount on
    declare @retcode int
                ,@categoryname sysname
                ,@alertmessageid int
                ,@alertnameid int
                ,@title sysname
                ,@name sysname
                ,@alertname sysname

    
    -- validate @mode
    
    if (@mode not in (0,1))
        return 1
    
    -- Threshold metrics has to exist
    
    if (object_id('msdb.dbo.MSreplmonthresholdmetrics') is null)
        return 1
    
    -- TEMPORARY
    
    if not exists (select * from sys.columns
                    where name = N'alertnameid'
                and object_id=object_id('msdb.dbo.MSreplmonthresholdmetrics'))
    begin
        exec sys.sp_replmonitorinitializemetrics
    end

    
    -- Get the category for the alerts
    -- Get Replication category name (assumes category_id = 20)
    
    select @categoryname = name from msdb.dbo.syscategories where category_id = 20
    
    -- enumerate through the collection
    
    declare #hcthresholds cursor local fast_forward for
        select title, alertmessageid, alertnameid
        from msdb.dbo.MSreplmonthresholdmetrics
    open #hcthresholds
    fetch #hcthresholds into @title, @alertmessageid, @alertnameid
    while (@@fetch_status != -1)
    begin
        select @name = null
        if (@mode = 0)
        begin
            
            -- add the alert
            
            if not exists (select * from msdb.dbo.sysalerts where message_id=@alertmessageid)
            begin
                select @alertname = isnull(formatmessage(@alertnameid), N'Replication Alert name')
                select @name  = formatmessage(20539, @alertname, @title)
                exec @retcode = msdb.dbo.sp_add_alert @name = @name
                                            ,@message_id = @alertmessageid
                                            ,@enabled = 1
                                            ,@delay_between_responses = 30
                                            ,@include_event_description_in = 5
                                            ,@category_name = @categoryname
                if @@error <> 0 or @retcode <> 0
                    return 1
            end
        end
        else
        begin
            
            -- drop the alert
            
            select @name = name from msdb.dbo.sysalerts where message_id=@alertmessageid
            if (@name is not null)
            begin
                exec @retcode = msdb.dbo.sp_delete_alert @name = @name
                if @@error <> 0 or @retcode <> 0
                    return (1)
            end
        end
        
        -- get next threshold
        
        fetch #hcthresholds into @title, @alertmessageid, @alertnameid
    end
    
    -- return
    
    return 0
end

 
Last revision 2008RTM
See also

  sp_MSadd_distributor_alerts_and_responses (Procedure)
sp_MSdrop_distributor_alerts_and_responses (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash