changed the monitoring code to use nmap for getting node status
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13778 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -2043,7 +2043,7 @@ sub get_hdwr_ip | ||||
|  | ||||
| #-------------------------------------------------------------------------------- | ||||
| =head3    pingNodeStatus | ||||
|       This function takes an array of nodes and returns their status using fping. | ||||
|       This function takes an array of nodes and returns their status using nmap or fping. | ||||
|     Arguments: | ||||
|        nodes-- an array of nodes. | ||||
|     Returns: | ||||
| @@ -2052,39 +2052,85 @@ sub get_hdwr_ip | ||||
| =cut | ||||
| #-------------------------------------------------------------------------------- | ||||
| sub pingNodeStatus { | ||||
|   my ($class, @mon_nodes)=@_; | ||||
|   my %status=(); | ||||
|   my @active_nodes=(); | ||||
|   my @inactive_nodes=(); | ||||
|   if ((@mon_nodes)&& (@mon_nodes > 0)) { | ||||
|     #get all the active nodes | ||||
|     my $nodes= join(' ', @mon_nodes); | ||||
|     my $temp=`fping -a $nodes 2> /dev/null`; | ||||
|     chomp($temp); | ||||
|     @active_nodes=split(/\n/, $temp); | ||||
|     my ($class, @mon_nodes)=@_; | ||||
|     my %status=(); | ||||
|     my @active_nodes=(); | ||||
|     my @inactive_nodes=(); | ||||
|     #print "NetworkUtils->pingNodeStatus called, nodes=@mon_nodes\n"; | ||||
|     if ((@mon_nodes)&& (@mon_nodes > 0)) { | ||||
| 	#get all the active nodes | ||||
| 	my $nodes= join(' ', @mon_nodes); | ||||
| 	if (-x '/usr/bin/nmap' or -x '/usr/local/bin/nmap') { #use nmap | ||||
| 	    #print "use nmap\n"; | ||||
| 	    my %deadnodes; | ||||
| 	    foreach (@mon_nodes) { | ||||
| 		$deadnodes{$_}=1; | ||||
| 	    }	  | ||||
| 	    open (NMAP, "nmap -PE --system-dns --send-ip -sP ". $nodes . " 2> /dev/null|") or die("Cannot open nmap pipe: $!"); | ||||
| 	    my $node; | ||||
| 	    while (<NMAP>) { | ||||
| 		if (/Host (.*) \(.*\) appears to be up/) { | ||||
| 		    $node=$1; | ||||
| 		    unless ($deadnodes{$node}) { | ||||
| 			foreach (keys %deadnodes) { | ||||
| 			    if ($node =~ /^$_\./) { | ||||
| 				$node = $_; | ||||
| 				last; | ||||
| 			    } | ||||
| 			} | ||||
| 		    } | ||||
| 		    delete $deadnodes{$node}; | ||||
| 		    push(@active_nodes, $node); | ||||
| 		} elsif (/Nmap scan report for ([^ ]*) /) { | ||||
| 		    $node=$1; | ||||
| 		} elsif (/Host is up./) { | ||||
| 		    unless ($deadnodes{$node}) { | ||||
| 			foreach (keys %deadnodes) { | ||||
| 			    if ($node =~ /^$_\./) { | ||||
| 				$node = $_; | ||||
| 			      last; | ||||
| 			    } | ||||
| 			} | ||||
| 		    } | ||||
| 		    delete $deadnodes{$node}; | ||||
| 		    push(@active_nodes, $node); | ||||
| 		} | ||||
| 	    } | ||||
| 	    foreach (sort keys %deadnodes) { | ||||
| 	      push(@inactive_nodes, $_); | ||||
| 	    } | ||||
| 	} else { #use fping | ||||
| 	    #print "use fping\n"; | ||||
|  | ||||
|     #get all the inactive nodes by substracting the active nodes from all. | ||||
|     my %temp2; | ||||
|     if ((@active_nodes) && ( @active_nodes > 0)) { | ||||
|       foreach(@active_nodes) { $temp2{$_}=1}; | ||||
|         foreach(@mon_nodes) { | ||||
|           if (!$temp2{$_}) { push(@inactive_nodes, $_);} | ||||
|         } | ||||
| 	    my $temp=`fping -a $nodes 2> /dev/null`; | ||||
| 	    chomp($temp); | ||||
| 	    @active_nodes=split(/\n/, $temp); | ||||
| 	     | ||||
| 	    #get all the inactive nodes by substracting the active nodes from all. | ||||
| 	    my %temp2; | ||||
| 	    if ((@active_nodes) && ( @active_nodes > 0)) { | ||||
| 		foreach(@active_nodes) { $temp2{$_}=1}; | ||||
| 		foreach(@mon_nodes) { | ||||
| 		    if (!$temp2{$_}) { push(@inactive_nodes, $_);} | ||||
| 		} | ||||
| 	    } | ||||
| 	    else {@inactive_nodes=@mon_nodes;} | ||||
| 	}      | ||||
|     } | ||||
|     else {@inactive_nodes=@mon_nodes;}      | ||||
|   } | ||||
|  | ||||
|   $status{$::STATUS_ACTIVE}=\@active_nodes; | ||||
|   $status{$::STATUS_INACTIVE}=\@inactive_nodes; | ||||
|   | ||||
|   return %status; | ||||
|      | ||||
|     $status{$::STATUS_ACTIVE}=\@active_nodes; | ||||
|     $status{$::STATUS_INACTIVE}=\@inactive_nodes; | ||||
|     #use Data::Dumper; | ||||
|     #print Dumper(%status); | ||||
|      | ||||
|     return %status; | ||||
| } | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
|  | ||||
| =head3  isReservedIP | ||||
|       Description : Validate whether specified string is a reseved IPv4 string. | ||||
|       Arguments   : ipstr - the string to be validated.  | ||||
|       Arguments   : ipstr - the string to be validated. | ||||
|       Returns     : 1 - valid reserved String. | ||||
|                     0 - invalid reserved String. | ||||
| =cut | ||||
| @@ -2104,7 +2150,7 @@ sub isReservedIP | ||||
|  | ||||
| =head3 isValidMAC | ||||
|       Description : Validate whether specified string is a MAC string. | ||||
|       Arguments   : macstr - the string to be validated.  | ||||
|       Arguments   : macstr - the string to be validated. | ||||
|       Returns     : 1 - valid MAC String. | ||||
|                     0 - invalid MAC String. | ||||
| =cut | ||||
| @@ -2123,7 +2169,7 @@ sub isValidMAC | ||||
|  | ||||
| =head3 isValidHostname | ||||
|       Description : Validate whether specified string is a valid hostname. | ||||
|       Arguments   : hostname - the string to be validated.  | ||||
|       Arguments   : hostname - the string to be validated. | ||||
|       Returns     : 1 - valid hostname String. | ||||
|                     0 - invalid hostname String. | ||||
| =cut | ||||
| @@ -2177,7 +2223,7 @@ sub int_to_ip | ||||
| #------------------------------------------------------------------------------- | ||||
|  | ||||
| =head3 get_allips_in_range | ||||
|       Description : Get all IPs in a IP range, return in a list.  | ||||
|       Description : Get all IPs in a IP range, return in a list. | ||||
|       Arguments   : $startip - start IP address | ||||
|                     $endip - end IP address | ||||
|                     $increment - increment factor | ||||
| @@ -2255,4 +2301,5 @@ sub get_all_nicips{ | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| 1; | ||||
|   | ||||
| @@ -12,6 +12,7 @@ use Sys::Hostname; | ||||
| use Socket; | ||||
| use xCAT::Utils; | ||||
| use xCAT::InstUtils; | ||||
| use xCAT::NetworkUtils; | ||||
| use xCAT::GlobalDef; | ||||
| use xCAT_monitoring::monitorctrl; | ||||
| use xCAT_monitoring::rmcmetrix; | ||||
| @@ -210,44 +211,6 @@ sub start { | ||||
| } | ||||
|  | ||||
|  | ||||
| #-------------------------------------------------------------------------------- | ||||
| =head3    pingNodeStatus | ||||
|       This function takes an array of nodes and returns their status using fping. | ||||
|     Arguments: | ||||
|        nodes-- an array of nodes. | ||||
|     Returns: | ||||
|        a hash that has the node status. The format is:  | ||||
|           {alive=>[node1, node3,...], unreachable=>[node4, node2...]} | ||||
| =cut | ||||
| #-------------------------------------------------------------------------------- | ||||
| sub pingNodeStatus { | ||||
|   my ($class, @mon_nodes)=@_; | ||||
|   my %status=(); | ||||
|   my @active_nodes=(); | ||||
|   my @inactive_nodes=(); | ||||
|   if ((@mon_nodes)&& (@mon_nodes > 0)) { | ||||
|     #get all the active nodes | ||||
|     my $nodes= join(' ', @mon_nodes); | ||||
|     my $temp=`fping -a $nodes 2> /dev/null`; | ||||
|     chomp($temp); | ||||
|     @active_nodes=split(/\n/, $temp); | ||||
|  | ||||
|     #get all the inactive nodes by substracting the active nodes from all. | ||||
|     my %temp2; | ||||
|     if ((@active_nodes) && ( @active_nodes > 0)) { | ||||
|       foreach(@active_nodes) { $temp2{$_}=1}; | ||||
|         foreach(@mon_nodes) { | ||||
|           if (!$temp2{$_}) { push(@inactive_nodes, $_);} | ||||
|         } | ||||
|     } | ||||
|     else {@inactive_nodes=@mon_nodes;}      | ||||
|   } | ||||
|  | ||||
|   $status{$::STATUS_ACTIVE}=\@active_nodes; | ||||
|   $status{$::STATUS_INACTIVE}=\@inactive_nodes; | ||||
|   | ||||
|   return %status; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| @@ -1028,7 +991,7 @@ sub addNodes { | ||||
|   #find in active nodes | ||||
|   my $inactive_nodes=[]; | ||||
|   if ($scope) {  | ||||
|     my %nodes_status=xCAT_monitoring::rmcmon->pingNodeStatus(@mon_nodes);  | ||||
|     my %nodes_status=xCAT::NetworkUtils->pingNodeStatus(@mon_nodes);  | ||||
|     $inactive_nodes=$nodes_status{$::STATUS_INACTIVE}; | ||||
|     #print "active nodes to add:@$active_nodes\ninactive nodes to add: @$inactive_nodes\n"; | ||||
|     if (@$inactive_nodes>0) {  | ||||
| @@ -1266,7 +1229,7 @@ sub removeNodes { | ||||
|   #find in active nodes | ||||
|   my $inactive_nodes=[]; | ||||
|   if ($scope) {  | ||||
|     my %nodes_status=xCAT_monitoring::rmcmon->pingNodeStatus(@mon_nodes);  | ||||
|     my %nodes_status=xCAT::NetworkUtils->pingNodeStatus(@mon_nodes);  | ||||
|     $inactive_nodes=$nodes_status{$::STATUS_INACTIVE}; | ||||
|     #print "active nodes to add:@$active_nodes\ninactive nodes to add: @$inactive_nodes\n"; | ||||
|     if (@$inactive_nodes>0) {  | ||||
|   | ||||
| @@ -8,6 +8,7 @@ BEGIN | ||||
| use lib "$::XCATROOT/lib/perl"; | ||||
| use strict; | ||||
| use xCAT::Utils; | ||||
| use xCAT::NetworkUtils; | ||||
| use xCAT::GlobalDef; | ||||
| use xCAT_monitoring::monitorctrl; | ||||
| use Sys::Hostname; | ||||
| @@ -414,7 +415,7 @@ sub getDescription { | ||||
|     status values for the nodes.   Use  command 'monadd xcatmon -n' and then  | ||||
|     'monstart xcatmon'  to start monitoring.  | ||||
|   Settings: | ||||
|     ping-interval:  the number of minutes between each fping operation.  | ||||
|     ping-interval:  the number of minutes between each nmap/fping operation.  | ||||
|         The default value is 3. | ||||
|     apps: a list of comma separated application names whose status will be queried.  | ||||
|         For how to get the status of each app, look for app name in the key filed  | ||||
|   | ||||
| @@ -7,6 +7,7 @@ BEGIN | ||||
| use lib "$::XCATROOT/lib/perl"; | ||||
| use xCAT::GlobalDef; | ||||
| use xCAT::Table; | ||||
| use xCAT::NetworkUtils; | ||||
| use xCAT_monitoring::xcatmon; | ||||
| ################################################################# | ||||
| # This script is used as a cron job by the xCAT monitoring plug-in | ||||
| @@ -30,11 +31,11 @@ my $tmp_node_unknown=$nodes_status_old{unknown}; | ||||
|  | ||||
| #get current node status | ||||
| my %nodes_status_new1=(); | ||||
| if ($tmp_node_active) { %nodes_status_new1=pingNodeStatus(@$tmp_node_active);}  | ||||
| if ($tmp_node_active) { %nodes_status_new1=xCAT::NetworkUtils->pingNodeStatus(@$tmp_node_active);}  | ||||
| my %nodes_status_new2=(); | ||||
| if ($tmp_node_inactive) {%nodes_status_new2=pingNodeStatus(@$tmp_node_inactive);} | ||||
| if ($tmp_node_inactive) {%nodes_status_new2=xCAT::NetworkUtils->pingNodeStatus(@$tmp_node_inactive);} | ||||
| my %nodes_status_new3=(); | ||||
| if ($tmp_node_unknown) { %nodes_status_new3=pingNodeStatus(@$tmp_node_unknown);} | ||||
| if ($tmp_node_unknown) { %nodes_status_new3=xCAT::NetworkUtils->pingNodeStatus(@$tmp_node_unknown);} | ||||
|  | ||||
| my $changed1=$nodes_status_new1{$::STATUS_INACTIVE}; | ||||
| my $changed2=$nodes_status_new2{$::STATUS_ACTIVE}; | ||||
| @@ -66,44 +67,5 @@ if (keys(%node_status) > 0) { | ||||
|  | ||||
|  | ||||
|  | ||||
| #-------------------------------------------------------------------------------- | ||||
| =head3    pingNodeStatus | ||||
|       This function takes an array of nodes and returns their status using fping. | ||||
|     Arguments: | ||||
|        nodes-- an array of nodes. | ||||
|     Returns: | ||||
|        a hash that has the node status. The format is:  | ||||
|           {alive=>[node1, node3,...], unreachable=>[node4, node2...]} | ||||
| =cut | ||||
| #-------------------------------------------------------------------------------- | ||||
| sub pingNodeStatus { | ||||
|   my @mon_nodes=@_; | ||||
|   %status=(); | ||||
|   my @active_nodes=(); | ||||
|   my @inactive_nodes=(); | ||||
|   if ((@mon_nodes)&& (@mon_nodes > 0)) { | ||||
|     #get all the active nodes | ||||
|     #TODO how to decide the path of fping. how about AIX, does it support fping? | ||||
|     my $nodes= join(' ', @mon_nodes); | ||||
|     my $temp=`fping -a $nodes 2> /dev/null`; | ||||
|     chomp($temp); | ||||
|     @active_nodes=split(/\n/, $temp); | ||||
|  | ||||
|     #get all the inactive nodes by substracting the active nodes from all. | ||||
|     my %temp2; | ||||
|     if ((@active_nodes) && ( @active_nodes > 0)) { | ||||
|       foreach(@active_nodes) { $temp2{$_}=1}; | ||||
|         foreach(@mon_nodes) { | ||||
|           if (!$temp2{$_}) { push(@inactive_nodes, $_);} | ||||
|         } | ||||
|     } | ||||
|     else {@inactive_nodes=@mon_nodes;}      | ||||
|   } | ||||
|  | ||||
|    | ||||
|   $status{$::STATUS_ACTIVE}=\@active_nodes; | ||||
|   $status{$::STATUS_INACTIVE}=\@inactive_nodes; | ||||
|   | ||||
|   return %status; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user