diff --git a/packages/check-sql/src/ms_sql/api.rs b/packages/check-sql/src/ms_sql/api.rs index 1821ea47f40..7643e1a7c58 100644 --- a/packages/check-sql/src/ms_sql/api.rs +++ b/packages/check-sql/src/ms_sql/api.rs @@ -46,7 +46,8 @@ pub struct InstanceEngine { pub version: String, pub edition: String, pub cluster: Option, - pub port: Option, + port: Option, + dynamic_port: Option, pub available: Option, } @@ -68,6 +69,10 @@ impl InstanceEngine { let result = section.to_header(); result + format!("{} not implemented\n", section.name).as_str() } + + pub fn port(&self) -> Option { + self.port.or(self.dynamic_port) + } } impl Column for Row { @@ -98,6 +103,9 @@ impl From<&Row> for InstanceEngine { port: row .get_optional_string(5) .and_then(|s| s.parse::().ok()), + dynamic_port: row + .get_optional_string(6) + .and_then(|s| s.parse::().ok()), available: None, } } diff --git a/packages/check-sql/src/ms_sql/queries.rs b/packages/check-sql/src/ms_sql/queries.rs index dff94465614..db0563cf37f 100644 --- a/packages/check-sql/src/ms_sql/queries.rs +++ b/packages/check-sql/src/ms_sql/queries.rs @@ -27,6 +27,7 @@ DECLARE @GetAll TABLE VersionNames nvarchar(100), ClusterNames nvarchar(100), Ports nvarchar(100), + DynamicPorts nvarchar(100), Data nvarchar(100)) Insert into @GetInstances @@ -85,11 +86,18 @@ BEGIN DECLARE @Port NVARCHAR(100); EXECUTE xp_regread @rootkey = 'HKEY_LOCAL_MACHINE', - @key = @cluster_key, + @key = @port_key, @value_name = 'tcpPort', @value = @Port OUTPUT; - insert into @GetAll(InstanceNames, InstanceIds, EditionNames, VersionNames, ClusterNames, Ports) Values( @InstanceName, @InstanceId, @Edition, @Version, @ClusterName, @Port ) + DECLARE @DynamicPort NVARCHAR(100); + EXECUTE xp_regread + @rootkey = 'HKEY_LOCAL_MACHINE', + @key = @port_key, + @value_name = 'TcpDynamicPorts', + @value = @DynamicPort OUTPUT; + + insert into @GetAll(InstanceNames, InstanceIds, EditionNames, VersionNames, ClusterNames, Ports, DynamicPorts) Values( @InstanceName, @InstanceId, @Edition, @Version, @ClusterName, @Port, @DynamicPort ) -- Get the next instance FETCH NEXT FROM instance_cursor INTO @InstanceName; @@ -98,7 +106,7 @@ END CLOSE instance_cursor; DEALLOCATE instance_cursor; -SELECT InstanceNames, InstanceIds, EditionNames, VersionNames, ClusterNames,Ports FROM @GetAll;"; +SELECT InstanceNames, InstanceIds, EditionNames, VersionNames, ClusterNames,Ports, DynamicPorts FROM @GetAll;"; pub const SYS_DATABASES: &str = "SELECT name FROM sys.databases"; diff --git a/packages/check-sql/tests/test_ms_sql.rs b/packages/check-sql/tests/test_ms_sql.rs index 5a19871f295..6d687597da6 100644 --- a/packages/check-sql/tests/test_ms_sql.rs +++ b/packages/check-sql/tests/test_ms_sql.rs @@ -29,7 +29,7 @@ fn is_instance_good(i: &InstanceEngine) -> bool { && i.id.contains(&i.name[..4]) && i.id.contains("MSSQL") && i.version.chars().filter(|&c| c == '.').count() == 3 - && i.port.is_none() + && i.port().is_some() && i.cluster.is_none() }