-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat : RMS_MGMT (#499)
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package GLPI::Agent::Task::Inventory::Generic::Remote_Mgmt::RMS; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use parent 'GLPI::Agent::Task::Inventory::Module'; | ||
|
||
use English qw(-no_match_vars); | ||
use UNIVERSAL::require; | ||
|
||
use GLPI::Agent::Tools; | ||
|
||
sub isEnabled { | ||
my (%params) = @_; | ||
|
||
return 0 unless OSNAME eq 'MSWin32'; | ||
|
||
GLPI::Agent::Tools::Win32->use(); | ||
|
||
my $key = getRegistryKey( | ||
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Usoris/Remote Utilities Host/Host/Parameters', | ||
# Important for remote inventory optimization | ||
required => [ qw/InternetId/ ], | ||
maxdepth => 1, | ||
logger => $params{logger} | ||
); | ||
|
||
return defined($key) ? 1 : 0; | ||
} | ||
|
||
sub doInventory { | ||
my (%params) = @_; | ||
|
||
my $inventory = $params{inventory}; | ||
my $logger = $params{logger}; | ||
|
||
my $InternetID = _getID(logger => $logger); | ||
|
||
if (defined($InternetID)) { | ||
$logger->debug('Found InternetID : ' . $InternetID) if ($logger); | ||
|
||
$inventory->addEntry( | ||
section => 'REMOTE_MGMT', | ||
entry => { | ||
ID => $InternetID, | ||
TYPE => 'rms' | ||
} | ||
); | ||
} else { | ||
$logger->debug('InternetID not found') if ($logger); | ||
} | ||
} | ||
|
||
sub _getID { | ||
my (%params) = @_; | ||
|
||
GLPI::Agent::Tools::Win32->use(); | ||
GLPI::Agent::XML->use(); | ||
|
||
my $internetid = getRegistryValue( | ||
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Usoris/Remote Utilities Host/Host/Parameters/InternetId', | ||
%params | ||
); | ||
|
||
$internetid = hex2dec($internetid); | ||
|
||
my $tree = GLPI::Agent::XML->new(string => $internetid)->dump_as_hash(); | ||
|
||
return unless defined($tree) && defined($tree->{rms_internet_id_settings}); | ||
|
||
return $tree->{rms_internet_id_settings}->{internet_id}; | ||
} | ||
|
||
1; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use lib 't/lib'; | ||
|
||
use English qw(-no_match_vars); | ||
use Test::Deep qw(cmp_deeply); | ||
use Test::More; | ||
use Test::MockModule; | ||
use Test::NoWarnings; | ||
|
||
use GLPI::Test::Utils; | ||
|
||
use GLPI::Agent::Task::Inventory::Generic::Remote_Mgmt::RMS; | ||
|
||
BEGIN { | ||
# use mock modules for non-available ones | ||
push @INC, 't/lib/fake/windows' if $OSNAME ne 'MSWin32'; | ||
} | ||
|
||
my $module = Test::MockModule->new( | ||
'GLPI::Agent::Tools::Win32' | ||
); | ||
|
||
my %win32_tests = ( | ||
'7.0.0.1' => "891-759-358-441", | ||
); | ||
|
||
plan tests => (scalar keys %win32_tests) + 1; | ||
|
||
foreach my $test (keys(%win32_tests)) { | ||
$module->mock( | ||
'_getRegistryKey', | ||
_mockGetRegistryKey($test) | ||
); | ||
my $internetID = GLPI::Agent::Task::Inventory::Generic::Remote_Mgmt::RMS::_getID(); | ||
is($internetID, $win32_tests{$test}, "RMS win32 getID - $test"); | ||
} | ||
|
||
# Adapted from GLPI::Test::Utils mockGetRegistryKey() | ||
sub _mockGetRegistryKey { | ||
my ($test) = @_; | ||
|
||
return sub { | ||
my (%params) = @_; | ||
|
||
# We can mock getRegistryKey or better _getRegistryKey to cover getRegistryValue | ||
my $path = $params{path} || $params{keyName}; | ||
my $file = "resources/generic/rms/rms-$test-$path.reg"; | ||
return loadRegistryDump($file); | ||
}; | ||
} |