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` );
+ 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;