Technical Article

Check W2K Event log and send results to DBA

,

This is a simple Script that checks the W2K event log of choice and emails the results to the DBA. This script also uses the find command so you can search for strings in your event logs. It creats two scripts, the first script sp_EventlogSys runs xp_sendmail which executes the second procedure sp_EventlogSysquery and attaches the results to a text file to be mailed to the DBA. This script has been setup to find all ERROR messages in the System event log. Just schedule the sp_eventlogsys to run every n hrs, n week and you'll have only the error messages sent by email.
Cheers
Greg

--Greg MacDonald - DBA 
--Family Insurance Corporation
--Aug 22 2002
--This script checks event logs for errors then emails the results to the DBA
--There are changes that need to be made for this script see commented lines below
--Feel free to modify or enhance this script...
--For this script to work you'll need the 'elogdmp.exe' copied from the-
--W2K Resource kit to Winnt\system32 directory on the server
--Then schedule it to run once every Nhrs or week or month.
--This should work on all versions of SQL Server
--email: gregm@familyins.com

Use Master
Go
Create Procedure sp_EventlogSys
AS
Exec master..xp_sendmail
 @Recipients = 'email_address', -- change to  your email address
 @Message = 'Event logs have been Check for Errors', -- Change to message of choice
 @Subject = 'Errors in System Log on Servername ', -- Change to subject of choice
 @attach_results = 'true',
 @attachments = 'Event log System.txt', -- Change to name of choice
 @width = 999,
 @query= 'exec master..sp_EventlogSysquery'

GO

Create procedure sp_EventlogSysquery
AS
DECLARE @cmd sysname, @var sysname
SET @var = 'elogdmp Servername system' --replace 'servername' with name of server and replace 'system' with log choice eg. (system or application or security)
SET @cmd = '' + @var + '| Find "ERROR"'-- you can replace string "ERROR" with any string you're looking for in the event logs.
EXEC master..xp_cmdshell @cmd

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating