Changeset 342


Ignore:
Timestamp:
Aug 30, 2018, 2:49:44 PM (6 years ago)
Author:
g7moreau
Message:
  • Better option for check dns
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r341 r342  
    26132613
    26142614   GetOptions(
    2615       'Direct|D'  => \$opt_direct,
     2615      'direct|d'  => \$opt_direct,
    26162616      'reverse|r' => \$opt_reverse,
    26172617      );
     
    26192619   my $computer_db = ipamdb_load($COMPUTER_YAML);
    26202620
    2621    LOOP_ON_DOMAINSET:
    2622    for my $domainset_current (keys %{$computer_db}) {
    2623       last LOOP_ON_DOMAINSET if $opt_direct;    # No DDT to DNS check
    2624       next if $domainset_current eq 'dset';
    2625       next if $domainset_current eq 'pool';
    2626       next if $domainset_current eq 'pxe';
    2627       next if $domainset_current eq 'tag';
    2628       next if $domainset_current eq 'version';
    2629 
    2630       my @domainsetdb = @{$computer_db->{$domainset_current}};
    2631 
    2632       LOOP_ON_COMPUTER:
    2633       for my $computer (@domainsetdb) {
    2634          my ($mac_address, $attribute) = %{$computer};
    2635          #my $new_mac = normalize_mac_address($mac_address);
    2636          my $ip = $attribute->{'ip'};
    2637          next LOOP_ON_COMPUTER if not $ip =~ m/$DDT::RE::IPv4_ADDRESS/xms;
    2638          next LOOP_ON_COMPUTER if $attribute->{'enabled'} eq 'no';
    2639 
    2640          my $dns_hostname_fq = scalar gethostbyaddr(inet_aton($ip), AF_INET);
    2641          my ($dns_hostname) = split /\./, $dns_hostname_fq;
    2642 
    2643          if ($attribute->{'hostname'} ne $dns_hostname) {
    2644             print "$mac_address ($domainset_current) $ip - $dns_hostname / $attribute->{'hostname'} # $attribute->{'comment'}\n";
    2645             next LOOP_ON_COMPUTER;
    2646             }
    2647 
    2648          my $packed_ip = scalar gethostbyname($dns_hostname_fq);
    2649          if (defined $packed_ip) {
    2650             my $ip_address = inet_ntoa($packed_ip);
    2651             if ($ip ne $ip_address) {
    2652                print "reverse DNS error for $dns_hostname_fq / $ip\n";
     2621   if ($opt_direct or not $opt_reverse) { # DDT to DNS check
     2622      LOOP_ON_DOMAINSET:
     2623      for my $domainset_current (keys %{$computer_db}) {
     2624         next if $domainset_current eq 'dset';
     2625         next if $domainset_current eq 'pool';
     2626         next if $domainset_current eq 'pxe';
     2627         next if $domainset_current eq 'tag';
     2628         next if $domainset_current eq 'version';
     2629
     2630         my @domainsetdb = @{$computer_db->{$domainset_current}};
     2631
     2632         LOOP_ON_COMPUTER:
     2633         for my $computer (@domainsetdb) {
     2634            my ($mac_address, $attribute) = %{$computer};
     2635            #my $new_mac = normalize_mac_address($mac_address);
     2636            my $ip = $attribute->{'ip'};
     2637            next LOOP_ON_COMPUTER if not $ip =~ m/$DDT::RE::IPv4_ADDRESS/xms;
     2638            next LOOP_ON_COMPUTER if $attribute->{'enabled'} eq 'no';
     2639
     2640            my $dns_hostname_fq = scalar gethostbyaddr(inet_aton($ip), AF_INET);
     2641            my ($dns_hostname) = split /\./, $dns_hostname_fq;
     2642
     2643            if ($attribute->{'hostname'} ne $dns_hostname) {
     2644               print "$mac_address ($domainset_current) $ip - $dns_hostname / $attribute->{'hostname'} # $attribute->{'comment'}\n";
    26532645               next LOOP_ON_COMPUTER;
    26542646               }
    2655             }
    2656          }
    2657       }
    2658 
    2659    if ($opt_reverse) {  # No DNS to DDT check
     2647
     2648            my $packed_ip = scalar gethostbyname($dns_hostname_fq);
     2649            if (defined $packed_ip) {
     2650               my $ip_address = inet_ntoa($packed_ip);
     2651               if ($ip ne $ip_address) {
     2652                  print "Error: bad IP for reverse DNS on $dns_hostname_fq / $ip\n";
     2653                  next LOOP_ON_COMPUTER;
     2654                  }
     2655               }
     2656            }
     2657         }
     2658      }
     2659
     2660   if ($opt_reverse) {  # DNS to DDT check
    26602661      my %saw; # count for unique member
    26612662      my @dns_domain_list = sort grep !$saw{$_}++,
     
    31493150 ddt change-mac [--hostname|-h hostname] [--domainset|-d domainset] [--ip|-i ip] [--mac|-m mac]
    31503151 ddt change-tag [--hostname|-h hostname] [--domainset|-d domainset] [--ip|-i ip] [--mac|-m mac] [--tag|-t tag]
    3151  ddt check-dns [--Direct] [--reverse]
     3152 ddt check-dns [--direct] [--reverse]
    31523153 ddt create-domainset [--domainset|-d domainset] [--dns-extension|-e dns_extension] [--comment|-c comment]
    31533154 ddt create-pool [--pool|-p pool] [--domainset|-d domainset] [--file-pool|-f file_pool] [--ipaddress-pool|-i ipaddress_pool]
     
    32433244 ddt change-mac [--hostname|-h hostname] [--domainset|-d domainset] [--ip|-i ip] [--mac|-m mac]
    32443245 ddt change-tag [--hostname|-h hostname] [--domainset|-d domainset] [--ip|-i ip] [--mac|-m mac] [--tag|-t tag]
    3245  ddt check-dns [--Direct] [--reverse]
     3246 ddt check-dns [--direct] [--reverse]
    32463247 ddt create-domainset [--domainset|-d domainset] [--dns-extension|-e dns_extension] [--comment|-c comment]
    32473248 ddt create-pool [--pool|-p pool] [--domainset|-d domainset] [--file-pool|-f file_pool] [--ipaddress-pool|-i ipaddress_pool]
     
    33323333=head2 check-dns
    33333334
    3334  ddt check-dns [--Direct] [--reverse]
     3335 ddt check-dns [--direct] [--reverse]
    33353336
    33363337=head2 create-domainset
Note: See TracChangeset for help on using the changeset viewer.