Skip to content

Commit

Permalink
add dynamic ports
Browse files Browse the repository at this point in the history
Change-Id: Ie412dac34c4bd2aec666d94e00c9fddc18597b15
  • Loading branch information
s-kipnis committed Nov 15, 2023
1 parent 954b3d1 commit ac4e274
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
10 changes: 9 additions & 1 deletion packages/check-sql/src/ms_sql/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub struct InstanceEngine {
pub version: String,
pub edition: String,
pub cluster: Option<String>,
pub port: Option<u16>,
port: Option<u16>,
dynamic_port: Option<u16>,
pub available: Option<bool>,
}

Expand All @@ -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<u16> {
self.port.or(self.dynamic_port)
}
}

impl Column for Row {
Expand Down Expand Up @@ -98,6 +103,9 @@ impl From<&Row> for InstanceEngine {
port: row
.get_optional_string(5)
.and_then(|s| s.parse::<u16>().ok()),
dynamic_port: row
.get_optional_string(6)
.and_then(|s| s.parse::<u16>().ok()),
available: None,
}
}
Expand Down
14 changes: 11 additions & 3 deletions packages/check-sql/src/ms_sql/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion packages/check-sql/tests/test_ms_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit ac4e274

Please sign in to comment.