Skip to content

Commit 48e79ff

Browse files
authored
Merge pull request #1056 from rabryst/patch-1
Preliminary SQL Server on Linux support
2 parents 2ec32c2 + 7325883 commit 48e79ff

File tree

1 file changed

+93
-21
lines changed

1 file changed

+93
-21
lines changed

sp_Blitz.sql

Lines changed: 93 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ AS
145145
,@MinServerMemory bigint
146146
,@MaxServerMemory bigint
147147
,@ColumnStoreIndexesInUse bit
148-
,@TraceFileIssue bit;
148+
,@TraceFileIssue bit
149+
-- Flag for Windows OS to help with Linux support
150+
,@IsWindowsOperatingSystem BIT;
149151

150152

151153
SET @crlf = NCHAR(13) + NCHAR(10);
@@ -235,11 +237,35 @@ AS
235237
WHERE DatabaseName IS NULL AND CheckID = 106 )
236238
AND (select convert(int,value_in_use) from sys.configurations where name = 'default trace enabled' ) = 1
237239
BEGIN
240+
-- Flag for Windows OS to help with Linux support
241+
IF EXISTS ( SELECT 1
242+
FROM sys.all_objects
243+
WHERE name = 'dm_os_host_info' )
244+
BEGIN
245+
SELECT @IsWindowsOperatingSystem = CASE WHEN host_platform = 'Windows' THEN 1 ELSE 0 END FROM sys.dm_os_host_info ;
246+
END;
247+
ELSE
248+
BEGIN
249+
SELECT @IsWindowsOperatingSystem = 1 ;
250+
END;
251+
238252
select @curr_tracefilename = [path] from sys.traces where is_default = 1 ;
239253
set @curr_tracefilename = reverse(@curr_tracefilename);
240-
select @indx = patindex('%\%', @curr_tracefilename) ;
241-
set @curr_tracefilename = reverse(@curr_tracefilename) ;
242-
set @base_tracefilename = left( @curr_tracefilename,len(@curr_tracefilename) - @indx) + '\log.trc' ;
254+
255+
-- Set the trace file path separator based on underlying OS
256+
IF (@IsWindowsOperatingSystem = 1)
257+
BEGIN
258+
select @indx = patindex('%\%', @curr_tracefilename) ;
259+
set @curr_tracefilename = reverse(@curr_tracefilename) ;
260+
set @base_tracefilename = left( @curr_tracefilename,len(@curr_tracefilename) - @indx) + '\log.trc' ;
261+
END;
262+
ELSE
263+
BEGIN
264+
select @indx = patindex('%/%', @curr_tracefilename) ;
265+
set @curr_tracefilename = reverse(@curr_tracefilename) ;
266+
set @base_tracefilename = left( @curr_tracefilename,len(@curr_tracefilename) - @indx) + '/log.trc' ;
267+
END;
268+
243269
END;
244270

245271
/* If the server has any databases on Antiques Roadshow, skip the checks that would break due to CTEs. */
@@ -6575,12 +6601,12 @@ IF @ProductVersionMajor >= 10
65756601
FROM #SkipChecks
65766602
WHERE DatabaseName IS NULL AND CheckID = 172 )
65776603
BEGIN
6578-
IF EXISTS ( SELECT 1
6579-
FROM sys.all_objects
6580-
WHERE name = 'dm_os_windows_info' )
6581-
6604+
-- sys.dm_os_host_info includes both Windows and Linux info
6605+
IF EXISTS (SELECT 1
6606+
FROM sys.all_objects
6607+
WHERE name = 'dm_os_host_info' )
65826608
BEGIN
6583-
6609+
65846610
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 172) WITH NOWAIT;
65856611

65866612
INSERT INTO [#BlitzResults]
@@ -6595,21 +6621,65 @@ IF @ProductVersionMajor >= 10
65956621
172 AS [CheckID] ,
65966622
250 AS [Priority] ,
65976623
'Server Info' AS [FindingsGroup] ,
6598-
'Windows Version' AS [Finding] ,
6599-
'https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions' AS [URL] ,
6624+
'Operating System Version' AS [Finding] ,
6625+
( CASE WHEN @IsWindowsOperatingSystem = 1
6626+
THEN 'https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions'
6627+
ELSE 'https://en.wikipedia.org/wiki/List_of_Linux_distributions'
6628+
END
6629+
) AS [URL] ,
66006630
( CASE
6601-
WHEN [owi].[windows_release] = '5' THEN 'You''re running a really old version: Windows 2000, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6602-
WHEN [owi].[windows_release] > '5' AND [owi].[windows_release] < '6' THEN 'You''re running a really old version: Windows Server 2003/2003R2 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6603-
WHEN [owi].[windows_release] >= '6' AND [owi].[windows_release] <= '6.1' THEN 'You''re running a pretty old version: Windows: Server 2008/2008R2 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6604-
WHEN [owi].[windows_release] = '6.2' THEN 'You''re running a rather modern version of Windows: Server 2012 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6605-
WHEN [owi].[windows_release] = '6.3' THEN 'You''re running a pretty modern version of Windows: Server 2012R2 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6606-
WHEN [owi].[windows_release] > '6.3' THEN 'Hot dog! You''re living in the future! You''re running version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6607-
ELSE 'I have no idea which version of Windows you''re on. Sorry.'
6631+
WHEN [ohi].[host_platform] = 'Linux' THEN 'You''re running the ' + CAST([ohi].[host_distribution] AS VARCHAR(35)) + ' distribution of ' + CAST([ohi].[host_platform] AS VARCHAR(35)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
6632+
WHEN [ohi].[host_platform] = 'Windows' AND [ohi].[host_release] = '5' THEN 'You''re running a really old version: Windows 2000, version ' + CAST([ohi].[host_release] AS VARCHAR(5))
6633+
WHEN [ohi].[host_platform] = 'Windows' AND [ohi].[host_release] > '5' AND [ohi].[host_release] < '6' THEN 'You''re running a really old version: ' + CAST([ohi].[host_distribution] AS VARCHAR(50)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
6634+
WHEN [ohi].[host_platform] = 'Windows' AND [ohi].[host_release] >= '6' AND [ohi].[host_release] <= '6.1' THEN 'You''re running a pretty old version: Windows: ' + CAST([ohi].[host_distribution] AS VARCHAR(50)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
6635+
WHEN [ohi].[host_platform] = 'Windows' AND [ohi].[host_release] = '6.2' THEN 'You''re running a rather modern version of Windows: ' + CAST([ohi].[host_distribution] AS VARCHAR(50)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
6636+
WHEN [ohi].[host_platform] = 'Windows' AND [ohi].[host_release] = '6.3' THEN 'You''re running a pretty modern version of Windows: ' + CAST([ohi].[host_distribution] AS VARCHAR(50)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
6637+
WHEN [ohi].[host_platform] = 'Windows' AND [ohi].[host_release] > '6.3' THEN 'Hot dog! You''re living in the future! You''re running ' + CAST([ohi].[host_distribution] AS VARCHAR(50)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
6638+
ELSE 'You''re running ' + CAST([ohi].[host_distribution] AS VARCHAR(35)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
66086639
END
66096640
) AS [Details]
6610-
FROM [sys].[dm_os_windows_info] [owi];
6611-
6641+
FROM [sys].[dm_os_host_info] [ohi];
66126642
END;
6643+
ELSE
6644+
BEGIN
6645+
-- Otherwise, stick with Windows-only detection
6646+
6647+
IF EXISTS ( SELECT 1
6648+
FROM sys.all_objects
6649+
WHERE name = 'dm_os_windows_info' )
6650+
6651+
BEGIN
6652+
6653+
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 172) WITH NOWAIT;
6654+
6655+
INSERT INTO [#BlitzResults]
6656+
( [CheckID] ,
6657+
[Priority] ,
6658+
[FindingsGroup] ,
6659+
[Finding] ,
6660+
[URL] ,
6661+
[Details] )
6662+
6663+
SELECT
6664+
172 AS [CheckID] ,
6665+
250 AS [Priority] ,
6666+
'Server Info' AS [FindingsGroup] ,
6667+
'Windows Version' AS [Finding] ,
6668+
'https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions' AS [URL] ,
6669+
( CASE
6670+
WHEN [owi].[windows_release] = '5' THEN 'You''re running a really old version: Windows 2000, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6671+
WHEN [owi].[windows_release] > '5' AND [owi].[windows_release] < '6' THEN 'You''re running a really old version: Windows Server 2003/2003R2 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6672+
WHEN [owi].[windows_release] >= '6' AND [owi].[windows_release] <= '6.1' THEN 'You''re running a pretty old version: Windows: Server 2008/2008R2 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6673+
WHEN [owi].[windows_release] = '6.2' THEN 'You''re running a rather modern version of Windows: Server 2012 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6674+
WHEN [owi].[windows_release] = '6.3' THEN 'You''re running a pretty modern version of Windows: Server 2012R2 era, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6675+
WHEN [owi].[windows_release] > '6.3' THEN 'Hot dog! You''re living in the future! You''re running version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6676+
ELSE 'I have no idea which version of Windows you''re on. Sorry.'
6677+
END
6678+
) AS [Details]
6679+
FROM [sys].[dm_os_windows_info] [owi];
6680+
6681+
END;
6682+
END;
66136683
END;
66146684

66156685
/*
@@ -6782,13 +6852,15 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
67826852

67836853
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 83) WITH NOWAIT;
67846854

6855+
-- DATETIMEOFFSET and DATETIME have different minimum values, so there's
6856+
-- a small workaround here to force 1753-01-01 if the minimum is detected
67856857
SET @StringToExecute = 'INSERT INTO #BlitzResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
67866858
SELECT 83 AS CheckID ,
67876859
250 AS Priority ,
67886860
''Server Info'' AS FindingsGroup ,
67896861
''Services'' AS Finding ,
67906862
'''' AS URL ,
6791-
N''Service: '' + servicename + N'' runs under service account '' + service_account + N''. Last startup time: '' + COALESCE(CAST(CAST(last_startup_time AS DATETIME) AS VARCHAR(50)), ''not shown.'') + ''. Startup type: '' + startup_type_desc + N'', currently '' + status_desc + ''.''
6863+
N''Service: '' + servicename + N'' runs under service account '' + service_account + N''. Last startup time: '' + COALESCE(CAST(CASE WHEN YEAR(last_startup_time) <= 1753 THEN CAST(''17530101'' as datetime) ELSE CAST(last_startup_time AS DATETIME) END AS VARCHAR(50)), ''not shown.'') + ''. Startup type: '' + startup_type_desc + N'', currently '' + status_desc + ''.''
67926864
FROM sys.dm_server_services OPTION (RECOMPILE);';
67936865

67946866
IF @Debug = 2 AND @StringToExecute IS NOT NULL PRINT @StringToExecute;

0 commit comments

Comments
 (0)