X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=Hostname.pm;h=f35ae2c15209dfe54f3ea0c3aea67aceb7c4c3c5;hb=a76954d5163b3f12b40fe759416d1444b61c346a;hp=e641d8dd6744a7e991dc330c2521f2de20209728;hpb=be014671d2dc4deaf3238e3828d26a23b9b40e1a;p=ocsinventory-agent-cn.git diff --git a/Hostname.pm b/Hostname.pm index e641d8d..f35ae2c 100644 --- a/Hostname.pm +++ b/Hostname.pm @@ -1,34 +1,25 @@ package Ocsinventory::Agent::Backend::OS::Generic::Hostname; sub check { - eval { require (Sys::Hostname) }; - return 1 unless $@; - `which hostname 2>&1`; - return if ($? >> 8)!=0; - `hostname 2>&1`; - return if ($? >> 8)!=0; - 1; + return 1 if can_load ("Sys::Hostname::Long"); + return 1 if can_run ("hostname"); + 0; } # Initialise the distro entry sub run { my $params = shift; - my $inventory = $params->{inventory}; + my $common = $params->{common}; my $hostname; - # ico, Tue, 26 May 2009 17:58:27 +0200 - chomp ( my $hostname = `hostname --fqdn` ); - #eval { require (Sys::Hostname) }; - #if (!$@) { - # $hostname = Sys::Hostname::hostname(); - #} else { - # chomp ( $hostname = `hostname` ); # TODO: This is not generic. - #} - #$hostname =~ s/\..*//; # keep just the hostname + if (can_load("Sys::Hostname::Long")) { + $hostname = Sys::Hostname::Long::hostname_long(); + } else { + chomp ( $hostname = `hostname --fqdn` ); # TODO: This is not generic. + } - - $inventory->setHardware ({NAME => $hostname}); + $common->setHardware ({NAME => $hostname}); } 1;