source: ocsinventory-agent/trunk/fuentes/lib/Ocsinventory/Agent/Backend/OS/Linux/Domains.pm @ 468

Last change on this file since 468 was 468, checked in by mabarracus, 4 years ago

Copyt trusty code

File size: 880 bytes
Line 
1package Ocsinventory::Agent::Backend::OS::Linux::Domains;
2use strict;
3
4sub check {
5  return unless can_run ("hostname");
6  my @domain = `hostname -d`;
7  return 1 if @domain || can_read ("/etc/resolv.conf");
8  0;
9}
10sub run {
11  my $params = shift;
12  my $common = $params->{common};
13
14  my $domain;
15  my %domain;
16  my @dns_list;
17  my $dns;
18  chomp($domain = `hostname -d`);
19
20  open RESOLV, "/etc/resolv.conf" or warn;
21    while(<RESOLV>){
22      if (/^nameserver\s+(\S+)/i) {
23        push(@dns_list,$1);
24      }
25      elsif (!$domain) {
26        $domain{$2} = 1 if (/^(domain|search)\s+(.+)/);
27      }
28    }
29  close RESOLV;
30
31  if (!$domain) {
32    $domain = join "/", keys %domain;
33  }
34 
35  $dns=join("/",@dns_list);
36  # If no domain name, we send "WORKGROUP"
37  $domain = 'WORKGROUP' unless $domain;
38
39  $common->setHardware({
40      WORKGROUP => $domain,
41      DNS => $dns
42    });
43
44}
45
461;
Note: See TracBrowser for help on using the repository browser.