2007-11-29 19:55:16 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2007-12-11 19:14:43 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use xCAT::GlobalDef;
|
2007-11-29 19:55:16 +00:00
|
|
|
use xCAT::Table;
|
2012-09-12 15:05:57 +00:00
|
|
|
use xCAT::NetworkUtils;
|
2008-02-16 04:51:42 +00:00
|
|
|
use xCAT_monitoring::xcatmon;
|
2007-11-29 19:55:16 +00:00
|
|
|
#################################################################
|
|
|
|
# This script is used as a cron job by the xCAT monitoring plug-in
|
2007-11-29 20:01:00 +00:00
|
|
|
# to monitor the node status. To activate it, simply do
|
|
|
|
# chtab pname=xCAT monitoring.nodestatmon=Y
|
2007-11-29 19:55:16 +00:00
|
|
|
##################################################################
|
|
|
|
|
2007-12-11 19:56:37 +00:00
|
|
|
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
|
|
|
#printf "%2d-%02d-%04d %02d:%02d:%02d: xcatnodemon started.\n", $mon+1,$mday,$year+1900,$hour,$min,$sec;
|
2007-11-29 19:55:16 +00:00
|
|
|
|
|
|
|
#get saved node status from the nodelist table
|
2008-02-16 04:51:42 +00:00
|
|
|
my %nodes_status_old=xCAT_monitoring::xcatmon::getMonNodesStatus();
|
2007-11-29 19:55:16 +00:00
|
|
|
|
|
|
|
#get a list of nodes
|
|
|
|
my $tmp_node_active=$nodes_status_old{$::STATUS_ACTIVE};
|
|
|
|
my $tmp_node_inactive=$nodes_status_old{$::STATUS_INACTIVE};
|
|
|
|
my $tmp_node_unknown=$nodes_status_old{unknown};
|
2007-12-11 19:44:58 +00:00
|
|
|
#print "active nodes: @$tmp_node_active\n";
|
|
|
|
#print "inactive nodes: @$tmp_node_inactive\n";
|
|
|
|
#print "unknown nodes: @$tmp_node_unknown\n";
|
2007-11-29 19:55:16 +00:00
|
|
|
|
|
|
|
#get current node status
|
|
|
|
my %nodes_status_new1=();
|
2012-09-12 15:05:57 +00:00
|
|
|
if ($tmp_node_active) { %nodes_status_new1=xCAT::NetworkUtils->pingNodeStatus(@$tmp_node_active);}
|
2007-11-29 19:55:16 +00:00
|
|
|
my %nodes_status_new2=();
|
2012-09-12 15:05:57 +00:00
|
|
|
if ($tmp_node_inactive) {%nodes_status_new2=xCAT::NetworkUtils->pingNodeStatus(@$tmp_node_inactive);}
|
2007-11-29 19:55:16 +00:00
|
|
|
my %nodes_status_new3=();
|
2012-09-12 15:05:57 +00:00
|
|
|
if ($tmp_node_unknown) { %nodes_status_new3=xCAT::NetworkUtils->pingNodeStatus(@$tmp_node_unknown);}
|
2007-11-29 19:55:16 +00:00
|
|
|
|
|
|
|
my $changed1=$nodes_status_new1{$::STATUS_INACTIVE};
|
|
|
|
my $changed2=$nodes_status_new2{$::STATUS_ACTIVE};
|
|
|
|
my $changed3=$nodes_status_new3{$::STATUS_INACTIVE};
|
|
|
|
my $changed4=$nodes_status_new3{$::STATUS_ACTIVE};
|
|
|
|
my @changed_active=(@$changed2, @$changed4);
|
|
|
|
my @changed_inactive=(@$changed1, @$changed3);
|
|
|
|
|
2007-12-11 19:56:37 +00:00
|
|
|
#print " switch to active: @changed_active\n";
|
|
|
|
#print " switch to inactive: @changed_inactive\n";
|
2007-11-29 19:55:16 +00:00
|
|
|
|
|
|
|
my %node_status=();
|
|
|
|
if (@changed_active>0) {
|
|
|
|
$node_status{$::STATUS_ACTIVE}=\@changed_active;
|
|
|
|
}
|
|
|
|
if (@changed_inactive>0) {
|
|
|
|
$node_status{$::STATUS_INACTIVE}=\@changed_inactive;
|
|
|
|
}
|
|
|
|
|
|
|
|
#only set the node status for the changed ones
|
|
|
|
if (keys(%node_status) > 0) {
|
2008-09-29 14:53:58 +00:00
|
|
|
#the second parameter means ignore checking. This is because the check is
|
|
|
|
#done getMonNodesStatus() call
|
|
|
|
xCAT_monitoring::xcatmon::setNodeStatusAttributes(\%node_status, 1);
|
2007-11-29 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 19:56:37 +00:00
|
|
|
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
|
|
|
#printf "%2d-%02d-%04d %02d:%02d:%02d: xcatnodemon finished.\n\n", $mon+1,$mday,$year+1900,$hour,$min,$sec;
|
2007-11-29 19:55:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|