2008-02-25 22:00:46 +00:00
|
|
|
package xCAT_plugin::nodestat;
|
2010-02-01 16:18:49 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
|
|
|
|
|
2008-07-18 19:59:20 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2008-02-25 22:00:46 +00:00
|
|
|
|
2010-02-01 16:18:49 +00:00
|
|
|
|
|
|
|
|
2008-02-25 22:00:46 +00:00
|
|
|
use Socket;
|
2012-06-27 13:35:55 +00:00
|
|
|
my $inet6support = eval {
|
|
|
|
require Socket6;
|
|
|
|
require IO::Socket::INET6;
|
|
|
|
1;
|
|
|
|
};
|
2008-02-25 23:48:15 +00:00
|
|
|
use IO::Handle;
|
2008-10-31 19:12:14 +00:00
|
|
|
use Getopt::Long;
|
2010-02-01 16:18:49 +00:00
|
|
|
use Data::Dumper;
|
|
|
|
use xCAT::GlobalDef;
|
2010-05-10 09:04:59 +00:00
|
|
|
use xCAT::NetworkUtils;
|
2012-08-09 04:07:40 +00:00
|
|
|
require xCAT::Utils;
|
|
|
|
require xCAT::TableUtils;
|
|
|
|
require xCAT::ServiceNodeUtils;
|
2010-02-01 16:18:49 +00:00
|
|
|
|
2009-04-07 15:47:42 +00:00
|
|
|
my %nodesetstats;
|
2011-05-23 18:32:29 +00:00
|
|
|
my %chainhash;
|
2010-02-01 16:18:49 +00:00
|
|
|
my %default_ports = (
|
2010-02-02 18:35:28 +00:00
|
|
|
'ftp' => '21',
|
|
|
|
'ssh' => '22',
|
|
|
|
'sshd' => '22',
|
|
|
|
'pbs' => '15002',
|
|
|
|
'pbs_mom' => '15002',
|
|
|
|
'xend' => '8002',
|
|
|
|
'll' => '9616',
|
|
|
|
'loadl' => '9616',
|
|
|
|
'loadl_master' => '9616',
|
|
|
|
'loadleveler' => '9616',
|
2011-09-12 17:37:27 +00:00
|
|
|
'gpfs' => '1191',
|
|
|
|
'rdp' => '3389',
|
|
|
|
'msrpc' => '135',
|
2010-02-01 16:18:49 +00:00
|
|
|
);
|
2008-02-25 22:00:46 +00:00
|
|
|
|
|
|
|
sub handled_commands {
|
|
|
|
return {
|
|
|
|
nodestat => 'nodestat',
|
2010-03-16 20:29:56 +00:00
|
|
|
nodestat_internal => 'nodestat',
|
2008-02-25 22:00:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-04-06 21:35:48 +00:00
|
|
|
sub pinghost {
|
|
|
|
my $node = shift;
|
|
|
|
my $rc = system("ping -q -n -c 1 -w 1 $node > /dev/null");
|
|
|
|
if ($rc == 0) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub nodesockopen {
|
|
|
|
my $node = shift;
|
|
|
|
my $port = shift;
|
|
|
|
my $socket;
|
|
|
|
my $addr = gethostbyname($node);
|
|
|
|
my $sin = sockaddr_in($port,$addr);
|
|
|
|
my $proto = getprotobyname('tcp');
|
|
|
|
socket($socket,PF_INET,SOCK_STREAM,$proto) || return 0;
|
|
|
|
connect($socket,$sin) || return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-02-25 22:00:46 +00:00
|
|
|
sub installer_query {
|
|
|
|
my $node = shift;
|
|
|
|
my $destport = 3001;
|
|
|
|
my $socket;
|
|
|
|
my $text = "";
|
2012-06-27 13:35:55 +00:00
|
|
|
if ($inet6support) {
|
|
|
|
$socket = IO::Socket::INET6->new(PeerAddr => $node, PeerPort => 3001);
|
|
|
|
unless ($socket) { return 0; }
|
|
|
|
} else {
|
|
|
|
my $proto = getprotobyname('tcp');
|
|
|
|
socket($socket,PF_INET,SOCK_STREAM,$proto) || return 0;
|
|
|
|
my $addr = gethostbyname($node);
|
|
|
|
my $sin = sockaddr_in($destport,$addr);
|
|
|
|
connect($socket,$sin) || return 0;
|
|
|
|
}
|
2008-02-25 23:48:15 +00:00
|
|
|
print $socket "stat \n";
|
|
|
|
$socket->flush;
|
2008-02-25 22:00:46 +00:00
|
|
|
while (<$socket>) {
|
|
|
|
$text.=$_;
|
|
|
|
}
|
2008-02-26 00:07:46 +00:00
|
|
|
$text =~ s/\n.*//;
|
2008-02-25 22:00:46 +00:00
|
|
|
return $text;
|
|
|
|
close($socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 14:25:58 +00:00
|
|
|
sub getstat {
|
|
|
|
my $response = shift;
|
2009-04-07 15:47:42 +00:00
|
|
|
foreach (@{$response->{node}}) {
|
|
|
|
$nodesetstats{$_->{name}->[0]} = $_->{data}->[0];
|
|
|
|
}
|
2008-02-26 14:25:58 +00:00
|
|
|
}
|
2008-02-25 22:00:46 +00:00
|
|
|
|
2008-04-15 14:37:26 +00:00
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 preprocess_request
|
|
|
|
|
|
|
|
Check and setup for hierarchy
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub preprocess_request
|
|
|
|
{
|
|
|
|
my $req = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my %sn;
|
2010-03-16 20:29:56 +00:00
|
|
|
|
2009-09-16 17:58:41 +00:00
|
|
|
if ((defined($req->{_xcatpreprocessed})) &&
|
|
|
|
($req->{_xcatpreprocessed}->[0] == 1)) {
|
|
|
|
return [$req];
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
|
2010-03-16 20:29:56 +00:00
|
|
|
my $command = $req->{command}->[0];
|
|
|
|
if ($command eq "nodestat") {
|
|
|
|
|
|
|
|
@ARGV=();
|
|
|
|
my $args=$req->{arg};
|
|
|
|
if ($args) {
|
2010-02-01 16:18:49 +00:00
|
|
|
@ARGV = @{$args};
|
2010-03-16 20:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# parse the options
|
|
|
|
$::UPDATE=0;
|
|
|
|
$::QUITE=0;
|
|
|
|
$::MON=0;
|
2010-03-19 14:57:57 +00:00
|
|
|
$::POWER=0;
|
2010-03-16 20:29:56 +00:00
|
|
|
#Getopt::Long::Configure("posix_default");
|
|
|
|
#Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
$Getopt::Long::ignorecase=0;
|
|
|
|
if (!GetOptions(
|
|
|
|
'm|usemon' => \$::MON,
|
|
|
|
'q|quite' => \$::QUITE, #this is a internal flag used by monitoring
|
|
|
|
'u|updatedb' => \$::UPDATE,
|
2010-03-19 14:57:57 +00:00
|
|
|
'p|powerstat' => \$::POWER,
|
2010-03-16 20:29:56 +00:00
|
|
|
'h|help' => \$::HELP,
|
|
|
|
'v|version' => \$::VERSION))
|
|
|
|
{
|
|
|
|
&usage($cb);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
if ($::HELP) {
|
|
|
|
&usage($cb);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if ($::VERSION) {
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
my $rsp={};
|
|
|
|
$rsp->{data}->[0] = "$version";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $cb);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
my $nodes = $req->{node};
|
|
|
|
if (!$nodes)
|
|
|
|
{
|
|
|
|
&usage($cb);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$req->{'update'}->[0]=$::UPDATE;
|
|
|
|
$req->{'quite'}->[0]=$::QUITE;
|
|
|
|
$req->{'mon'}->[0]=$::MON;
|
2010-03-19 14:57:57 +00:00
|
|
|
$req->{'power'}->[0]=$::POWER;
|
2010-03-16 20:29:56 +00:00
|
|
|
return [$req];
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2010-03-16 20:29:56 +00:00
|
|
|
|
|
|
|
#the following is for nodestat_internal command
|
2008-04-15 14:37:26 +00:00
|
|
|
my $nodes = $req->{node};
|
|
|
|
my $service = "xcat";
|
2008-04-18 19:38:34 +00:00
|
|
|
my @requests;
|
2010-02-01 16:18:49 +00:00
|
|
|
if ($nodes) {
|
|
|
|
my $usenmapfrommn=0;
|
|
|
|
if (-x '/usr/bin/nmap' or -x '/usr/local/bin/nmap') {
|
2012-05-23 05:17:42 +00:00
|
|
|
#my $sitetab = xCAT::Table->new('site');
|
|
|
|
#if ($sitetab) {
|
|
|
|
#(my $ref) = $sitetab->getAttribs({key => 'useNmapfromMN'}, 'value');
|
2012-08-09 04:07:40 +00:00
|
|
|
my @entries = xCAT::TableUtils->get_site_attribute("useNmapfromMN");
|
2012-05-23 05:17:42 +00:00
|
|
|
my $t_entry = $entries[0];
|
|
|
|
if (defined($t_entry)) {
|
|
|
|
if ($t_entry =~ /1|yes|YES|Y|y/) { $usenmapfrommn=1; }
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2012-05-23 05:17:42 +00:00
|
|
|
#}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#get monsettings
|
|
|
|
my %apps = ();
|
2010-03-16 20:29:56 +00:00
|
|
|
my $mon=$req->{'mon'}->[0];
|
|
|
|
if ($mon == 1) { %apps=getStatusMonsettings(); }
|
2010-02-01 16:18:49 +00:00
|
|
|
|
|
|
|
#if no apps specified in the monsetting table, add sshd, pbs and xend
|
|
|
|
if (keys(%apps) == 0) {
|
|
|
|
$apps{'sshd'}->{'group'} = "ALL"; #ALL means anything on the nodelist table, it is different from all
|
|
|
|
$apps{'sshd'}->{'port'} = "22";
|
2012-08-08 20:59:29 +00:00
|
|
|
$apps{'https'}->{'group'} = "ALL"; #ALL means anything on the nodelist table, it is different from all
|
|
|
|
$apps{'https'}->{'port'} = "443";
|
2010-02-01 16:18:49 +00:00
|
|
|
$apps{'pbs'}->{'group'} = "ALL";
|
|
|
|
$apps{'pbs'}->{'port'} = "15002";
|
|
|
|
$apps{'xend'}->{'group'} = "ALL";
|
|
|
|
$apps{'xend'}->{'port'} = "8002";
|
2011-09-12 17:37:27 +00:00
|
|
|
$apps{'rdp'}->{'group'} = "ALL";
|
|
|
|
$apps{'rdp'}->{'port'} = "3389";
|
|
|
|
$apps{'msrpc'}->{'group'} = "ALL";
|
|
|
|
$apps{'msrpc'}->{'port'} = "135";
|
2012-08-08 20:59:29 +00:00
|
|
|
$apps{'APPS'}=['sshd', 'https', 'pbs', 'xend'];
|
2010-02-01 16:18:49 +00:00
|
|
|
} else {
|
|
|
|
#go thorugh the settings and put defaults in
|
|
|
|
foreach my $app (keys(%apps)) {
|
|
|
|
if ($app eq 'APPS') { next; }
|
|
|
|
if (!exists($apps{$app}->{'group'})) { $apps{$app}->{'group'} = "ALL"; }
|
2010-10-29 18:18:03 +00:00
|
|
|
if (exists($apps{$app}->{'cmd'}) || exists($apps{$app}->{'dcmd'}) || exists($apps{$app}->{'lcmd'})) { next; }
|
2010-02-01 16:18:49 +00:00
|
|
|
if (exists($apps{$app}->{'port'})) { next; }
|
|
|
|
#add port number in if nothing is specified
|
|
|
|
if (exists($default_ports{$app})) { $apps{$app}->{'port'} = $default_ports{$app}; }
|
|
|
|
else {
|
2010-02-02 17:58:28 +00:00
|
|
|
my $p=`grep "^$app" /etc/services`;
|
|
|
|
if ($? == 0) {
|
|
|
|
my @a_list=sort(split('\n', $p));
|
|
|
|
my @a_temp=split('/',$a_list[0]);
|
|
|
|
my @a=split(' ', $a_temp[0]);
|
|
|
|
$apps{$app}->{'port'}=$a[1];
|
|
|
|
} else {
|
|
|
|
my $rsp={};
|
|
|
|
$rsp->{data}->[0]= "Cannot find port number for application $app. Please either specify a port number or a command in monsetting table for $app.";;
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $cb);
|
|
|
|
return (0);
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#always add sshd
|
|
|
|
if (!exists($apps{'ssh'}) || !exists($apps{'sshd'}) ) {
|
|
|
|
$apps{'sshd'}->{'group'} = "ALL";
|
|
|
|
$apps{'sshd'}->{'port'} = "22";
|
|
|
|
my $pa=$apps{'APPS'};
|
|
|
|
push @$pa, 'sshd';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#print Dumper(%apps);
|
|
|
|
# find service nodes for requested nodes
|
|
|
|
# build an individual request for each service node
|
2012-08-09 04:07:40 +00:00
|
|
|
my $sn = xCAT::ServiceNodeUtils->get_ServiceNode($nodes, $service, "MN");
|
2010-02-01 16:18:49 +00:00
|
|
|
|
|
|
|
#get the member for each group
|
|
|
|
my %groups=();
|
|
|
|
foreach my $app (keys %apps) {
|
|
|
|
if ($app eq 'APPS') { next; }
|
|
|
|
my $group=$apps{$app}->{'group'};
|
|
|
|
if (($group) && ($group ne "ALL") && (! exists($groups{$group}))) {
|
|
|
|
my @tmp_nodes = xCAT::NodeRange::noderange($group);
|
|
|
|
foreach (@tmp_nodes) {
|
|
|
|
$groups{$group}->{$_}=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# build each request for each service node
|
|
|
|
my $all_apps=$apps{'APPS'};
|
|
|
|
my %all_porthash=(); #stores all the port apps if usenmapfrommn=1
|
2010-10-29 18:18:03 +00:00
|
|
|
my %lcmdhash=(); #('myapp2,myapp3'=> {
|
|
|
|
# lcmd=>'/tmp/mycmd1,/usr/bin/date',
|
|
|
|
# node=>[node1,node2]
|
|
|
|
# }
|
|
|
|
#)
|
2010-02-01 16:18:49 +00:00
|
|
|
foreach my $snkey (keys %$sn)
|
|
|
|
{
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{node} = $sn->{$snkey};
|
2008-04-15 14:37:26 +00:00
|
|
|
$reqcopy->{'_xcatdest'} = $snkey;
|
2009-07-15 15:32:16 +00:00
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
2008-04-15 14:37:26 +00:00
|
|
|
|
2010-02-01 16:18:49 +00:00
|
|
|
$reqcopy->{'useNmapfromMN'}->[0]=$usenmapfrommn;
|
|
|
|
$reqcopy->{'allapps'}=$all_apps;
|
|
|
|
|
|
|
|
my %porthash=(); #('sshd,ll'=> {
|
|
|
|
# port=>'22,5001',
|
|
|
|
# node=>[node1,node2]
|
|
|
|
# }
|
|
|
|
#)
|
|
|
|
my %cmdhash=(); #('gpfs,myapp'=> {
|
|
|
|
# cmd=>'/tmp/mycmd1,/usr/bin/date',
|
|
|
|
# node=>[node1,node2]
|
|
|
|
# }
|
|
|
|
#)
|
|
|
|
my %dcmdhash=(); #('myapp2,myapp3'=> {
|
|
|
|
# dcmd=>'/tmp/mycmd1,/usr/bin/date',
|
|
|
|
# node=>[node1,node2]
|
|
|
|
# }
|
|
|
|
#)
|
|
|
|
my @nodes_for_sn=@{$sn->{$snkey}};
|
2010-10-29 18:18:03 +00:00
|
|
|
|
2010-02-01 16:18:49 +00:00
|
|
|
foreach my $node (@nodes_for_sn) {
|
|
|
|
my @ports;
|
|
|
|
my @portapps;
|
|
|
|
my @cmds;
|
|
|
|
my @cmdapps;
|
|
|
|
my @dcmds;
|
|
|
|
my @dcmdapps;
|
2010-10-29 18:18:03 +00:00
|
|
|
my @lcmdapps;
|
|
|
|
my @lcmds;
|
2010-02-01 16:18:49 +00:00
|
|
|
foreach my $app (keys %apps) {
|
|
|
|
if ($app eq 'APPS') { next; }
|
|
|
|
my $group=$apps{$app}->{'group'};
|
|
|
|
if (($group eq "ALL") || ($groups{$group}->{$node})) {
|
|
|
|
#print "app=$app\n";
|
|
|
|
if (exists($apps{$app}->{'port'})) {
|
|
|
|
push @ports, $apps{$app}->{'port'};
|
|
|
|
push @portapps, $app;
|
|
|
|
}
|
|
|
|
elsif (exists($apps{$app}->{'cmd'})) {
|
|
|
|
push @cmds, $apps{$app}->{'cmd'};
|
|
|
|
push @cmdapps, $app;
|
|
|
|
}
|
|
|
|
elsif (exists($apps{$app}->{'dcmd'})) {
|
|
|
|
push @dcmds, $apps{$app}->{'dcmd'};
|
|
|
|
push @dcmdapps, $app;
|
|
|
|
}
|
2010-10-29 18:18:03 +00:00
|
|
|
elsif (exists($apps{$app}->{'lcmd'})) {
|
|
|
|
push @lcmds, $apps{$app}->{'lcmd'};
|
|
|
|
push @lcmdapps, $app;
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#print "ports=@ports\n";
|
|
|
|
#print "portapps=@portapps\n";
|
|
|
|
#print "cmds=@cmds\n";
|
|
|
|
#print "cmdapps=@cmdapps\n";
|
|
|
|
#print "dcmds=@dcmds\n";
|
|
|
|
#print "dcmdapps=@dcmdapps\n";
|
|
|
|
if (@portapps>0) {
|
|
|
|
my $tmpapps=join(',', @portapps);
|
2010-10-29 18:18:03 +00:00
|
|
|
if (($usenmapfrommn==1) && (@cmdapps==0) && (@dcmdapps==0) && (@lcmdapps==0)) {
|
2010-02-01 16:18:49 +00:00
|
|
|
#this is the case where mn handles ports for all nodes using nmap
|
|
|
|
#The current limitation is that when there are cmd or dcmd specified for the node
|
|
|
|
# nmap has to be done on the service node because if both mn and sn update the appstatus
|
|
|
|
# one will overwites the other.
|
|
|
|
if (exists($all_porthash{$tmpapps})) {
|
|
|
|
my $pa=$all_porthash{$tmpapps}->{'node'};
|
|
|
|
push @$pa, $node;
|
|
|
|
} else {
|
|
|
|
$all_porthash{$tmpapps}->{'node'}=[$node];
|
|
|
|
$all_porthash{$tmpapps}->{'port'}=join(',', @ports);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (exists($porthash{$tmpapps})) {
|
|
|
|
my $pa=$porthash{$tmpapps}->{'node'};
|
|
|
|
push @$pa, $node;
|
|
|
|
} else {
|
|
|
|
$porthash{$tmpapps}->{'node'}=[$node];
|
|
|
|
$porthash{$tmpapps}->{'port'}=join(',', @ports);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (@cmdapps>0) {
|
|
|
|
my $tmpapps=join(',', @cmdapps);
|
|
|
|
if (exists($cmdhash{$tmpapps})) {
|
|
|
|
my $pa=$cmdhash{$tmpapps}->{'node'};
|
|
|
|
push @$pa, $node;
|
|
|
|
} else {
|
|
|
|
$cmdhash{$tmpapps}->{'node'}=[$node];
|
|
|
|
$cmdhash{$tmpapps}->{'cmd'}=join(',', @cmds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (@dcmdapps>0) {
|
|
|
|
my $tmpapps=join(',', @dcmdapps);
|
|
|
|
if (exists($dcmdhash{$tmpapps})) {
|
|
|
|
my $pa=$dcmdhash{$tmpapps}->{'node'};
|
|
|
|
push @$pa, $node;
|
|
|
|
} else {
|
|
|
|
$dcmdhash{$tmpapps}->{'node'}=[$node];
|
|
|
|
$dcmdhash{$tmpapps}->{'dcmd'}=join(',', @dcmds);
|
|
|
|
}
|
|
|
|
}
|
2010-10-29 18:18:03 +00:00
|
|
|
if (@lcmdapps>0) {
|
|
|
|
my $i=0;
|
|
|
|
foreach my $lapp (@lcmdapps) {
|
|
|
|
if (exists($lcmdhash{$lapp})) {
|
|
|
|
my $pa=$lcmdhash{$lapp}->{'node'};
|
|
|
|
push @$pa, $node;
|
|
|
|
} else {
|
|
|
|
$lcmdhash{$lapp}->{'node'}=[$node];
|
|
|
|
$lcmdhash{$lapp}->{'lcmd'}=$lcmds[$i];
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
} #end foreach (@nodes_for_sn)
|
|
|
|
|
|
|
|
#print Dumper(%porthash);
|
2010-10-29 18:18:03 +00:00
|
|
|
#print "cmdhash=" . Dumper(%cmdhash);
|
2010-02-01 16:18:49 +00:00
|
|
|
#now push the settings into the requests
|
|
|
|
my $i=1;
|
2010-10-29 18:18:03 +00:00
|
|
|
if ((keys(%porthash) == 0) && (keys(%cmdhash) == 0) && (keys(%dcmdhash) == 0) && (keys(%lcmdhash) == 0)) { next; }
|
2010-02-01 16:18:49 +00:00
|
|
|
foreach my $tmpapps (keys %porthash) {
|
|
|
|
$reqcopy->{'portapps'}->[0]= scalar keys %porthash;
|
|
|
|
$reqcopy->{"portapps$i"}->[0]= $tmpapps;
|
|
|
|
$reqcopy->{"portapps$i" . "port"}->[0]= $porthash{$tmpapps}->{'port'};
|
|
|
|
$reqcopy->{"portapps$i" . "node"} = $porthash{$tmpapps}->{'node'};;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$i=1;
|
|
|
|
foreach my $tmpapps (keys %cmdhash) {
|
|
|
|
$reqcopy->{'cmdapps'}->[0]= scalar keys %cmdhash;
|
|
|
|
$reqcopy->{"cmdapps$i"}->[0]= $tmpapps;
|
|
|
|
$reqcopy->{"cmdapps$i" . "cmd"}->[0]= $cmdhash{$tmpapps}->{'cmd'};
|
|
|
|
$reqcopy->{"cmdapps$i" . "node"} = $cmdhash{$tmpapps}->{'node'};;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$i=1;
|
|
|
|
foreach my $tmpapps (keys %dcmdhash) {
|
|
|
|
$reqcopy->{'dcmdapps'}->[0]= scalar keys %dcmdhash;
|
|
|
|
$reqcopy->{"dcmdapps$i"}->[0]= $tmpapps;
|
|
|
|
$reqcopy->{"dcmdapps$i" . "dcmd"}->[0]= $dcmdhash{$tmpapps}->{'dcmd'};
|
|
|
|
$reqcopy->{"dcmdapps$i" . "node"} = $dcmdhash{$tmpapps}->{'node'};
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#done
|
|
|
|
push @requests, $reqcopy;
|
2010-10-29 18:18:03 +00:00
|
|
|
} #enf sn_key
|
|
|
|
|
|
|
|
|
|
|
|
#print "apps=" . Dumper(%apps);
|
2010-02-01 16:18:49 +00:00
|
|
|
|
|
|
|
#mn handles all nmap when useNmapfromMN=1 on the site table
|
|
|
|
if (($usenmapfrommn == 1) && (keys(%all_porthash) > 0)) {
|
2012-08-09 04:07:40 +00:00
|
|
|
my @hostinfo=xCAT::NetworkUtils->determinehostname();
|
2010-02-01 16:18:49 +00:00
|
|
|
my %iphash=();
|
|
|
|
foreach(@hostinfo) {$iphash{$_}=1;}
|
|
|
|
my $handled=0;
|
|
|
|
foreach my $req (@requests) {
|
|
|
|
my $currsn=$req->{'_xcatdest'};
|
|
|
|
if (exists($iphash{$currsn})) {
|
|
|
|
my $i=1;
|
|
|
|
foreach my $tmpapps (keys %all_porthash) {
|
|
|
|
$req->{'portapps'}->[0]= scalar keys %all_porthash;
|
|
|
|
$req->{"portapps$i"}->[0]= $tmpapps;
|
|
|
|
$req->{"portapps$i" . "port"}->[0]= $all_porthash{$tmpapps}->{'port'};
|
|
|
|
$req->{"portapps$i" . "node"} = $all_porthash{$tmpapps}->{'node'};;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$handled=1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$handled) {
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
|
|
$reqcopy->{'useNmapfromMN'}->[0]=$usenmapfrommn;
|
|
|
|
$reqcopy->{'allapps'}=$all_apps;
|
|
|
|
my $i=1;
|
|
|
|
foreach my $tmpapps (keys %all_porthash) {
|
|
|
|
$reqcopy->{'portapps'}->[0]= scalar keys %all_porthash;
|
|
|
|
$reqcopy->{"portapps$i"}->[0]= $tmpapps;
|
|
|
|
$reqcopy->{"portapps$i" . "port"}->[0]= $all_porthash{$tmpapps}->{'port'};
|
|
|
|
$reqcopy->{"portapps$i" . "node"} = $all_porthash{$tmpapps}->{'node'};;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
push @requests, $reqcopy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if ($usenmapfrommn) {
|
|
|
|
# my $reqcopy = {%$req};
|
|
|
|
# $reqcopy->{'update'}->[0]=$::UPDATE;
|
|
|
|
# $reqcopy->{'useNmapfromMN'}->[0]=1;
|
|
|
|
# if (!$::UPDATE) {
|
|
|
|
# push @requests, $reqcopy;
|
|
|
|
# return \@requests; #do not distribute, nodestat seems to lose accuracy and slow down distributed, if using nmap
|
|
|
|
# }
|
|
|
|
#}
|
2010-10-29 18:18:03 +00:00
|
|
|
|
|
|
|
#now handle local commands
|
|
|
|
#print "lcmdhash=" . Dumper(%lcmdhash);
|
|
|
|
if (keys(%lcmdhash) > 0) {
|
2012-08-09 04:07:40 +00:00
|
|
|
my @hostinfo=xCAT::NetworkUtils->determinehostname();
|
2010-10-29 18:18:03 +00:00
|
|
|
my %iphash=();
|
|
|
|
foreach(@hostinfo) {$iphash{$_}=1;}
|
|
|
|
my $handled=0;
|
|
|
|
foreach my $req (@requests) {
|
|
|
|
my $currsn=$req->{'_xcatdest'};
|
|
|
|
if (exists($iphash{$currsn})) {
|
|
|
|
my $i=1;
|
|
|
|
foreach my $lapp (keys %lcmdhash) {
|
|
|
|
$req->{'lcmdapps'}->[0]= scalar keys %lcmdhash;
|
|
|
|
$req->{"lcmdapps$i"}->[0]= $lapp;
|
|
|
|
$req->{"lcmdapps$i" . "cmd"}->[0]= $lcmdhash{$lapp}->{'lcmd'};
|
|
|
|
$req->{"lcmdapps$i" . "node"} = $lcmdhash{$lapp}->{'node'};;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$handled=1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$handled) {
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
|
|
$reqcopy->{'allapps'}=$all_apps;
|
|
|
|
my $i=1;
|
|
|
|
foreach my $lapp (keys %lcmdhash) {
|
|
|
|
$reqcopy->{'lcmdapps'}->[0]= scalar keys %lcmdhash;
|
|
|
|
$reqcopy->{"lcmdapps$i"}->[0]= $lapp;
|
|
|
|
$reqcopy->{"lcmdapps$i" . "cmd"}->[0]= $lcmdhash{$lapp}->{'lcmd'};
|
|
|
|
$reqcopy->{"lcmdapps$i" . "node"} = $lcmdhash{$lapp}->{'node'};;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
push @requests, $reqcopy;
|
|
|
|
}
|
|
|
|
}
|
2008-04-15 14:37:26 +00:00
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
|
2008-04-15 14:37:26 +00:00
|
|
|
return \@requests;
|
2009-02-21 14:25:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 21:35:48 +00:00
|
|
|
sub interrogate_node { #Meant to run against confirmed up nodes
|
|
|
|
my $node=shift;
|
|
|
|
my $doreq=shift;
|
2010-02-01 16:18:49 +00:00
|
|
|
my $p_tmp=shift;
|
|
|
|
my %portservices = %$p_tmp;
|
|
|
|
|
2009-04-06 21:35:48 +00:00
|
|
|
my $status = "";
|
2010-02-01 16:18:49 +00:00
|
|
|
my $appsd=""; #detailed status
|
|
|
|
my $ret={};
|
2010-02-02 16:31:05 +00:00
|
|
|
$ret->{'status'}="ping";
|
2010-02-01 16:18:49 +00:00
|
|
|
|
|
|
|
foreach my $port (keys(%portservices)) {
|
|
|
|
if (nodesockopen($node,$port)) {
|
|
|
|
$status.=$portservices{$port} . ",";
|
|
|
|
$appsd.=$portservices{$port} . "=up,";
|
|
|
|
} else {
|
|
|
|
$appsd.=$portservices{$port} . "=down,";
|
|
|
|
}
|
2009-04-06 21:35:48 +00:00
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
|
2009-04-06 21:35:48 +00:00
|
|
|
$status =~ s/,$//;
|
2010-02-01 16:18:49 +00:00
|
|
|
$appsd =~ s/,$//;
|
|
|
|
$ret->{'appsd'}=$appsd;
|
2009-04-06 21:35:48 +00:00
|
|
|
if ($status) {
|
2010-02-01 16:18:49 +00:00
|
|
|
$ret->{'appstatus'}=$status;
|
|
|
|
return $ret;
|
2009-04-06 21:35:48 +00:00
|
|
|
}
|
|
|
|
if ($status = installer_query($node)) {
|
2010-02-01 16:18:49 +00:00
|
|
|
$ret->{'status'}=$status;
|
|
|
|
return $ret;
|
2009-04-06 21:35:48 +00:00
|
|
|
} else { #pingable, but no *clue* as to what the state may be
|
|
|
|
$doreq->({command=>['nodeset'],
|
|
|
|
node=>[$node],
|
|
|
|
arg=>['stat']},
|
|
|
|
\&getstat);
|
2010-02-01 16:18:49 +00:00
|
|
|
$ret->{'status'} = 'ping '.$nodesetstats{$node};
|
|
|
|
return $ret;
|
2009-04-06 21:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process_request_nmap {
|
2008-02-25 22:00:46 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
2008-02-26 14:25:58 +00:00
|
|
|
my $doreq = shift;
|
2010-02-01 16:18:49 +00:00
|
|
|
my $nodelist=shift;
|
|
|
|
my $p_tmp=shift;
|
|
|
|
my %portservices = %$p_tmp;
|
|
|
|
my @nodes =();
|
|
|
|
if ($nodelist) { @nodes=@$nodelist;}
|
|
|
|
|
2010-01-15 19:31:26 +00:00
|
|
|
my %nodebyip;
|
2009-04-04 01:00:38 +00:00
|
|
|
my @livenodes;
|
2009-02-21 14:25:06 +00:00
|
|
|
my %unknownnodes;
|
2011-05-23 18:32:29 +00:00
|
|
|
my $chaintab = xCAT::Table->new('chain',-create=>0);
|
|
|
|
if ($chaintab) {
|
|
|
|
%chainhash = %{$chaintab->getNodesAttribs(\@nodes,['currstate'])};
|
|
|
|
}
|
2012-06-25 19:41:33 +00:00
|
|
|
my $hoststab = xCAT::Table->new('hosts',-create=>0);
|
|
|
|
my %hostsents;
|
|
|
|
if ($hoststab) { %hostsents = %{$hoststab->getNodesAttribs(\@nodes,['ip'])}; }
|
|
|
|
my @ips;
|
|
|
|
my @ip6s;
|
2009-02-21 14:25:06 +00:00
|
|
|
foreach (@nodes) {
|
|
|
|
$unknownnodes{$_}=1;
|
2010-05-10 09:04:59 +00:00
|
|
|
my $ip = undef;
|
2012-06-25 19:41:33 +00:00
|
|
|
if ($hostsents{$_}) {
|
|
|
|
$ip = $hostsents{$_}->[0]->{ip};
|
|
|
|
$nodebyip{$ip} = $_;
|
|
|
|
$ip = xCAT::NetworkUtils->getipaddr($ip);
|
|
|
|
$nodebyip{$ip} = $_;
|
|
|
|
} else {
|
|
|
|
$ip = xCAT::NetworkUtils->getipaddr($_);
|
|
|
|
}
|
|
|
|
if( !defined $ip) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{name}=[$_];
|
|
|
|
$rsp{data} = [ "Please make sure $_ exists in /etc/hosts or DNS or hosts table" ];
|
|
|
|
$callback->({node=>[\%rsp]});
|
|
|
|
} else {
|
|
|
|
if ($ip =~ /:/) {
|
|
|
|
push @ip6s,$ip;
|
|
|
|
} else {
|
|
|
|
push @ips,$ip;
|
|
|
|
}
|
|
|
|
$nodebyip{$ip} = $_;
|
|
|
|
}
|
2009-02-21 14:25:06 +00:00
|
|
|
}
|
2009-04-01 06:52:40 +00:00
|
|
|
|
2010-02-01 16:18:49 +00:00
|
|
|
my $ret={};
|
2008-02-25 22:00:46 +00:00
|
|
|
my $node;
|
2009-02-21 14:25:06 +00:00
|
|
|
my $fping;
|
2009-04-04 01:00:38 +00:00
|
|
|
my $ports = join ',',keys %portservices;
|
|
|
|
my %deadnodes;
|
|
|
|
foreach (@nodes) {
|
|
|
|
$deadnodes{$_}=1;
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
#print "nmap -PE --send-ip -p $ports,3001 ".join(' ',@nodes) . "\n";
|
2011-09-12 17:37:27 +00:00
|
|
|
# open($fping,"nmap -PE --send-ip -p $ports,3001 ".join(' ',@nodes). " 2> /dev/null|") or die("Can't start nmap: $!");
|
2009-04-04 01:00:38 +00:00
|
|
|
my $currnode='';
|
|
|
|
my $port;
|
|
|
|
my $state;
|
|
|
|
my %states;
|
|
|
|
my %rsp;
|
2009-04-07 15:09:13 +00:00
|
|
|
my $installquerypossible=0;
|
2009-04-07 15:47:42 +00:00
|
|
|
my @nodesetnodes=();
|
2012-06-25 19:41:33 +00:00
|
|
|
foreach my $ip6 (0,1) { #first pass, ipv4, second pass ipv6
|
|
|
|
if ($ip6 and scalar(@ip6s)) {
|
2012-10-08 21:08:03 +00:00
|
|
|
open($fping,"nmap -6 -PS$ports,3001 -n --send-ip -p $ports,3001 ".join(' ',@ip6s). " 2> /dev/null|") or die("Can't start nmap: $!");
|
2012-08-10 16:23:23 +00:00
|
|
|
} elsif (not $ip6 and scalar(@ips)) {
|
2012-08-08 20:56:47 +00:00
|
|
|
open($fping,"nmap -PE -n --send-ip -p $ports,3001 ".join(' ',@ips). " 2> /dev/null|") or die("Can't start nmap: $!");
|
2012-06-25 19:41:33 +00:00
|
|
|
} else { next; }
|
2009-02-21 14:25:06 +00:00
|
|
|
while (<$fping>) {
|
2012-06-25 19:41:33 +00:00
|
|
|
if (/Interesting ports on ([^ ]*)[: ]/ or /Nmap scan report for ([^ ]*)/) {
|
2010-09-23 18:15:48 +00:00
|
|
|
my $tmpnode=$1;
|
2010-09-23 18:34:17 +00:00
|
|
|
if ($currnode) { #if still thinking about last node, flush him out
|
2010-09-23 18:15:48 +00:00
|
|
|
my $status = join ',',sort keys %states ;
|
|
|
|
my $appsd="";
|
|
|
|
foreach my $portnum(keys %portservices) {
|
|
|
|
my $app_t=$portservices{$portnum};
|
|
|
|
if ($states{$app_t}) {$appsd .= $app_t . "=up,";}
|
|
|
|
else {$appsd .= $app_t . "=down,";}
|
|
|
|
}
|
|
|
|
$appsd =~ s/,$//;
|
2012-06-27 13:35:55 +00:00
|
|
|
my $target=$currnode;
|
|
|
|
if ($hostsents{$target} and $target = $hostsents{$target}->[0]->{ip}) { $target = $hostsents{$target}->[0]->{ip}; }
|
2010-09-23 18:15:48 +00:00
|
|
|
|
2012-06-27 13:35:55 +00:00
|
|
|
if ($status or ($installquerypossible and $status = installer_query($target))) { #pingable, but no *clue* as to what the state may be
|
2010-09-23 18:34:17 +00:00
|
|
|
$ret->{$currnode}->{'status'}="ping";
|
|
|
|
$ret->{$currnode}->{'appstatus'}=$status;
|
|
|
|
$ret->{$currnode}->{'appsd'}=$appsd;
|
|
|
|
$currnode="";
|
|
|
|
%states=();
|
|
|
|
} else {
|
2010-09-23 18:15:48 +00:00
|
|
|
push @nodesetnodes,$currnode; #Aggregate call to nodeset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$currnode=$tmpnode;
|
2012-06-25 19:41:33 +00:00
|
|
|
$currnode =~ s/:$//;
|
|
|
|
|
2010-10-12 20:44:45 +00:00
|
|
|
|
2010-01-15 19:31:26 +00:00
|
|
|
my $nip;
|
2010-05-10 09:04:59 +00:00
|
|
|
if ($nip = xCAT::NetworkUtils->getipaddr($currnode)) { #reverse lookup may not resemble the nodename, key by ip
|
2010-01-15 19:31:26 +00:00
|
|
|
if ($nodebyip{$nip}) {
|
|
|
|
$currnode = $nodebyip{$nip};
|
|
|
|
}
|
|
|
|
}
|
2009-04-07 15:09:13 +00:00
|
|
|
$installquerypossible=0; #reset possibility indicator
|
2009-04-07 15:47:42 +00:00
|
|
|
%rsp=();
|
2009-04-04 01:00:38 +00:00
|
|
|
unless ($deadnodes{$1}) {
|
2009-07-09 18:26:56 +00:00
|
|
|
my $shortname;
|
2009-04-04 01:00:38 +00:00
|
|
|
foreach (keys %deadnodes) {
|
2009-07-09 18:26:56 +00:00
|
|
|
if (/\./) {
|
|
|
|
$shortname = $_;
|
|
|
|
$shortname =~ s/\..*//;
|
|
|
|
}
|
|
|
|
if ($currnode =~ /^$_\./ or ($shortname and $shortname eq $currnode)) {
|
2009-04-04 01:00:38 +00:00
|
|
|
$currnode = $_;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete $deadnodes{$currnode};
|
|
|
|
} elsif ($currnode) {
|
2010-08-10 18:57:30 +00:00
|
|
|
#if (/^MAC/) { #oops not all nmap records end with MAC
|
2009-04-04 01:00:38 +00:00
|
|
|
if (/^PORT/) { next; }
|
|
|
|
($port,$state) = split;
|
2010-10-29 18:18:03 +00:00
|
|
|
if ($port and $port =~ /^(\d*)\// and $state eq 'open') {
|
2011-05-23 18:32:29 +00:00
|
|
|
if ($1 eq "3001" and $chainhash{$currnode}->[0]->{currstate} =~ /^install/) {
|
2009-04-07 15:09:13 +00:00
|
|
|
$installquerypossible=1; #It is possible to actually query node
|
2011-05-23 18:32:29 +00:00
|
|
|
} elsif ($1 ne "3001") {
|
2009-04-07 15:09:13 +00:00
|
|
|
$states{$portservices{$1}}=1;
|
|
|
|
}
|
2009-04-04 01:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-12 20:44:45 +00:00
|
|
|
}
|
2012-06-25 19:41:33 +00:00
|
|
|
}
|
2010-09-23 18:34:17 +00:00
|
|
|
|
2010-10-12 20:44:45 +00:00
|
|
|
if ($currnode) {
|
|
|
|
my $status = join ',',sort keys %states ;
|
|
|
|
my $appsd="";
|
|
|
|
foreach my $portnum(keys %portservices) {
|
|
|
|
my $app_t=$portservices{$portnum};
|
|
|
|
if ($states{$app_t}) {$appsd .= $app_t . "=up,";}
|
|
|
|
else {$appsd .= $app_t . "=down,";}
|
|
|
|
}
|
|
|
|
$appsd =~ s/,$//;
|
|
|
|
|
2012-06-27 13:35:55 +00:00
|
|
|
my $target=$currnode;
|
|
|
|
if ($hostsents{$target} and $hostsents{$target}->[0]->{ip}) { $target = $hostsents{$target}->[0]->{ip}; }
|
|
|
|
if ($status or ($installquerypossible and $status = installer_query($target))) { #pingable, but no *clue* as to what the state may be
|
2010-10-12 20:44:45 +00:00
|
|
|
$ret->{$currnode}->{'status'}="ping";
|
|
|
|
$ret->{$currnode}->{'appstatus'}=$status;
|
|
|
|
$ret->{$currnode}->{'appsd'}=$appsd;
|
|
|
|
$currnode="";
|
|
|
|
%states=();
|
|
|
|
} else {
|
|
|
|
push @nodesetnodes,$currnode; #Aggregate call to nodeset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 15:47:42 +00:00
|
|
|
if (@nodesetnodes) {
|
|
|
|
$doreq->({command=>['nodeset'],
|
|
|
|
node=>\@nodesetnodes,
|
|
|
|
arg=>['stat']},
|
|
|
|
\&getstat);
|
|
|
|
foreach (@nodesetnodes) {
|
2010-02-01 16:18:49 +00:00
|
|
|
$ret->{$_}->{'status'}=$nodesetstats{$_};
|
2009-04-07 15:47:42 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-04 01:00:38 +00:00
|
|
|
foreach $currnode (sort keys %deadnodes) {
|
2010-02-01 16:18:49 +00:00
|
|
|
$ret->{$currnode}->{'status'}="noping";
|
2009-04-04 01:00:38 +00:00
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
|
|
|
|
return $ret;
|
2008-02-25 22:00:46 +00:00
|
|
|
}
|
2009-04-06 21:35:48 +00:00
|
|
|
|
2010-02-01 16:18:49 +00:00
|
|
|
|
|
|
|
sub process_request_port {
|
2009-04-06 21:35:48 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
2010-02-01 16:18:49 +00:00
|
|
|
my $nodelist=shift;
|
|
|
|
my $p_tmp=shift;
|
|
|
|
my %portservices = %$p_tmp;
|
|
|
|
my @nodes = ();
|
|
|
|
if ($nodelist) { @nodes=@$nodelist;}
|
2009-04-06 21:35:48 +00:00
|
|
|
|
|
|
|
my %unknownnodes;
|
|
|
|
foreach (@nodes) {
|
|
|
|
$unknownnodes{$_}=1;
|
|
|
|
my $packed_ip = undef;
|
2010-05-10 09:04:59 +00:00
|
|
|
$packed_ip = xCAT::NetworkUtils->getipaddr($_);
|
2009-04-06 21:35:48 +00:00
|
|
|
if( !defined $packed_ip) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{name}=[$_];
|
|
|
|
$rsp{data} = [ "Please make sure $_ exists in /etc/hosts" ];
|
|
|
|
$callback->({node=>[\%rsp]});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-01 16:18:49 +00:00
|
|
|
my $status={};
|
|
|
|
|
|
|
|
if (@nodes>0) {
|
|
|
|
my $node;
|
|
|
|
my $fping;
|
|
|
|
open($fping,"fping ".join(' ',@nodes). " 2> /dev/null|") or die("Can't start fping: $!");
|
|
|
|
while (<$fping>) {
|
|
|
|
my %rsp;
|
|
|
|
my $node=$_;
|
|
|
|
$node =~ s/ .*//;
|
|
|
|
chomp $node;
|
|
|
|
if (/ is alive/) {
|
|
|
|
$status->{$node} = interrogate_node($node,$doreq, $p_tmp);
|
|
|
|
} elsif (/is unreachable/) {
|
|
|
|
$status->{$node}->{'status'}="noping";
|
|
|
|
} elsif (/ address not found/) {
|
|
|
|
$status->{$node}->{'status'}="nosuchhost";
|
|
|
|
}
|
2009-04-06 21:35:48 +00:00
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub process_request_local_command {
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my $nodelist=shift;
|
|
|
|
my $p_tmp=shift;
|
|
|
|
my %cmdhash = %$p_tmp;
|
|
|
|
|
|
|
|
my @nodes = ();
|
|
|
|
if ($nodelist) { @nodes=@$nodelist;}
|
|
|
|
|
|
|
|
my $status={};
|
|
|
|
|
|
|
|
if (@nodes>0) {
|
|
|
|
foreach my $tmp_cmds (keys %cmdhash) {
|
|
|
|
my @cmds=split(',', $tmp_cmds);
|
|
|
|
my @apps=split(',', $cmdhash{$tmp_cmds});
|
|
|
|
my $index=0;
|
|
|
|
foreach my $cmd (@cmds) {
|
|
|
|
my $nodes_string=join(',', @nodes);
|
|
|
|
my $ret=`$cmd $nodes_string`;
|
2010-10-29 18:18:03 +00:00
|
|
|
#print "ret=$ret\n";
|
2010-02-01 16:18:49 +00:00
|
|
|
if (($? ==0) && ($ret)) {
|
|
|
|
my @ret_array=split('\n', $ret);
|
|
|
|
foreach(@ret_array) {
|
|
|
|
my @a=split(':', $_);
|
|
|
|
chomp($a[1]);
|
|
|
|
if (exists($status->{$a[0]})) {
|
|
|
|
$status->{$a[0]} .= "," . $apps[$index] . "=" . $a[1];
|
|
|
|
} else {
|
|
|
|
$status->{$a[0]} = $apps[$index] . "=" . $a[1];;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub process_request_remote_command {
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my $nodelist=shift;
|
|
|
|
my $p_tmp=shift;
|
|
|
|
my %cmdhash = %$p_tmp;
|
|
|
|
my @nodes = ();
|
|
|
|
if ($nodelist) { @nodes=@$nodelist;}
|
|
|
|
|
|
|
|
my $status={};
|
|
|
|
|
|
|
|
if (@nodes>0) {
|
|
|
|
foreach my $tmp_cmds (keys %cmdhash) {
|
|
|
|
my @cmds=split(',', $tmp_cmds);
|
|
|
|
my @apps=split(',', $cmdhash{$tmp_cmds});
|
|
|
|
my $index=0;
|
|
|
|
foreach my $cmd (@cmds) {
|
|
|
|
my $nodes_string=join(',', @nodes);
|
|
|
|
#print "XCATBYPASS=Y xdsh $nodes_string $cmd\n";
|
|
|
|
my $ret=`XCATBYPASS=Y xdsh $nodes_string $cmd`;
|
|
|
|
if ($ret) {
|
|
|
|
my @ret_array=split('\n', $ret);
|
|
|
|
foreach(@ret_array) {
|
|
|
|
my @a=split(':', $_, 2);
|
|
|
|
chomp($a[1]); #remove newline
|
|
|
|
$a[1] =~ s/^\s+//; #remove leading white spaces
|
|
|
|
$a[1] =~ s/\s+$//; #remove tailing white spaces
|
|
|
|
|
|
|
|
if (exists($status->{$a[0]})) {
|
|
|
|
$status->{$a[0]} .= "," . $apps[$index] . "=" . $a[1];
|
|
|
|
} else {
|
|
|
|
$status->{$a[0]} = $apps[$index] . "=" . $a[1];;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process_request {
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
%nodesetstats=();
|
2010-03-16 20:29:56 +00:00
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my $separator="XXXXXYYYYYZZZZZ";
|
2011-06-29 12:03:28 +00:00
|
|
|
my $usefping;
|
2011-07-12 12:57:32 +00:00
|
|
|
if (ref $request->{arg}) {
|
|
|
|
@ARGV=@{$request->{arg}};
|
|
|
|
GetOptions(
|
|
|
|
'f' => \$usefping
|
|
|
|
);
|
|
|
|
}
|
2011-06-29 12:03:28 +00:00
|
|
|
|
2010-03-16 20:29:56 +00:00
|
|
|
|
|
|
|
if ($command eq "nodestat_internal") {
|
2010-10-12 20:44:45 +00:00
|
|
|
|
2010-03-16 20:29:56 +00:00
|
|
|
#if ( -x '/usr/bin/nmap' ) {
|
|
|
|
# my %portservices = (
|
|
|
|
# '22' => 'sshd',
|
|
|
|
# '15002' => 'pbs',
|
|
|
|
# '8002' => 'xend',
|
|
|
|
# );
|
|
|
|
#
|
|
|
|
# return process_request_nmap($request, $callback, $doreq, $request->{node}, \%portservices);
|
|
|
|
# }
|
|
|
|
|
|
|
|
#handle ports and nodelist.status
|
|
|
|
my $status={};
|
|
|
|
if (exists($request->{'portapps'})) {
|
|
|
|
for (my $i=1; $i<=$request->{'portapps'}->[0]; $i++) {
|
|
|
|
my %portservices=();
|
|
|
|
my @apps=split(',', $request->{"portapps$i"}->[0]);
|
|
|
|
my @ports=split(',', $request->{"portapps$i" . "port"}->[0]);
|
|
|
|
my $nodes=$request->{"portapps$i" . "node"};
|
|
|
|
for (my $j=0; $j <@ports; $j++) {
|
|
|
|
$portservices{$ports[$j]}=$apps[$j];
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ret={};
|
2011-06-29 12:03:28 +00:00
|
|
|
if ( not $usefping and -x '/usr/bin/nmap' ) {
|
2010-03-16 20:29:56 +00:00
|
|
|
$ret=process_request_nmap($request, $callback, $doreq, $nodes, \%portservices);
|
|
|
|
} else {
|
|
|
|
$ret=process_request_port($request, $callback, $doreq, $nodes, \%portservices);
|
|
|
|
}
|
|
|
|
%$status=(%$status, %$ret);
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2010-03-16 20:29:56 +00:00
|
|
|
|
2010-10-29 18:18:03 +00:00
|
|
|
|
2010-03-16 20:29:56 +00:00
|
|
|
#handle local commands
|
|
|
|
if (exists($request->{'cmdapps'})) {
|
|
|
|
for (my $i=1; $i<=$request->{'cmdapps'}->[0]; $i++) {
|
|
|
|
my %cmdhash=();
|
|
|
|
my @apps=split(',', $request->{"cmdapps$i"}->[0]);
|
|
|
|
my @cmds=split(',', $request->{"cmdapps$i" . "cmd"}->[0]);
|
|
|
|
my $nodes=$request->{"cmdapps$i" . "node"};
|
|
|
|
for (my $j=0; $j <@cmds; $j++) {
|
|
|
|
$cmdhash{$cmds[$j]}=$apps[$j];
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ret = process_request_local_command($request, $callback, $doreq, $nodes, \%cmdhash);
|
2010-10-29 18:18:03 +00:00
|
|
|
#print Dumper($ret);
|
|
|
|
|
|
|
|
foreach my $node1 (keys(%$ret)) {
|
|
|
|
if (exists($status->{$node1})) {
|
|
|
|
my $appstatus=$status->{$node1}->{'appstatus'};
|
|
|
|
if ($appstatus) { $status->{$node1}->{'appstatus'} .= "," . $ret->{$node1}; }
|
|
|
|
else { $status->{$node1}->{'appstatus'} = $ret->{$node1}; }
|
|
|
|
my $appsd=$status->{$node1}->{'appsd'};
|
|
|
|
if ($appsd) { $status->{$node1}->{'appsd'} .= "," . $ret->{$node1}; }
|
|
|
|
else { $status->{$node1}->{'appsd'} = $ret->{$node1}; }
|
|
|
|
} else {
|
|
|
|
$status->{$node1}->{'appstatus'} = $ret->{$node1};
|
|
|
|
$status->{$node1}->{'appsd'} = $ret->{$node1};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#handle local l commands
|
|
|
|
if (exists($request->{'lcmdapps'})) {
|
|
|
|
for (my $i=1; $i<=$request->{'lcmdapps'}->[0]; $i++) {
|
|
|
|
my %cmdhash=();
|
|
|
|
my @apps=split(',', $request->{"lcmdapps$i"}->[0]);
|
|
|
|
my @cmds=split(',', $request->{"lcmdapps$i" . "cmd"}->[0]);
|
|
|
|
my $nodes=$request->{"lcmdapps$i" . "node"};
|
|
|
|
for (my $j=0; $j <@cmds; $j++) {
|
|
|
|
$cmdhash{$cmds[$j]}=$apps[$j];
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ret = process_request_local_command($request, $callback, $doreq, $nodes, \%cmdhash);
|
|
|
|
|
2010-03-16 20:29:56 +00:00
|
|
|
foreach my $node1 (keys(%$ret)) {
|
|
|
|
if (exists($status->{$node1})) {
|
|
|
|
my $appstatus=$status->{$node1}->{'appstatus'};
|
|
|
|
if ($appstatus) { $status->{$node1}->{'appstatus'} .= "," . $ret->{$node1}; }
|
|
|
|
else { $status->{$node1}->{'appstatus'} = $ret->{$node1}; }
|
|
|
|
my $appsd=$status->{$node1}->{'appsd'};
|
|
|
|
if ($appsd) { $status->{$node1}->{'appsd'} .= "," . $ret->{$node1}; }
|
|
|
|
else { $status->{$node1}->{'appsd'} = $ret->{$node1}; }
|
|
|
|
} else {
|
|
|
|
$status->{$node1}->{'appstatus'} = $ret->{$node1};
|
|
|
|
$status->{$node1}->{'appsd'} = $ret->{$node1};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2010-03-16 20:29:56 +00:00
|
|
|
|
2010-10-29 18:18:03 +00:00
|
|
|
|
2010-03-16 20:29:56 +00:00
|
|
|
#handle remote commands
|
|
|
|
if (exists($request->{'dcmdapps'})) {
|
|
|
|
for (my $i=1; $i<=$request->{'dcmdapps'}->[0]; $i++) {
|
|
|
|
my %dcmdhash=();
|
|
|
|
my @apps=split(',', $request->{"dcmdapps$i"}->[0]);
|
|
|
|
my @dcmds=split(',', $request->{"dcmdapps$i" . "dcmd"}->[0]);
|
|
|
|
my $nodes=$request->{"dcmdapps$i" . "node"};
|
|
|
|
for (my $j=0; $j <@dcmds; $j++) {
|
|
|
|
$dcmdhash{$dcmds[$j]}=$apps[$j];
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ret = process_request_remote_command($request, $callback, $doreq, $nodes, \%dcmdhash);
|
|
|
|
foreach my $node1 (keys(%$ret)) {
|
|
|
|
if (exists($status->{$node1})) {
|
|
|
|
my $appstatus=$status->{$node1}->{'appstatus'};
|
|
|
|
if ($appstatus) { $status->{$node1}->{'appstatus'} .= "," . $ret->{$node1}; }
|
|
|
|
else { $status->{$node1}->{'appstatus'} = $ret->{$node1}; }
|
|
|
|
my $appsd=$status->{$node1}->{'appsd'};
|
|
|
|
if ($appsd) { $status->{$node1}->{'appsd'} .= "," . $ret->{$node1}; }
|
|
|
|
else { $status->{$node1}->{'appsd'} = $ret->{$node1}; }
|
|
|
|
} else {
|
|
|
|
$status->{$node1}->{'appstatus'} = $ret->{$node1};
|
|
|
|
$status->{$node1}->{'appsd'} = $ret->{$node1};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2010-10-29 18:18:03 +00:00
|
|
|
|
|
|
|
|
2010-03-16 20:29:56 +00:00
|
|
|
#nodestat_internal command the output, nodestat command will collect it
|
2010-02-01 16:18:49 +00:00
|
|
|
foreach my $node1 (sort keys(%$status)) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{name}=[$node1];
|
|
|
|
my $st=$status->{$node1}->{'status'};
|
|
|
|
my $ast= $status->{$node1}->{'appstatus'};
|
2010-03-16 20:29:56 +00:00
|
|
|
my $appsd = $status->{$node1}->{'appsd'};
|
2010-10-29 18:18:03 +00:00
|
|
|
$st=$st?$st:'';
|
|
|
|
$ast=$ast?$ast:'';
|
|
|
|
$appsd=$appsd?$appsd:'';
|
2010-03-16 20:29:56 +00:00
|
|
|
|
|
|
|
$rsp{data}->[0] = "$st$separator$ast$separator$appsd";
|
2010-02-01 16:18:49 +00:00
|
|
|
$callback->({node=>[\%rsp]});
|
|
|
|
}
|
2010-03-16 20:29:56 +00:00
|
|
|
} else { #nodestat command
|
|
|
|
#first collect the status from the nodes
|
|
|
|
my $reqcopy = {%$request};
|
|
|
|
$reqcopy->{command}->[0]='nodestat_internal';
|
|
|
|
my $ret = xCAT::Utils->runxcmd($reqcopy, $doreq, 0, 1);
|
|
|
|
|
|
|
|
#print Dumper($ret);
|
|
|
|
my $status={};
|
|
|
|
my @noping_nodes=();
|
2010-03-19 14:57:57 +00:00
|
|
|
my $power=$request->{'power'}->[0];
|
2010-03-16 20:29:56 +00:00
|
|
|
foreach my $tmpdata (@$ret) {
|
|
|
|
if ($tmpdata =~ /([^:]+): (.*)$separator(.*)$separator(.*)/) {
|
2010-10-12 20:44:45 +00:00
|
|
|
#print "node=$1, status=$2, appstatus=$3, appsd=$4\n";
|
2010-10-29 18:18:03 +00:00
|
|
|
if ($status->{$1}->{'status'}) {
|
|
|
|
$status->{$1}->{'status'}=$status->{$1}->{'status'} . ",$2";
|
|
|
|
} else {
|
|
|
|
$status->{$1}->{'status'}=$2;
|
|
|
|
}
|
|
|
|
if ($status->{$1}->{'appstatus'}) {
|
|
|
|
$status->{$1}->{'appstatus'}= $status->{$1}->{'appstatus'} . ",$3";
|
|
|
|
} else {
|
|
|
|
$status->{$1}->{'appstatus'}=$3;
|
|
|
|
}
|
|
|
|
if ($status->{$1}->{'appsd'}) {
|
|
|
|
$status->{$1}->{'appsd'}=$status->{$1}->{'appsd'} . ",$4";
|
|
|
|
} else {
|
|
|
|
$status->{$1}->{'appsd'}=$4;
|
|
|
|
}
|
2010-03-19 14:57:57 +00:00
|
|
|
if (($power) && ($2 eq "noping")) {
|
2010-03-16 20:29:56 +00:00
|
|
|
push(@noping_nodes, $1);
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2010-03-16 20:29:56 +00:00
|
|
|
} else {
|
|
|
|
my $rsp;
|
2010-03-16 20:33:32 +00:00
|
|
|
$rsp->{data}->[0]= "$tmpdata";
|
2010-03-16 20:29:56 +00:00
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
}
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
|
2010-10-29 18:18:03 +00:00
|
|
|
#print Dumper($status);
|
2010-03-19 14:57:57 +00:00
|
|
|
#get power status for noping nodes
|
|
|
|
if (($power) && (@noping_nodes > 0)) {
|
2010-03-16 20:29:56 +00:00
|
|
|
#print "noping_nodes=@noping_nodes\n";
|
|
|
|
my $ret = xCAT::Utils->runxcmd(
|
|
|
|
{
|
|
|
|
command => ['rpower'],
|
|
|
|
node => \@noping_nodes,
|
|
|
|
arg => [ 'stat' ]
|
|
|
|
},
|
|
|
|
$doreq, 0, 1 );
|
|
|
|
|
|
|
|
foreach my $tmpdata (@$ret) {
|
|
|
|
if ($tmpdata =~ /([^:]+): (.*)/) {
|
2010-03-16 20:42:12 +00:00
|
|
|
$status->{$1}->{'status'}="noping($2)";
|
2010-03-16 20:29:56 +00:00
|
|
|
} else {
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0]= "$tmpdata";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#print Dumper($request);
|
|
|
|
my $update=$request->{'update'}->[0];
|
|
|
|
my $quite=$request->{'quite'}->[0];
|
|
|
|
|
|
|
|
|
|
|
|
#show the output
|
|
|
|
if (!$quite) {
|
|
|
|
foreach my $node1 (sort keys(%$status)) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{name}=[$node1];
|
|
|
|
my $st=$status->{$node1}->{'status'};
|
|
|
|
my $ast= $status->{$node1}->{'appstatus'};
|
|
|
|
if ($st) {
|
|
|
|
if ($st eq 'ping') { $st = $ast ? "$ast" : "$st"; }
|
|
|
|
else { $st = $ast ? "$st,$ast" : "$st"; }
|
|
|
|
} else {
|
|
|
|
$st=$ast;
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2010-03-16 20:29:56 +00:00
|
|
|
$rsp{data}->[0] = $st;
|
|
|
|
$callback->({node=>[\%rsp]});
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
2010-03-16 20:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#update the nodelist table
|
|
|
|
if ($update) {
|
|
|
|
my $nodetab=xCAT::Table->new('nodelist', -create=>1);
|
|
|
|
if ($nodetab) {
|
|
|
|
my $status1={};
|
|
|
|
#get current values and compare with the new value to decide if update of db is necessary
|
|
|
|
my @nodes1=keys(%$status);
|
|
|
|
my $stuff = $nodetab->getNodesAttribs(\@nodes1, ['node', 'status', 'appstatus']);
|
|
|
|
|
|
|
|
#get current local time
|
|
|
|
my (
|
|
|
|
$sec, $min, $hour, $mday, $mon,
|
|
|
|
$year, $wday, $yday, $isdst
|
|
|
|
)
|
|
|
|
= localtime(time);
|
|
|
|
my $currtime = sprintf("%02d-%02d-%04d %02d:%02d:%02d",
|
|
|
|
$mon + 1, $mday, $year + 1900,
|
|
|
|
$hour, $min, $sec);
|
|
|
|
|
|
|
|
foreach my $node1 (@nodes1) {
|
|
|
|
my $oldstatus=$stuff->{$node1}->[0]->{status};
|
|
|
|
my $newstatus=$status->{$node1}->{status};
|
|
|
|
if ($newstatus) {
|
|
|
|
if ((!$oldstatus) || ($newstatus ne $oldstatus)) {
|
|
|
|
$status1->{$node1}->{status}= $newstatus;
|
|
|
|
$status1->{$node1}->{statustime}= $currtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($oldstatus) {
|
|
|
|
$status1->{$node1}->{status}= "";
|
|
|
|
$status1->{$node1}->{statustime}= "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $oldappstatus=$stuff->{$node1}->[0]->{'appstatus'};
|
|
|
|
my $newappstatus=$status->{$node1}->{'appsd'};
|
2011-03-11 07:04:37 +00:00
|
|
|
while ($newappstatus =~ /(\w+)\=(\w+)/) {
|
|
|
|
my $tmp1=$1;
|
|
|
|
my $tmp2=$2;
|
2012-02-08 18:37:48 +00:00
|
|
|
if ($oldappstatus) {
|
|
|
|
if($oldappstatus =~ /$tmp1\=/){
|
|
|
|
$oldappstatus =~ s/$tmp1\=\w+/$tmp1\=$tmp2/g;
|
|
|
|
}else{
|
|
|
|
$oldappstatus = $oldappstatus."\,$tmp1\=$tmp2";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$oldappstatus = "$tmp1\=$tmp2";
|
|
|
|
}
|
|
|
|
$newappstatus =~ s/(\w+)\=(\w+)//;
|
2011-03-11 07:04:37 +00:00
|
|
|
}
|
|
|
|
$status1->{$node1}->{appstatus}= $oldappstatus;
|
|
|
|
$status1->{$node1}->{appstatustime}= $currtime;
|
2010-03-16 20:29:56 +00:00
|
|
|
}
|
|
|
|
#print Dumper($status1);
|
|
|
|
$nodetab->setNodesAttribs($status1);
|
|
|
|
}
|
2010-02-01 16:18:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-06 21:35:48 +00:00
|
|
|
}
|
2009-04-07 15:47:42 +00:00
|
|
|
|
2008-10-31 19:12:14 +00:00
|
|
|
sub usage
|
|
|
|
{
|
|
|
|
my $cb=shift;
|
|
|
|
my $rsp={};
|
|
|
|
$rsp->{data}->[0]= "Usage:";
|
2010-03-19 14:57:57 +00:00
|
|
|
$rsp->{data}->[1]= " nodestat [noderange] [-m|--usemon] [-p|powerstat] [-u|--updatedb]";
|
2008-10-31 19:12:14 +00:00
|
|
|
$rsp->{data}->[2]= " nodestat [-h|--help|-v|--version]";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $cb);
|
|
|
|
}
|
2008-02-25 22:00:46 +00:00
|
|
|
|
2010-02-01 16:18:49 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
=head3 getStatusMonsettings
|
|
|
|
This function goes to the monsetting table to retrieve the settings related to
|
|
|
|
the node status and app status monitoring.
|
|
|
|
Arguments:
|
|
|
|
none.
|
|
|
|
Returns:
|
|
|
|
a hash that has settings from the monsetting table for node status and
|
|
|
|
app status monitoring. For example:
|
|
|
|
( 'APPS'=>[ll,gpfs],
|
|
|
|
'll' =>
|
|
|
|
{
|
|
|
|
'group' => 'service,compute',
|
|
|
|
'port' => '5001'
|
|
|
|
},
|
|
|
|
'gpfs' =>
|
|
|
|
{
|
|
|
|
'group' => 'service',
|
|
|
|
'cmd' => '/tmp/gpfscmd'
|
|
|
|
};
|
|
|
|
)
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
sub getStatusMonsettings {
|
|
|
|
my %apps=();
|
|
|
|
my $tab=xCAT::Table->new('monsetting');
|
|
|
|
if ( defined($tab)) {
|
|
|
|
my ($ent) = $tab->getAttribs({name => 'xcatmon', key => 'apps' }, 'value');
|
|
|
|
if ( defined($ent) ) {
|
|
|
|
my $tmp_list=$ent->{value};
|
|
|
|
if ($tmp_list) {
|
|
|
|
my @applist=split(',', $tmp_list);
|
|
|
|
foreach my $app (@applist) {
|
|
|
|
$apps{$app}={};
|
|
|
|
}
|
|
|
|
$apps{'APPS'}=\@applist;
|
|
|
|
my @results = $tab->getAttribs({name => 'xcatmon'}, 'key','value');
|
|
|
|
if (@results) {
|
|
|
|
foreach(@results) {
|
|
|
|
my $key=$_->{key};
|
|
|
|
my $value=$_->{value};
|
|
|
|
if (exists($apps{$key})) {
|
|
|
|
my @tem_value=split(',',$value);
|
|
|
|
foreach my $pair (@tem_value) {
|
|
|
|
my @tmp_action=split('=', $pair);
|
|
|
|
if (exists($apps{$key}->{$tmp_action[0]})) {
|
|
|
|
$apps{$key}->{$tmp_action[0]} = $apps{$key}->{$tmp_action[0]} . "," . $tmp_action[1];
|
|
|
|
} else {
|
|
|
|
$apps{$key}->{$tmp_action[0]}=$tmp_action[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return %apps;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
=head3 getNodeStatusAndAppstatus
|
|
|
|
This function goes to the xCAT nodelist table to retrieve the saved node status and appstatus
|
|
|
|
for all the node that are managed by local nodes.
|
|
|
|
Arguments:
|
|
|
|
nodelist--- an array of nodes
|
|
|
|
Returns:
|
|
|
|
a hash pointer that has the node status and appstatus. The format is:
|
|
|
|
{ node1=> {
|
|
|
|
status=>'active',appstatus=>'sshd=up,ll=up,gpfs=down'
|
|
|
|
} ,
|
|
|
|
node2=> {
|
|
|
|
status=>'active',appstatus=>'sshd=up,ll=down,gpfs=down'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
sub getMonNodesStatusAndAppStatus {
|
|
|
|
my @nodes=@_;
|
|
|
|
|
|
|
|
my %status=();
|
|
|
|
my $table=xCAT::Table->new("nodelist", -create =>1);
|
|
|
|
my $tabdata=$table->getNodesAttribs(\@nodes,['node', 'status', 'appstatus']);
|
|
|
|
foreach my $node (@nodes) {
|
|
|
|
my $tmp1=$tabdata->{$node}->[0];
|
|
|
|
if ($tmp1) {
|
|
|
|
$status{$node}->{status}=$tmp1->{status};
|
|
|
|
$status{$node}->{appstatus}=$tmp1->{appstatus};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return %status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-25 22:00:46 +00:00
|
|
|
1;
|