Skip to content

Commit

Permalink
BrentOzarULTD#3356 fix for xp_readerrorlog
Browse files Browse the repository at this point in the history
  • Loading branch information
Montro1981 committed Sep 26, 2023
1 parent 5e7f4f2 commit 0984827
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions sp_Blitz.sql
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ AS
,@SkipMSDB bit = 0
,@SkipModel bit = 0
,@SkipTempDB bit = 0
,@SkipValidateLogins bit = 0;
,@SkipValidateLogins bit = 0
,@SkipXPReadErrorLog bit = 0;

DECLARE
@db_perms table
Expand Down Expand Up @@ -338,6 +339,32 @@ AS
END;
END;

IF ISNULL(@SkipXPReadErrorLog, 0) != 1 /*If @SkipXPReadErrorLog hasn't been set to 1 by the caller*/
BEGIN
IF OBJECT_ID(N'tempdb..#XpReadErrorLogTest') IS NOT NULL
EXEC sp_executesql N'DROP TABLE #XpReadErrorLogTest;';

CREATE TABLE #XpReadErrorLogTest
(
[LogDate] DATETIME
,[ProcessInfo] NVARCHAR(12)
,[LogText] NVARCHAR(4000)
);

BEGIN TRY
INSERT INTO #XpReadErrorLogTest
EXEC xp_readerrorlog 0, 1, N'Server process ID is';

SET @SkipXPReadErrorLog = 0; /*We can execute xp_readerrorlog*/
END TRY
BEGIN CATCH
SET @SkipXPReadErrorLog = 1; /*We don't have execute rights or xp_readerrorlog throws an error so skip it*/
END CATCH;

IF OBJECT_ID(N'tempdb..#XpReadErrorLogTest') IS NOT NULL
EXEC sp_executesql N'DROP TABLE #XpReadErrorLogTest;';
END; /*Need execute on xp_readerrorlog*/

SET @crlf = NCHAR(13) + NCHAR(10);
SET @ResultText = 'sp_Blitz Results: ' + @crlf;

Expand Down Expand Up @@ -542,7 +569,13 @@ AS
SELECT
v.*
FROM (VALUES(NULL, 2301, NULL)) AS v (DatabaseName, CheckID, ServerName) /*sp_validatelogins*/
WHERE @SkipValidateLogins = 1
WHERE @SkipValidateLogins = 1;

INSERT #SkipChecks (DatabaseName, CheckID, ServerName)
SELECT
v.*
FROM (VALUES(NULL, 193, NULL)) AS v (DatabaseName, CheckID, ServerName) /*xp_readerrorlog*/
WHERE @SkipXPReadErrorLog = 1;

IF(OBJECT_ID('tempdb..#InvalidLogins') IS NOT NULL)
BEGIN
Expand Down

0 comments on commit 0984827

Please sign in to comment.