Skip to content

Commit

Permalink
feat : RMS_MGMT (#499)
Browse files Browse the repository at this point in the history
yes1n authored Sep 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8d387bc commit fb10e0c
Showing 3 changed files with 128 additions and 0 deletions.
74 changes: 74 additions & 0 deletions lib/GLPI/Agent/Task/Inventory/Generic/Remote_Mgmt/RMS.pm
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 added resources/generic/rms/rms-7.0.0.1-Parameters.reg
Binary file not shown.
54 changes: 54 additions & 0 deletions t/tasks/inventory/generic/remote_mgmt/rms.t
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);
};
}

0 comments on commit fb10e0c

Please sign in to comment.