Skip to content

Commit f5870cb

Browse files
authored
Merge pull request #3358 from Montro1981/SQL-Server-First-Responder-Kit_3355
#3355 Added permissions check for MSDB
2 parents acc9b22 + 99b8058 commit f5870cb

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

sp_Blitz.sql

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,35 @@ AS
336336
SET @SkipModel = 1; /*We don't have read permissions in the model database*/
337337
END;
338338
END;
339+
340+
IF ISNULL(@SkipMSDB, 0) != 1 /*If @SkipMSDB hasn't been set to 1 by the caller*/
341+
BEGIN
342+
IF EXISTS
343+
(
344+
SELECT 1/0
345+
FROM @db_perms
346+
WHERE database_name = N'msdb'
347+
)
348+
BEGIN
349+
BEGIN TRY
350+
IF EXISTS
351+
(
352+
SELECT 1/0
353+
FROM msdb.sys.objects
354+
)
355+
BEGIN
356+
SET @SkipMSDB = 0; /*We have read permissions in the msdb database, and can view the objects*/
357+
END;
358+
END TRY
359+
BEGIN CATCH
360+
SET @SkipMSDB = 1; /*We have read permissions in the msdb database ... oh wait we got tricked, we can't view the objects*/
361+
END CATCH;
362+
END;
363+
ELSE
364+
BEGIN
365+
SET @SkipMSDB = 1; /*We don't have read permissions in the msdb database*/
366+
END;
367+
END;
339368
END;
340369

341370
SET @crlf = NCHAR(13) + NCHAR(10);
@@ -502,6 +531,21 @@ AS
502531
FROM (VALUES(NULL, 29, NULL)) AS v (DatabaseName, CheckID, ServerName) /*Looks for user tables in model*/
503532
WHERE @SkipModel = 1;
504533

534+
INSERT #SkipChecks (DatabaseName, CheckID, ServerName)
535+
SELECT
536+
v.*
537+
FROM (VALUES(NULL, 6, NULL), /*Jobs Owned By Users*/
538+
(NULL, 28, NULL), /*SQL Agent Job Runs at Startup*/
539+
(NULL, 57, NULL), /*Tables in the MSDB Database*/
540+
(NULL, 79, NULL), /*Shrink Database Job*/
541+
(NULL, 94, NULL), /*Agent Jobs Without Failure Emails*/
542+
(NULL, 123, NULL), /*Agent Jobs Starting Simultaneously*/
543+
(NULL, 180, NULL), /*Shrink Database Step In Maintenance Plan*/
544+
(NULL, 181, NULL), /*Repetitive Maintenance Tasks*/
545+
(NULL, 219, NULL) /*Alerts Without Event Descriptions*/
546+
) AS v (DatabaseName, CheckID, ServerName)
547+
WHERE @SkipMSDB = 1;
548+
505549
INSERT #SkipChecks (DatabaseName, CheckID, ServerName)
506550
SELECT
507551
v.*

0 commit comments

Comments
 (0)