Skip to content

Commit

Permalink
feat: Add fqdn support case fro assetname-support option
Browse files Browse the repository at this point in the history
Support assetname-support option working for remoteinventory
  • Loading branch information
g-bougard committed Nov 23, 2023
1 parent 4643fd3 commit 818f949
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Revision history for GLPI agent

inventory:
* PR #531: Add SentinelOne Antivirus support on Linux, thanks to @MarcSamD
* Feature: Update support assetname-support as option for agent on most unix
if 1 (the default), the short hostname is used as asset name
if 2, the as-is hostname (can be fqdn) is used as asset name
if 3, the fqdn hostname is used as asset name
this feature does not apply on MacOS or Windows
this feature now works for remote ssh and for option 3, it requires perl installed
on targeted computer and perl mode enabled on defined remote.

netdiscovery/netinventory:
* Enhanced Toshiba printers support
Expand Down
2 changes: 1 addition & 1 deletion lib/GLPI/Agent/Task/Inventory/Generic/Domains.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sub doInventory {

# attempt to deduce the actual domain from the host name
# and fallback on the domain search list
my $hostname = getHostname();
my $hostname = getHostname(fqdn => 1);
my $pos = index $hostname, '.';

if ($pos > 0) {
Expand Down
2 changes: 2 additions & 0 deletions lib/GLPI/Agent/Task/Inventory/Generic/Hostname.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ sub doInventory {
my $hostname;
if ($assetname_support == 2) {
$hostname = getHostname();
} elsif ($assetname_support == 3) {
$hostname = getHostname(fqdn => 1);
} else {
$hostname = getHostname(short => 1);
}
Expand Down
34 changes: 27 additions & 7 deletions lib/GLPI/Agent/Tools/Hostname.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ BEGIN {
sub getHostname {
my (%params) = @_;

my $remote = $GLPI::Agent::Tools::remote;
return $remote->getRemoteHostname() if $remote;
my $hostname;

my $hostname = $OSNAME eq 'MSWin32' ?
_getHostnameWindows() :
_getHostnameUnix() ;
my $remote = $GLPI::Agent::Tools::remote;
if ($remote) {
if ($params{fqdn}) {
$hostname = $remote->getRemoteFQDN()
and $hostname =~ s/\.$//; # the module may return a trailing dot
}
# Fallback on getgetRemoteHostname if fqdn was requested and failed
$hostname = $remote->getRemoteHostname()
if empty($hostname);
} else {
$hostname = $OSNAME eq 'MSWin32' ? _getHostnameWindows() : _getHostnameUnix(%params);
}

# Support assetname-support = 1 option
if ($params{short}) {
$hostname =~ s/\..*$//;
}
Expand All @@ -45,9 +54,20 @@ sub getHostname {
}

sub _getHostnameUnix {
my (%params) = @_;

Sys::Hostname->require();
return Sys::Hostname::hostname();
my $hostname;

if ($params{fqdn}) {
Net::Domain->require();
$hostname = Net::Domain::hostfqdn();
$hostname =~ s/\.$//; # the module may return a trailing dot
} else {
Sys::Hostname->require();
$hostname = Sys::Hostname::hostname();
}

return $hostname;
}

sub _getHostnameWindows {
Expand Down

0 comments on commit 818f949

Please sign in to comment.