Permits a client to define and send a trap (an SNMP alert) to an SNMP client.
xp_snmp_raisetrap server, database, error_message, message_id, severity, user, comment, date_and_time, return_status OUTPUT
where
For more information about message_id, see sp_addmessage in the Microsoft SQL Server Transact-SQL Reference.
For more information on severity, see sp_addmessage in the Microsoft SQL Server Transact-SQL Reference.
Status | Description |
---|---|
0 | The SQL agent is running and the trap was sent successfully. |
2 | A memory error occurred. |
3 | The network has not been started. |
4 | The SQL SNMP agent has timed out while waiting for a response from the SNMP client. |
5 | The SQL SNMP agent is not running. |
This procedure provides communication about SQL Server conditions to SNMP management workstation(s). You can create your own error messages, message error numbers, and severity levels, although it is recommended that you use the error messages, message error numbers, and severity levels provided in the sysmessages or sysservermessages system tables. In the Network control panel, you can define which SNMP management workstations (clients) will receive traps under SNMP service. Clients are set up on a per SQL Server basis.
Traps are usually administrative alerts about conditions or events within the SQL Server. Applications may also raise traps to notify SNMP clients of application specific conditions. For example, this procedure allows the system administrator to alert an SNMP workstation of an action that the system administrator needs to fix.
For more information about SNMP, consult your Microsoft Windows NT operating-system documentation.
This example sends a trap to the SNMP management workstation.
DECLARE @db varchar(30) DECLARE @user varchar(30) DECLARE @dt datetime DECLARE @retval int SELECT @dt = getdate() SELECT @user = user_name() SELECT @db = db_name() EXECUTE xp_snmp_raisetrap @@servername, @db, 'The authors table was updated', 50001, 10, @user, 'This trap could have been raised by an update trigger on the authors table', @dt, @retval OUTPUT SELECT Status = @retval