Skip to content

Commit 7325883

Browse files
authored
Preliminary SQL Server on Linux support
This is not full support for SQL Server on Linux, but it does fix two bugs that occurred when running on SQL Server 2017 RC2 on Ubuntu. - The first was to do with trace files, where a backslash was used for the path separator. - The second was to do with a minimum value of `DATETIMEOFFSET` failing when casting to `DATETIME`. - The third was a bonus for detecting the version of operating system, using `sys.dm_host_info` if available.
1 parent 066f58c commit 7325883

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. */
@@ -6523,12 +6549,12 @@ IF @ProductVersionMajor >= 10
65236549
FROM #SkipChecks
65246550
WHERE DatabaseName IS NULL AND CheckID = 172 )
65256551
BEGIN
6526-
IF EXISTS ( SELECT 1
6527-
FROM sys.all_objects
6528-
WHERE name = 'dm_os_windows_info' )
6529-
6552+
-- sys.dm_os_host_info includes both Windows and Linux info
6553+
IF EXISTS (SELECT 1
6554+
FROM sys.all_objects
6555+
WHERE name = 'dm_os_host_info' )
65306556
BEGIN
6531-
6557+
65326558
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 172) WITH NOWAIT;
65336559

65346560
INSERT INTO [#BlitzResults]
@@ -6543,21 +6569,65 @@ IF @ProductVersionMajor >= 10
65436569
172 AS [CheckID] ,
65446570
250 AS [Priority] ,
65456571
'Server Info' AS [FindingsGroup] ,
6546-
'Windows Version' AS [Finding] ,
6547-
'https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions' AS [URL] ,
6572+
'Operating System Version' AS [Finding] ,
6573+
( CASE WHEN @IsWindowsOperatingSystem = 1
6574+
THEN 'https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions'
6575+
ELSE 'https://en.wikipedia.org/wiki/List_of_Linux_distributions'
6576+
END
6577+
) AS [URL] ,
65486578
( CASE
6549-
WHEN [owi].[windows_release] = '5' THEN 'You''re running a really old version: Windows 2000, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6550-
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))
6551-
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))
6552-
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))
6553-
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))
6554-
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))
6555-
ELSE 'I have no idea which version of Windows you''re on. Sorry.'
6579+
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))
6580+
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))
6581+
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))
6582+
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))
6583+
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))
6584+
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))
6585+
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))
6586+
ELSE 'You''re running ' + CAST([ohi].[host_distribution] AS VARCHAR(35)) + ', version ' + CAST([ohi].[host_release] AS VARCHAR(5))
65566587
END
65576588
) AS [Details]
6558-
FROM [sys].[dm_os_windows_info] [owi];
6559-
6589+
FROM [sys].[dm_os_host_info] [ohi];
65606590
END;
6591+
ELSE
6592+
BEGIN
6593+
-- Otherwise, stick with Windows-only detection
6594+
6595+
IF EXISTS ( SELECT 1
6596+
FROM sys.all_objects
6597+
WHERE name = 'dm_os_windows_info' )
6598+
6599+
BEGIN
6600+
6601+
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 172) WITH NOWAIT;
6602+
6603+
INSERT INTO [#BlitzResults]
6604+
( [CheckID] ,
6605+
[Priority] ,
6606+
[FindingsGroup] ,
6607+
[Finding] ,
6608+
[URL] ,
6609+
[Details] )
6610+
6611+
SELECT
6612+
172 AS [CheckID] ,
6613+
250 AS [Priority] ,
6614+
'Server Info' AS [FindingsGroup] ,
6615+
'Windows Version' AS [Finding] ,
6616+
'https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions' AS [URL] ,
6617+
( CASE
6618+
WHEN [owi].[windows_release] = '5' THEN 'You''re running a really old version: Windows 2000, version ' + CAST([owi].[windows_release] AS VARCHAR(5))
6619+
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))
6620+
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))
6621+
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))
6622+
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))
6623+
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))
6624+
ELSE 'I have no idea which version of Windows you''re on. Sorry.'
6625+
END
6626+
) AS [Details]
6627+
FROM [sys].[dm_os_windows_info] [owi];
6628+
6629+
END;
6630+
END;
65616631
END;
65626632

65636633
/*
@@ -6730,13 +6800,15 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
67306800

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

6803+
-- DATETIMEOFFSET and DATETIME have different minimum values, so there's
6804+
-- a small workaround here to force 1753-01-01 if the minimum is detected
67336805
SET @StringToExecute = 'INSERT INTO #BlitzResults (CheckID, Priority, FindingsGroup, Finding, URL, Details)
67346806
SELECT 83 AS CheckID ,
67356807
250 AS Priority ,
67366808
''Server Info'' AS FindingsGroup ,
67376809
''Services'' AS Finding ,
67386810
'''' AS URL ,
6739-
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 + ''.''
6811+
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 + ''.''
67406812
FROM sys.dm_server_services OPTION (RECOMPILE);';
67416813

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

0 commit comments

Comments
 (0)