Skip to content

Commit

Permalink
fix: Enhanced MSSQL database inventory on Windows
Browse files Browse the repository at this point in the history
Close #675
  • Loading branch information
g-bougard committed May 24, 2024
1 parent dd4eee6 commit 17f77e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Inventory:
inventory as this is required by GLPI. This fixes issues with full-inventory-postpone
new feature introduced in 1.8 and with --partial glpi-inventory script option.
* fix #673: Fix support of network port type on MacOSX
* fix #675: Enhanced MSSQL database inventory on Windows by discovering installed
instances.

netdiscovery/netinventory:
* fix #642: Support snmp-retries configuration parameter to set snmp requests
Expand Down
25 changes: 24 additions & 1 deletion lib/GLPI/Agent/Task/Inventory/Generic/Databases/MSSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use English qw(-no_match_vars);
use strict;
use warnings;

use UNIVERSAL::require;

use parent 'GLPI::Agent::Task::Inventory::Generic::Databases';

use GLPI::Agent::Tools;
Expand Down Expand Up @@ -39,8 +41,27 @@ sub _getDatabaseService {
my $credentials = delete $params{credentials};
return [] unless $credentials && ref($credentials) eq 'ARRAY';

# Add SQLExpress default credential when trying default credential
# Handle default credentials case
if (@{$credentials} == 1 && !keys(%{$credentials->[0]})) {
# On windows, we can discover instance names in registry
if (OSNAME eq 'MSWin32') {
GLPI::Agent::Tools::Win32->require();
my $instances = GLPI::Agent::Tools::Win32::getRegistryKey(
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SQL Server/Instance Names/SQL',
);
foreach my $key (%{$instances}) {
# Only consider valuename keys
my ($instance) = $key =~ m{^/(.+)$}
or next;
# Default credentials will still match MSSQLSERVER instance
next if $instance eq 'MSSQLSERVER';
push @{$credentials}, {
type => "_discovered_instance",
instance => $instance,
};
}
}
# Add SQLExpress default credential when trying default credential
push @{$credentials}, {
type => "login_password",
socket => "localhost\\SQLExpress",
Expand Down Expand Up @@ -197,6 +218,8 @@ sub _mssqlOptions {
$credential->{password} =~ s/"/\\"/g;
$options .= ' -P "'.$credential->{password}.'"' ;
}
} elsif ($credential->{type} eq "_discovered_instance" && $credential->{instance}) {
$options .= " -S .\\$credential->{instance}" ;
}

return $options;
Expand Down

0 comments on commit 17f77e5

Please sign in to comment.