April 18, 2012

sp_dbmmonitorchangealert (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_dbmmonitorchangealert(nvarchar @database_name
, int @alert_id
, int @threshold
, bit @enabled)

MetaData:

 create procedure sys.sp_dbmmonitorchangealert  
(
@database_name sysname,
@alert_id int , -- 1 TimeBehind (minutes), 2 = SendQueue (kb), 3 = RedoQueue (kb), 4 = AverageDelay (milleseconds), 5 retention period (hours)
@threshold int , -- Value
@enabled bit = 1 -- is this enabled or not? By default it is enabled.
)
as
begin
set nocount on
-- Is the caller SYSADMIN?
if (is_srvrolemember(N'sysadmin') <> 1 )
begin
raiserror(21089, 16, 1)
return (1)
end
-- Is this a system database?
if(@database_name = N'msdb' or @database_name = N'master' or @database_name = N'model' or @database_name = N'tempdb')
begin
raiserror( 32050, 16, 1)
return 1
end
-- Are the parameters correct?
if(@alert_id < 1 or @alert_id > 5 or @threshold < 0)
begin
raiserror( 32036, 16, 2 )
return 1
end
-- Does the table exist?
if object_id ( N'msdb.dbo.dbm_monitor_alerts', N'U' ) is null
begin
raiserror( 32041, 16, 1 )
return 1
end
-- Does the database exist?
if not exists (select * from master.sys.databases where name = @database_name)
begin
raiserror(15010, 16, 1, @database_name)
return 1
end
-- If the alert row does not exist, create it. otherwise update it.
if not exists (select * from msdb.dbo.dbm_monitor_alerts where database_id = db_id(@database_name))
begin -- TO DO: Change this around a bit to update it in one statement
if @alert_id = 1
begin
insert into msdb.dbo.dbm_monitor_alerts (database_id, time_behind, enable_time_behind)
values (db_id(@database_name), @threshold, @enabled )
return 0
end
if @alert_id = 2
begin
insert into msdb.dbo.dbm_monitor_alerts (database_id, send_queue, enable_send_queue)
values (db_id(@database_name), @threshold, @enabled )
return 0
end
if @alert_id = 3
begin
insert into msdb.dbo.dbm_monitor_alerts (database_id, redo_queue, enable_redo_queue)
values (db_id(@database_name), @threshold, @enabled )
return 0
end
if @alert_id = 4
begin
insert into msdb.dbo.dbm_monitor_alerts (database_id, average_delay, enable_average_delay)
values (db_id(@database_name), @threshold, @enabled )
return 0
end
if @alert_id = 5
begin
if @threshold > 85440 -- this is about 10 years
begin
raiserror( 32036, 16, 2 ) -- generic error message about parameter out of range.
return 1
end
insert into msdb.dbo.dbm_monitor_alerts (database_id, retention_period )
values (db_id(@database_name), @threshold )
return 0
end
end
else
begin
if @alert_id = 1
begin
update msdb.dbo.dbm_monitor_alerts set time_behind = @threshold, enable_time_behind = @enabled where database_id = db_id(@database_name)
return 0
end
if @alert_id = 2
begin
update msdb.dbo.dbm_monitor_alerts set send_queue = @threshold, enable_send_queue = @enabled where database_id = db_id(@database_name)
return 0
end
if @alert_id = 3
begin
update msdb.dbo.dbm_monitor_alerts set redo_queue = @threshold, enable_redo_queue = @enabled where database_id = db_id(@database_name)
return 0
end
if @alert_id = 4
begin
update msdb.dbo.dbm_monitor_alerts set average_delay = @threshold, enable_average_delay = @enabled where database_id = db_id(@database_name)
return 0
end
if @alert_id = 5
begin
if @threshold > 85440 -- this is about 10 years
begin
raiserror( 32036, 16, 2 ) -- generic error message about parameter out of range.
return 1
end
update msdb.dbo.dbm_monitor_alerts set retention_period = @threshold where database_id = db_id(@database_name)
return 0
end
end
return 1
end

No comments:

Post a Comment

Total Pageviews