diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index f49fb3253..831bae20a 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -4711,5 +4711,4 @@ sub get_nmapversion { return $nmap_version; } - 1; diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm index 4d0a99052..a02ca4d1c 100755 --- a/xCAT-server/lib/perl/xCAT/SvrUtils.pm +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -1163,6 +1163,7 @@ sub update_tables_with_diskless_image nodes: a reference to nodes array display: whether just display the result, if not 'yes', the result will be written to the mac table. + nopping: will not call pping subroutine if it set as "nopping" Returns: Return a hash with node name as key Globals: @@ -1170,7 +1171,7 @@ sub update_tables_with_diskless_image Error: none Example: - xCAT::Utils->get_mac_by_arp($nodes, $display); + xCAT::Utils->get_mac_by_arp($nodes, $display, $nopping); Comments: =cut @@ -1178,26 +1179,28 @@ sub update_tables_with_diskless_image #------------------------------------------------------------------------------- sub get_mac_by_arp () { - my ($class, $nodes, $display) = @_; + my ($class, $nodes, $display, $nopping) = @_; my $node; my $data; my %ret = (); my $unreachable_nodes = ""; my $noderange = join (',', @$nodes); - my @output = xCAT::Utils->runcmd("/opt/xcat/bin/pping $noderange", -1); - - foreach my $line (@output) { - my ($hostname, $result) = split ':', $line; - my ($token, $status) = split ' ', $result; - chomp($token); - if ($token eq 'ping') { - $node->{$hostname}->{reachable} = 1; + + if ( $nopping ne "nopping" ) { + my @output = xCAT::Utils->runcmd("/opt/xcat/bin/pping $noderange", -1); + foreach my $line (@output) { + my ($hostname, $result) = split ':', $line; + my ($token, $status) = split ' ', $result; + chomp($token); + if ($token eq 'ping') { + $node->{$hostname}->{reachable} = 1; + } } } foreach my $n ( @$nodes ) { - if ( $node->{$n}->{reachable} ) { + if ( ( $node->{$n}->{reachable} ) || ( $nopping eq "nopping" ) ){ my $output; my $IP = xCAT::NetworkUtils::toIP( $n ); if ( xCAT::Utils->isAIX() ) { diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index 344997d2b..38c7e3546 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -13,6 +13,7 @@ use xCAT::Usage; use xCAT::NodeRange; use xCAT::NetworkUtils; use xCAT::Utils; +use xCAT::SvrUtils; use XML::Simple; no strict; use Data::Dumper; @@ -826,13 +827,19 @@ sub snmp_scan { my $ranges = get_ip_ranges($request); - #use nmap to find if snmp port is enabled - # only open port will be scan + ########################################################## + #use nmap to parse the ip range and possible output from the command: + # Nmap scan report for switch-10-5-22-1 (10.5.22.1) 161/udp open snmp + # Nmap scan report for 10.5.23.1 161/udp open snmp + # Nmap scan report for 10.5.24.1 161/udp closed snmp + # Host 10.5.23.1 appears to be up ... good. 161/udp open|filtered snmp + # Host 10.5.24.1 appears to be up ... good. 161/udp closed snmp + ########################################################## my $nmap_version = xCAT::Utils->get_nmapversion(); if (xCAT::Utils->version_cmp($nmap_version,"5.10") < 0) { - $ccmd = "/usr/bin/nmap -P0 -v -sU -p 161 -oA snmp_scan @$ranges | grep up | grep good "; + $ccmd = "/usr/bin/nmap -P0 -v -sU -p 161 -oA snmp_scan @$ranges | grep -E 'appears to be up|^161' | perl -pe 's/\\n/ / if \$. % 2'"; } else { - $ccmd = "/usr/bin/nmap -P0 -v -sU -p 161 -oA snmp_scan @$ranges | grep 'open port 161' "; + $ccmd = "/usr/bin/nmap -P0 -v -sU -p 161 -oA snmp_scan @$ranges | grep -v 'host down' | grep -E 'Nmap scan report|^161' | perl -pe 's/\\n/ / if \$. % 2'"; } if (exists($globalopt{verbose})) { send_msg($request, 0, "Process command: $ccmd\n"); @@ -855,19 +862,28 @@ sub snmp_scan { foreach my $line (@lines) { my @array = split / /, $line; - my $ip; - if (xCAT::Utils->version_cmp($nmap_version,"5.10") < 0) { - $ip = $array[1]; - } else { - $ip = $array[5]; + if ($line =~ /\b(\d{1,3}(?:\.\d{1,3}){3})\b/) + { + $ip = $1; } if (exists($globalopt{verbose})) { send_msg($request, 0, "Run snmpwalk command to get information for $ip"); } + if ($line =~ /close/) { + send_msg($request, 0, "*** snmp port is disabled for $ip ***"); + next; + } + my $vendor = get_snmpvendorinfo($request, $ip); if ($vendor) { - my $mac = get_snmpmac($request, $ip); + my $display = ""; + my $nopping = "nopping"; + my $output = xCAT::SvrUtils->get_mac_by_arp([$ip], $display, $nopping); + my ($desc,$mac) = split /: /, $output->{$ip}; + if (exists($globalopt{verbose})) { + send_msg($request, 0, "node: $ip, mac: $mac"); + } if (!$mac) { $mac="nomac_nmap_$counter"; $counter++;