fixed errors
[ocsinventory-agent-cn.git] / Hostname.pm
index c576c58..f35ae2c 100644 (file)
@@ -1,22 +1,25 @@
 package Ocsinventory::Agent::Backend::OS::Generic::Hostname;
 
 sub check {
-    my $params = shift;
-    my $common = $params->{common};
-    return 1 if $common->can_run ("hostname");
-    0;
+  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 $common = $params->{common};
+  my $params = shift;
+  my $common = $params->{common};
 
-    my $hostname;
+  my $hostname;
 
-    chomp ( $hostname = `hostname -f` ); # TODO: This is not generic.
+  if (can_load("Sys::Hostname::Long")) {
+    $hostname = Sys::Hostname::Long::hostname_long();
+  } else {
+    chomp ( $hostname = `hostname --fqdn` ); # TODO: This is not generic.
+  }
 
-    $common->setHardware ({NAME => $hostname});
+  $common->setHardware ({NAME => $hostname});
 }
 
 1;