2007-11-29 19:34:38 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::monctrlcmds;
|
2007-12-11 19:14:43 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
2008-03-05 20:43:37 +00:00
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
2007-12-11 19:14:43 +00:00
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
|
2007-11-29 19:34:38 +00:00
|
|
|
use xCAT::NodeRange;
|
|
|
|
use xCAT::Table;
|
|
|
|
use xCAT::MsgUtils;
|
2007-12-11 19:14:43 +00:00
|
|
|
use xCAT_monitoring::monitorctrl;
|
2008-03-13 02:13:29 +00:00
|
|
|
use xCAT::Utils;
|
2007-11-29 19:34:38 +00:00
|
|
|
|
2008-04-18 20:33:19 +00:00
|
|
|
my $callback;
|
2007-11-29 19:34:38 +00:00
|
|
|
1;
|
|
|
|
|
2008-04-18 20:33:19 +00:00
|
|
|
|
|
|
|
|
2007-11-29 19:34:38 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
=head1 xCAT_plugin:monctrlcmds
|
|
|
|
=head2 Package Description
|
|
|
|
xCAT monitoring control commands plugini module. This modules handles
|
|
|
|
monitoring related commands.
|
|
|
|
=cut
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
=head3 handled_commands
|
|
|
|
It returns a list of commands handled by this plugin.
|
|
|
|
Arguments:
|
|
|
|
none
|
|
|
|
Returns:
|
|
|
|
a list of commands.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
sub handled_commands {
|
|
|
|
return {
|
2008-03-21 20:32:41 +00:00
|
|
|
monstart => "monctrlcmds",
|
|
|
|
monstop => "monctrlcmds",
|
|
|
|
monupdate => "monctrlcmds",
|
|
|
|
monls => "monctrlcmds",
|
|
|
|
monaddnode => "monctrlcmds",
|
|
|
|
monrmnode => "monctrlcmds",
|
2007-11-29 19:34:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
=head3 process_request
|
|
|
|
It processes the monitoring control commands.
|
|
|
|
Arguments:
|
|
|
|
request -- a hash table which contains the command name.
|
|
|
|
callback -- a callback pointer to return the response to.
|
|
|
|
args -- a list of arguments that come with the command.
|
|
|
|
Returns:
|
|
|
|
0 for success. The output is returned through the callback pointer.
|
|
|
|
1. for unsuccess. The error messages are returns through the callback pointer.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
sub process_request {
|
|
|
|
use Getopt::Long;
|
|
|
|
# options can be bundled up like -vV
|
|
|
|
Getopt::Long::Configure("bundling") ;
|
|
|
|
$Getopt::Long::ignorecase=0;
|
|
|
|
|
|
|
|
my $request = shift;
|
2008-04-18 20:33:19 +00:00
|
|
|
$callback = shift;
|
2007-11-29 19:34:38 +00:00
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my $args=$request->{arg};
|
2008-04-18 20:33:19 +00:00
|
|
|
my $doreq = shift;
|
2007-11-29 19:34:38 +00:00
|
|
|
|
2008-03-21 20:32:41 +00:00
|
|
|
if ($command eq "monstart") {
|
2008-04-18 20:33:19 +00:00
|
|
|
my ($ret, $msg) = monstart($args, $callback, $doreq);
|
2007-11-29 19:34:38 +00:00
|
|
|
if ($msg) {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{dara}->[0]= $msg;
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
2008-03-21 20:32:41 +00:00
|
|
|
elsif ($command eq "monstop") {
|
2008-04-18 20:33:19 +00:00
|
|
|
my ($ret, $msg) = monstop($args, $callback, $doreq);
|
2007-11-29 19:34:38 +00:00
|
|
|
if ($msg) {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{data}->[0]= $msg;
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
2008-03-21 20:32:41 +00:00
|
|
|
elsif ($command eq "monupdate") {
|
2007-11-29 19:34:38 +00:00
|
|
|
xCAT_monitoring::monitorctrl::sendMonSignal();
|
|
|
|
}
|
2008-03-21 20:32:41 +00:00
|
|
|
elsif ($command eq "monls") {
|
|
|
|
my ($ret, $msg) = monls($args, $callback);
|
|
|
|
if ($msg) {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{data}->[0]= $msg;
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
elsif ($command eq "monaddnode") {
|
|
|
|
my ($ret, $msg) = monaddnode($args, $callback);
|
|
|
|
if ($msg) {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{data}->[0]= $msg;
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
elsif ($command eq "monrmnode") {
|
|
|
|
my ($ret, $msg) = monrmnode($args, $callback);
|
2008-03-05 20:43:37 +00:00
|
|
|
if ($msg) {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{data}->[0]= $msg;
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
2007-11-29 19:34:38 +00:00
|
|
|
else {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{data}->[0]= "unsupported command: $command.";
|
|
|
|
$callback->($rsp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-18 20:33:19 +00:00
|
|
|
sub take_answer {
|
|
|
|
my $resp = shift;
|
|
|
|
$callback->($resp);
|
|
|
|
}
|
|
|
|
|
2007-11-29 19:34:38 +00:00
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
2008-03-21 20:32:41 +00:00
|
|
|
=head3 monstart
|
2008-01-18 18:14:45 +00:00
|
|
|
This function registers the given monitoring plug-in to the 'monitoring' table.
|
|
|
|
xCAT will invoke the monitoring plug-in to start the 3rd party software, which
|
|
|
|
this plug-in connects to, to monitor the xCAT cluster.
|
2007-11-29 19:34:38 +00:00
|
|
|
Arguments:
|
|
|
|
callback - the pointer to the callback function.
|
|
|
|
args - The format of the args is:
|
|
|
|
[-h|--help|-v|--version] or
|
2008-03-05 20:43:37 +00:00
|
|
|
name [-n|--nodestatmon] [-s|--settings ...]
|
2007-11-29 19:34:38 +00:00
|
|
|
where
|
2008-01-18 18:14:45 +00:00
|
|
|
name is the monitoring plug-in name. For example: rmcmon.
|
|
|
|
The specified plug-in will be registered and invoked
|
|
|
|
for monitoring the xCAT cluster.
|
|
|
|
-n|--nodestatmon indicates that this plug-in will be used for feeding the node liveness
|
|
|
|
status to the xCAT nodelist table. If not specified, the plug-in will not be used
|
|
|
|
for feeding node status to xCAT.
|
2008-03-05 20:43:37 +00:00
|
|
|
-s|--settings settings are used by the plug-in to customize it behavor.
|
2007-11-29 19:34:38 +00:00
|
|
|
Returns:
|
|
|
|
0 for success. The output is returned through the callback pointer.
|
|
|
|
1. for unsuccess. The error messages are returns through the callback pointer.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
2008-03-21 20:32:41 +00:00
|
|
|
sub monstart {
|
2007-11-29 19:34:38 +00:00
|
|
|
my $args=shift;
|
|
|
|
my $callback=shift;
|
2008-04-18 20:33:19 +00:00
|
|
|
my $doreq = shift;
|
2007-11-29 19:34:38 +00:00
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
|
|
|
|
2008-03-13 02:13:29 +00:00
|
|
|
if (xCAT::Utils->isServiceNode()) {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{data}->[0]= "This command is not supported on a service node.";
|
|
|
|
$callback->($rsp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-29 19:34:38 +00:00
|
|
|
# subroutine to display the usage
|
2008-03-21 20:32:41 +00:00
|
|
|
sub monstart_usage
|
2007-11-29 19:34:38 +00:00
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]= "Usage:";
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[1]= " monstart name [-n|--nodestatmon] [-s|--settings settings]";
|
|
|
|
$rsp->{data}->[2]= " monstart [-h|--help|-v|--version]";
|
2008-03-05 20:43:37 +00:00
|
|
|
$rsp->{data}->[3]= " name is the name of the monitoring plug-in module to be registered and invoked.";
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[4]= " Use 'monls -a' command to list all the monitoring plug-in names.";
|
2008-03-05 20:43:37 +00:00
|
|
|
$rsp->{data}->[5]= " settings is used by the monitoring plug-in to customize its behavior.";
|
|
|
|
$rsp->{data}->[6]= " Format: [key1=value1],[key2=value2]... ";
|
|
|
|
$rsp->{data}->[7]= " Please note that the square brackets are needed. ";
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[7]= " Use 'monls name -d' command to look for the possible settings for a plug-in.";
|
|
|
|
$rsp->{data}->[8]= " Example: monstart xcatmon -n -s [ping-interval=10]";
|
2007-11-29 19:34:38 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ARGV=@{$args};
|
2008-02-23 01:01:49 +00:00
|
|
|
my $settings;
|
2007-11-29 19:34:38 +00:00
|
|
|
|
|
|
|
# parse the options
|
|
|
|
if(!GetOptions(
|
|
|
|
'h|help' => \$::HELP,
|
2008-01-18 18:14:45 +00:00
|
|
|
'v|version' => \$::VERSION,
|
2008-02-23 01:01:49 +00:00
|
|
|
'n|nodestatmon' => \$::NODESTATMON,
|
|
|
|
's|settings=s' => \$settings))
|
2007-11-29 19:34:38 +00:00
|
|
|
{
|
2008-03-21 20:32:41 +00:00
|
|
|
&monstart_usage;
|
2007-11-29 19:34:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the usage if -h or --help is specified
|
|
|
|
if ($::HELP) {
|
2008-03-21 20:32:41 +00:00
|
|
|
&monstart_usage;
|
2007-11-29 19:34:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the version statement if -v or --verison is specified
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my %rsp;
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[0]= "monstart version 1.0";
|
2007-11-29 19:34:38 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-18 18:14:45 +00:00
|
|
|
#my @product_names;
|
|
|
|
my $pname;
|
2007-11-29 19:34:38 +00:00
|
|
|
if (@ARGV < 1)
|
|
|
|
{
|
2008-03-21 20:32:41 +00:00
|
|
|
&monstart_usage;
|
2007-11-29 19:34:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2008-01-18 18:14:45 +00:00
|
|
|
#@product_names=split(/,/, $ARGV[0]);
|
|
|
|
$pname=$ARGV[0];
|
|
|
|
$file_name="$::XCATROOT/lib/perl/xCAT_monitoring/$pname.pm";
|
|
|
|
if (!-e $file_name) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]="File $file_name does not exist.";
|
|
|
|
$callback->($rsp);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
#load the module in memory
|
|
|
|
eval {require($file_name)};
|
|
|
|
if ($@) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]="The file $file_name has compiling errors:\n$@\n";
|
|
|
|
$callback->($rsp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2007-11-29 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-21 20:32:41 +00:00
|
|
|
#my %ret = xCAT_monitoring::monitorctrl::startmonitoring(@product_names);
|
2007-11-29 19:34:38 +00:00
|
|
|
|
2008-01-18 18:14:45 +00:00
|
|
|
#my %rsp;
|
|
|
|
#$rsp->{data}->[0]= "starting @product_names";
|
|
|
|
#my $i=1;
|
|
|
|
#foreach (keys %ret) {
|
|
|
|
# my $ret_array=$ret{$_};
|
|
|
|
# $rsp->{data}->[$i++]= "$_: $ret_array->[1]";
|
|
|
|
#}
|
|
|
|
|
|
|
|
#my $nodestatmon=xCAT_monitoring::monitorctrl::nodeStatMonName();
|
|
|
|
#if ($nodestatmon) {
|
|
|
|
# foreach (@product_names) {
|
|
|
|
# if ($_ eq $nodestatmon) {
|
|
|
|
# my ($code, $msg)=xCAT_monitoring::monitorctrl::startNodeStatusMonitoring($nodestatmon);
|
|
|
|
# $rsp->{data}->[$i++]="node status monitoring with $nodestatmon: $msg";
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
#}
|
|
|
|
|
|
|
|
my $table=xCAT::Table->new("monitoring", -create => 1,-autocommit => 1);
|
|
|
|
if ($table) {
|
|
|
|
(my $ref) = $table->getAttribs({name => $pname}, name);
|
|
|
|
if ($ref and $ref->{name}) {
|
|
|
|
my %rsp;
|
2008-03-05 20:43:37 +00:00
|
|
|
$rsp->{data}->[0]="$pname has already been activated for monitoring.";
|
2008-01-18 18:14:45 +00:00
|
|
|
$callback->($rsp);
|
2007-11-29 19:34:38 +00:00
|
|
|
}
|
2008-01-18 18:14:45 +00:00
|
|
|
else {
|
2008-03-05 20:43:37 +00:00
|
|
|
#update the monsetting table
|
2008-03-14 17:18:42 +00:00
|
|
|
if ($settings) {
|
2008-03-05 20:43:37 +00:00
|
|
|
my $table1=xCAT::Table->new("monsetting", -create => 1,-autocommit => 1);
|
|
|
|
my %key_col1 = (name=>$pname);
|
|
|
|
#parse the settings. Setting format: key="value",key="value"....
|
2008-03-14 17:18:42 +00:00
|
|
|
while ($settings =~ s/^\[([^\[\]\=]*)=([^\[\]]*)\](,)*//) {
|
2008-03-05 20:43:37 +00:00
|
|
|
$key_col1{key}=$1;
|
|
|
|
$setting_hash{value}=$2;
|
|
|
|
$table1->setAttribs(\%key_col1, \%setting_hash);
|
|
|
|
}
|
|
|
|
$table1->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
#update the monitoring table
|
2008-01-18 18:14:45 +00:00
|
|
|
my %key_col = (name=>$pname);
|
|
|
|
my $nstat='N';
|
|
|
|
if ($::NODESTATMON) {
|
|
|
|
$nstat='Y';
|
|
|
|
}
|
2008-03-04 21:45:26 +00:00
|
|
|
my %tb_cols=(nodestatmon=>$nstat, disable=>"0");
|
2008-01-18 18:14:45 +00:00
|
|
|
$table->setAttribs(\%key_col, \%tb_cols);
|
2008-02-23 01:01:49 +00:00
|
|
|
}
|
|
|
|
$table->close();
|
2007-11-29 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-13 02:13:29 +00:00
|
|
|
#tell the service node to start monitoring too
|
|
|
|
my $mon_hierachy=xCAT_monitoring::monitorctrl->getMonHierarchy();
|
|
|
|
my @mon_servers=keys(%$mon_hierachy);
|
|
|
|
my @hostinfo=xCAT::Utils->determinehostname();
|
2008-03-20 15:54:51 +00:00
|
|
|
#print "hostinfo=@hostinfo\n";
|
2008-03-13 02:13:29 +00:00
|
|
|
%iphash=();
|
|
|
|
foreach(@hostinfo) {$iphash{$_}=1;}
|
|
|
|
foreach (@mon_servers) {
|
2008-03-14 17:18:42 +00:00
|
|
|
if (! $iphash{$_} && ($_ ne "noservicenode")) { #if it is not this node, meaning it is ms
|
2008-03-13 02:13:29 +00:00
|
|
|
my %rsp2;
|
|
|
|
$rsp2->{data}->[0]="sending request to $_...";
|
|
|
|
$callback->($rsp2);
|
2008-04-18 20:33:19 +00:00
|
|
|
# my $result=`psh --nonodecheck $_ monupdate 2>1&`;
|
|
|
|
# if ($result) {
|
|
|
|
# $rsp2->{data}->[0]="$result";
|
|
|
|
# $callback->($rsp2);
|
|
|
|
# }
|
|
|
|
my %req=();
|
|
|
|
push @{$req{command}}, "monupdate";
|
|
|
|
$req{'_xcatdest'}=$_;
|
|
|
|
$doreq->(\%req,\&take_answer);
|
2008-03-13 02:13:29 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-05 20:43:37 +00:00
|
|
|
|
2008-01-18 18:14:45 +00:00
|
|
|
my %rsp1;
|
|
|
|
$rsp1->{data}->[0]="done.";
|
|
|
|
$callback->($rsp1);
|
|
|
|
|
2007-11-29 19:34:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
2008-03-21 20:32:41 +00:00
|
|
|
=head3 monstop
|
2008-01-18 18:14:45 +00:00
|
|
|
This function unregisters the given monitoring plug-in from the 'monitoring' table.
|
|
|
|
xCAT will ask the monitoring plug-in to stop the 3rd party software, which
|
|
|
|
this plug-in connects to, to monitor the xCAT cluster.
|
2007-11-29 19:34:38 +00:00
|
|
|
Arguments:
|
|
|
|
callback - the pointer to the callback function.
|
|
|
|
args - The format of the args is:
|
|
|
|
[-h|--help|-v|--version] or
|
2008-01-18 18:14:45 +00:00
|
|
|
name
|
2007-11-29 19:34:38 +00:00
|
|
|
where
|
2008-01-18 18:14:45 +00:00
|
|
|
name is the monitoring plug-in name. For example: rmcmon.
|
|
|
|
The specified plug-in will be un-registered and stoped
|
|
|
|
for monitoring the xCAT cluster.
|
2007-11-29 19:34:38 +00:00
|
|
|
Returns:
|
|
|
|
0 for success. The output is returned through the callback pointer.
|
|
|
|
1. for unsuccess. The error messages are returns through the callback pointer.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
2008-03-21 20:32:41 +00:00
|
|
|
sub monstop {
|
2007-11-29 19:34:38 +00:00
|
|
|
my $args=shift;
|
|
|
|
my $callback=shift;
|
2008-04-18 20:33:19 +00:00
|
|
|
my $doreq = shift;
|
2007-11-29 19:34:38 +00:00
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
|
|
|
|
2008-03-13 02:13:29 +00:00
|
|
|
if (xCAT::Utils->isServiceNode()) {
|
|
|
|
my %rsp=();
|
|
|
|
$rsp->{data}->[0]= "This command is not supported on a service node.";
|
|
|
|
$callback->($rsp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-29 19:34:38 +00:00
|
|
|
# subroutine to display the usage
|
2008-03-21 20:32:41 +00:00
|
|
|
sub monstop_usage
|
2007-11-29 19:34:38 +00:00
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]= "Usage:";
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[1]= " monstop name";
|
|
|
|
$rsp->{data}->[2]= " monstop [-h|--help|-v|--version]";
|
2008-03-05 20:43:37 +00:00
|
|
|
$rsp->{data}->[3]= " name is the name of the monitoring plug-in module registered in the monitoring table.";
|
2007-11-29 19:34:38 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ARGV=@{$args};
|
|
|
|
# parse the options
|
|
|
|
if(!GetOptions(
|
|
|
|
'h|help' => \$::HELP,
|
|
|
|
'v|version' => \$::VERSION,))
|
|
|
|
{
|
2008-03-21 20:32:41 +00:00
|
|
|
&monstop_usage;
|
2007-11-29 19:34:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the usage if -h or --help is specified
|
|
|
|
if ($::HELP) {
|
2008-03-21 20:32:41 +00:00
|
|
|
&monstop_usage;
|
2007-11-29 19:34:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the version statement if -v or --verison is specified
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my %rsp;
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[0]= "monstop version 1.0";
|
2007-11-29 19:34:38 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-18 18:14:45 +00:00
|
|
|
#my @product_names;
|
|
|
|
my $pname;
|
2007-11-29 19:34:38 +00:00
|
|
|
if (@ARGV < 1)
|
|
|
|
{
|
2008-03-21 20:32:41 +00:00
|
|
|
&monstop_usage;
|
2007-11-29 19:34:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2008-01-18 18:14:45 +00:00
|
|
|
#@product_names=split(/,/, $ARGV[0]);
|
|
|
|
$pname=$ARGV[0];
|
2007-11-29 19:34:38 +00:00
|
|
|
}
|
|
|
|
|
2008-01-18 18:14:45 +00:00
|
|
|
#my %ret = xCAT_monitoring::monitorctrl::stopMonitoring(@product_names);
|
|
|
|
#my %rsp;
|
|
|
|
#$rsp->{data}->[0]= "stopping @product_names";
|
|
|
|
#my $i=1;
|
|
|
|
#foreach (keys %ret) {
|
|
|
|
# my $ret_array=$ret{$_};
|
|
|
|
# $rsp->{data}->[$i++]= "$_: $ret_array->[1]";
|
|
|
|
#}
|
|
|
|
|
|
|
|
#my $nodestatmon=xCAT_monitoring::monitorctrl::nodeStatMonName();
|
|
|
|
#if ($nodestatmon) {
|
|
|
|
# foreach (@product_names) {
|
|
|
|
# if ($_ eq $nodestatmon) {
|
|
|
|
# my ($code, $msg)=xCAT_monitoring::monitorctrl::stopNodeStatusMonitoring($nodestatmon);
|
|
|
|
# $rsp->{data}->[$i++]="node status monitoring with $nodestatmon: $msg";
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
#}
|
|
|
|
my $table=xCAT::Table->new("monitoring", -create => 1,-autocommit => 1);
|
|
|
|
if ($table) {
|
|
|
|
(my $ref) = $table->getAttribs({name => $pname}, name);
|
|
|
|
if ($ref and $ref->{name}) {
|
|
|
|
my %key_col = (name=>$pname);
|
2008-03-04 21:45:26 +00:00
|
|
|
my %tb_cols=(disable=>"1");
|
|
|
|
$table->setAttribs(\%key_col, \%tb_cols);
|
|
|
|
}
|
2008-01-18 18:14:45 +00:00
|
|
|
else {
|
|
|
|
my %rsp;
|
2008-03-05 20:43:37 +00:00
|
|
|
$rsp->{data}->[0]="$pname was not registered or not activated.";
|
2008-01-18 18:14:45 +00:00
|
|
|
$callback->($rsp);
|
2008-03-04 21:45:26 +00:00
|
|
|
}
|
|
|
|
$table->close();
|
2007-11-29 19:34:38 +00:00
|
|
|
}
|
2008-01-18 18:14:45 +00:00
|
|
|
|
2008-03-13 02:13:29 +00:00
|
|
|
#tell all the service nodes to stop monitoring too
|
|
|
|
my $mon_hierachy=xCAT_monitoring::monitorctrl->getMonHierarchy();
|
|
|
|
my @mon_servers=keys(%$mon_hierachy);
|
|
|
|
my @hostinfo=xCAT::Utils->determinehostname();
|
|
|
|
%iphash=();
|
|
|
|
foreach(@hostinfo) {$iphash{$_}=1;}
|
|
|
|
foreach (@mon_servers) {
|
2008-03-14 17:18:42 +00:00
|
|
|
if (! $iphash{$_} && ($_ ne "noservicenode")) { #if it is not this node, meaning it is ms
|
2008-03-13 02:13:29 +00:00
|
|
|
my %rsp2;
|
|
|
|
$rsp2->{data}->[0]="sending request to $_...";
|
|
|
|
$callback->($rsp2);
|
2008-04-18 20:33:19 +00:00
|
|
|
# my $result=`psh --nonodecheck $_ monupdate 2>1&`;
|
|
|
|
# if ($result) {
|
|
|
|
# $rsp2->{data}->[0]="$result";
|
|
|
|
# $callback->($rsp2);
|
|
|
|
#}
|
|
|
|
my %req=();
|
|
|
|
push @{$req{command}}, "monupdate";
|
|
|
|
$req{'_xcatdest'}=$_;
|
|
|
|
$doreq->(\%req,\&take_answer);
|
2008-03-13 02:13:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-18 18:14:45 +00:00
|
|
|
my %rsp1;
|
|
|
|
$rsp1->{data}->[0]="done.";
|
|
|
|
$callback->($rsp1);
|
2007-11-29 19:34:38 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 20:43:37 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
2008-03-21 20:32:41 +00:00
|
|
|
=head3 monls
|
2008-03-05 20:43:37 +00:00
|
|
|
This function list the monitoring plug-in module names, status and description.
|
|
|
|
Arguments:
|
|
|
|
callback - the pointer to the callback function.
|
|
|
|
args - The format of the args is:
|
|
|
|
[-h|--help|-v|--version] or
|
|
|
|
[name] [-a|all] [-d|--description]
|
|
|
|
Returns:
|
|
|
|
0 for success. The output is returned through the callback pointer.
|
|
|
|
1. for unsuccess. The error messages are returns through the callback pointer.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
2008-03-21 20:32:41 +00:00
|
|
|
sub monls {
|
2008-03-05 20:43:37 +00:00
|
|
|
my $args=shift;
|
|
|
|
my $callback=shift;
|
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
|
|
|
|
|
|
|
# subroutine to display the usage
|
2008-03-21 20:32:41 +00:00
|
|
|
sub monls_usage
|
2008-03-05 20:43:37 +00:00
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]= "Usage:";
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[1]= " monls name [-d|--description]";
|
|
|
|
$rsp->{data}->[2]= " monls [-a|--all] [-d|--description]";
|
|
|
|
$rsp->{data}->[3]= " monls [-h|--help|-v|--version]";
|
2008-03-05 20:43:37 +00:00
|
|
|
$rsp->{data}->[4]= " name is the name of the monitoring plug-in module.";
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ARGV=@{$args};
|
|
|
|
|
|
|
|
# parse the options
|
|
|
|
if(!GetOptions(
|
|
|
|
'h|help' => \$::HELP,
|
|
|
|
'v|version' => \$::VERSION,
|
|
|
|
'a|all' => \$::ALL,
|
|
|
|
'd|discription' => \$::DESC))
|
|
|
|
{
|
2008-03-21 20:32:41 +00:00
|
|
|
&monls_usage;
|
2008-03-05 20:43:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the usage if -h or --help is specified
|
|
|
|
if ($::HELP) {
|
2008-03-21 20:32:41 +00:00
|
|
|
&monls_usage;
|
2008-03-05 20:43:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the version statement if -v or --verison is specified
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my %rsp;
|
2008-03-21 20:32:41 +00:00
|
|
|
$rsp->{data}->[0]= "monls version 1.0";
|
2008-03-05 20:43:37 +00:00
|
|
|
$callback->($rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
my %names=();
|
|
|
|
my $plugin_dir="$::XCATROOT/lib/perl/xCAT_monitoring";
|
|
|
|
my $usetab=0;
|
|
|
|
if (@ARGV > 0)
|
|
|
|
{
|
|
|
|
$names{$ARGV[0]}=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($::ALL) {
|
|
|
|
#get all the module names from /opt/xcat/lib/perl/XCAT_monitoring directory
|
|
|
|
my @plugins=glob($plugin_dir."/*.pm");
|
|
|
|
foreach (@plugins) {
|
|
|
|
/.*\/([^\/]*).pm$/;
|
|
|
|
$names{$1}=0;
|
|
|
|
}
|
|
|
|
# remove 2 files that are not plug-ins
|
|
|
|
delete($names{monitorctrl});
|
|
|
|
delete($names{montbhandler});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$usetab=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#get the list from the table
|
|
|
|
my $table=xCAT::Table->new("monitoring", -create =>1);
|
|
|
|
if ($table) {
|
|
|
|
my $tmp1=$table->getAllEntries();
|
|
|
|
if (defined($tmp1) && (@$tmp1 > 0)) {
|
|
|
|
foreach(@$tmp1) {
|
|
|
|
my $pname=$_->{name};
|
|
|
|
if (($usetab) || exists($names{$pname})) {
|
|
|
|
$names{$pname}=1;
|
|
|
|
my $monnode=0;
|
|
|
|
my $disable=1;
|
|
|
|
if ($_->{nodestatmon} =~ /1|Yes|yes|YES|Y|y/) { $monnode=1; }
|
|
|
|
if ($_->{disable} =~ /0|NO|No|no|N|n/) { $disable=0; }
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]="$pname\t\t".
|
|
|
|
($disable ? "not-monitored" : "monitored") .
|
|
|
|
($monnode ? "\tnode-status-monitored" : "");
|
|
|
|
if ($::DESC) {
|
|
|
|
#find out the monitoring plugin file and module name for the product
|
|
|
|
my $file_name="$::XCATROOT/lib/perl/xCAT_monitoring/$pname.pm";
|
|
|
|
my $module_name="xCAT_monitoring::$pname";
|
|
|
|
#load the module in memory
|
|
|
|
eval {require($file_name)};
|
|
|
|
if ($@) {
|
|
|
|
$rsp->{data}->[1]=" Description:\n not available. The file $file_name cannot be located or has compiling errors.";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rsp->{data}->[1]=${$module_name."::"}{getDescription}->() . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
} #foreach
|
|
|
|
}
|
|
|
|
$table->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#now handle the ones that are not in the table
|
|
|
|
foreach(keys(%names)) {
|
|
|
|
my $pname=$_;
|
|
|
|
if ($names{$pname}==0) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]="$pname\t\tnot-monitored";
|
|
|
|
if ($::DESC) {
|
|
|
|
#find out the monitoring plugin file and module name for the product
|
|
|
|
my $file_name="$::XCATROOT/lib/perl/xCAT_monitoring/$pname.pm";
|
|
|
|
my $module_name="xCAT_monitoring::$pname";
|
|
|
|
#load the module in memory
|
|
|
|
eval {require($file_name)};
|
|
|
|
if ($@) {
|
|
|
|
$rsp->{data}->[1]=" Description:\n not available. The file $file_name cannot be located or has compiling errors.";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rsp->{data}->[1]=${$module_name."::"}{getDescription}->(). "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 20:32:41 +00:00
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
=head3 monaddnode
|
|
|
|
This function informs all the active monitoring plug-ins to add the given
|
|
|
|
nodes to their monitoring domain
|
|
|
|
Arguments:
|
|
|
|
callback - the pointer to the callback function.
|
|
|
|
args - The format of the args is:
|
|
|
|
[-h|--help|-v|--version] or
|
|
|
|
noderange
|
|
|
|
Returns:
|
|
|
|
0 for success. The output is returned through the callback pointer.
|
|
|
|
1. for unsuccess. The error messages are returns through the callback pointer.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
sub monaddnode {
|
|
|
|
my $args=shift;
|
|
|
|
my $callback=shift;
|
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
|
|
|
|
|
|
|
# subroutine to display the usage
|
|
|
|
sub monaddnode_usage
|
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]= "Usage:";
|
|
|
|
$rsp->{data}->[1]= " monaddnode noderange";
|
|
|
|
$rsp->{data}->[2]= " monaddnode [-h|--help|-v|--version]";
|
|
|
|
$rsp->{data}->[3]= " noderange is a list of comma separated node or node group names.";
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ARGV=@{$args};
|
|
|
|
# parse the options
|
|
|
|
if(!GetOptions(
|
|
|
|
'h|help' => \$::HELP,
|
|
|
|
'v|version' => \$::VERSION,))
|
|
|
|
{
|
|
|
|
&monaddnode_usage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the usage if -h or --help is specified
|
|
|
|
if ($::HELP) {
|
|
|
|
&monaddnode_usage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the version statement if -v or --verison is specified
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]= "monaddnode version 1.0";
|
|
|
|
$callback->($rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my $noderange;
|
|
|
|
if (@ARGV < 1)
|
|
|
|
{
|
|
|
|
&monaddnode_usage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$noderange=$ARGV[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
my @nodenames=noderange($noderange);
|
|
|
|
my @missed=nodesmissed();
|
|
|
|
if (@missed > 0) {
|
|
|
|
my %rsp1;
|
|
|
|
$rsp1->{data}->[0]="Invalide nodes:@missed";
|
|
|
|
$callback->($rsp1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
my %ret=xCAT_monitoring::monitorctrl->addNodes(\@nodenames);
|
|
|
|
|
|
|
|
if (%ret) {
|
|
|
|
foreach(keys(%ret)) {
|
|
|
|
my $retstat=$ret{$_};
|
|
|
|
my %rsp1;
|
|
|
|
$rsp1->{data}->[0]="$_: @$retstat";
|
|
|
|
$callback->($rsp1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
=head3 monrmnode
|
|
|
|
This function informs all the active monitoring plug-ins to remove the given
|
|
|
|
nodes to their monitoring domain
|
|
|
|
Arguments:
|
|
|
|
callback - the pointer to the callback function.
|
|
|
|
args - The format of the args is:
|
|
|
|
[-h|--help|-v|--version] or
|
|
|
|
noderange
|
|
|
|
Returns:
|
|
|
|
0 for success. The output is returned through the callback pointer.
|
|
|
|
1. for unsuccess. The error messages are returns through the callback pointer.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
sub monrmnode {
|
|
|
|
my $args=shift;
|
|
|
|
my $callback=shift;
|
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
2007-11-29 19:34:38 +00:00
|
|
|
|
2008-03-21 20:32:41 +00:00
|
|
|
# subroutine to display the usage
|
|
|
|
sub monrmnode_usage
|
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]= "Usage:";
|
|
|
|
$rsp->{data}->[1]= " monrmnode noderange";
|
|
|
|
$rsp->{data}->[2]= " monrmnode [-h|--help|-v|--version]";
|
|
|
|
$rsp->{data}->[3]= " noderange is a list of comma separated node or node group names.";
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
2007-11-29 19:34:38 +00:00
|
|
|
|
2008-03-21 20:32:41 +00:00
|
|
|
@ARGV=@{$args};
|
|
|
|
# parse the options
|
|
|
|
if(!GetOptions(
|
|
|
|
'h|help' => \$::HELP,
|
|
|
|
'v|version' => \$::VERSION,))
|
|
|
|
{
|
|
|
|
&monrmnode_usage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the usage if -h or --help is specified
|
|
|
|
if ($::HELP) {
|
|
|
|
&monrmnode_usage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the version statement if -v or --verison is specified
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp->{data}->[0]= "monrmnode version 1.0";
|
|
|
|
$callback->($rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my $noderange;
|
|
|
|
if (@ARGV < 1)
|
|
|
|
{
|
|
|
|
&monrmnode_usage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$noderange=$ARGV[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
my @nodenames=noderange($noderange, 0);
|
|
|
|
if (@nodenames==0) { return 0;}
|
|
|
|
|
|
|
|
my %ret=xCAT_monitoring::monitorctrl->removeNodes(\@nodenames);
|
|
|
|
if (%ret) {
|
|
|
|
foreach(keys(%ret)) {
|
|
|
|
my $retstat=$ret{$_};
|
|
|
|
my %rsp1;
|
|
|
|
$rsp1->{data}->[0]="$_: @$retstat";
|
|
|
|
$callback->($rsp1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2007-11-29 19:34:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-13 02:13:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|