added support for Nagios monitorin

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@11555 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
linggao 2012-02-10 20:19:54 +00:00
parent 2d8be7cbb3
commit 2dd8e712c7
4 changed files with 1674 additions and 50 deletions

View File

@ -6520,4 +6520,44 @@ sub isSELINUX
#-------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
=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;
}
1;

View File

@ -203,6 +203,7 @@ sub sendMonSignal {
0 means local host only.
2 means both local host and nodes,
callback -- the callback pointer for error and status displaying. It can be null.
grands -- a hash pointer. key: "servicenode,xcatmaset", value: a array pointer of grand children nodes. This one is only set when the current node is mn and handleGrandChildren returns 1 by the monitoring plugin.
Returns:
A hash table keyed by the plug-in names. The value is an array pointer
pointer to a return code and message pair. For example:
@ -218,6 +219,7 @@ sub startMonitoring {
my $noderef=shift,
my $scope=shift;
my $callback=shift;
my $grands=shift;
refreshProductList();
@ -230,7 +232,7 @@ sub startMonitoring {
#print "product_names=@product_names\n";
my %ret=();
print "-------startMonitoring: product_names=@product_names\n";
#print "-------startMonitoring: product_names=@product_names\n";
foreach(@product_names) {
my $aRef=$PRODUCT_LIST{$_};
if ($aRef) {
@ -239,7 +241,7 @@ sub startMonitoring {
undef $SIG{CHLD};
#initialize and start monitoring
no strict "refs";
my @ret1 = ${$module_name."::"}{start}->($noderef, $scope, $callback);
my @ret1 = ${$module_name."::"}{start}->($noderef, $scope, $callback,$grands);
$ret{$_}=\@ret1;
} else {
$ret{$_}=[1, "Monitoring plug-in module $_ is not registered or enabled."];
@ -264,6 +266,7 @@ sub startMonitoring {
0 means local host only.
2 means both local host and nodes,
callback -- the callback pointer for error and status displaying. It can be null.
grands -- a hash pointer. key: "servicenode,xcatmaset", value: a array pointer of grand children nodes. This one is only set when the current node is mn and handleGrandChildren returns 1 by the monitoring plugin.
Returns:
(return_code, error_message)
@ -277,11 +280,12 @@ sub startNodeStatusMonitoring {
my $noderef=shift,
my $scope=shift;
my $callback=shift;
my $grands=shift;
refreshProductList();
if (!$pname) {$pname=$NODESTAT_MON_NAME;}
print "----startNodeStatusMonitoring: pname=$pname\n";
#print "----startNodeStatusMonitoring: pname=$pname\n";
if ($pname) {
my $aRef=$PRODUCT_LIST{$pname};
@ -290,12 +294,12 @@ sub startNodeStatusMonitoring {
undef $SIG{CHLD};
no strict "refs";
my $method = ${$module_name."::"}{supportNodeStatusMon}->();
print "method=$method\n";
#print "method=$method\n";
# return value 0 means not support. 1 means yes.
if ($method > 0) {
#start nodes tatus monitoring
no strict "refs";
my @ret2 = ${$module_name."::"}{startNodeStatusMon}->($noderef, $scope, $callback);
my @ret2 = ${$module_name."::"}{startNodeStatusMon}->($noderef, $scope, $callback,$grands);
return @ret2;
}
else {
@ -325,6 +329,7 @@ sub startNodeStatusMonitoring {
0 means local host only.
2 means both local host and nodes,
callback -- the callback pointer for error and status displaying. It can be null.
grands -- a hash pointer. key: "servicenode,xcatmaset", value: a array pointer of grand children nodes. This one is only set when the current node is mn and handleGrandChildren returns 1 by the monitoring plugin.
Returns:
A hash table keyed by the plug-in names. The value is ann array pointer
pointer to a return code and message pair. For example:
@ -340,6 +345,7 @@ sub stopMonitoring {
my $noderef=shift,
my $scope=shift;
my $callback=shift;
my $grands=shift;
#refreshProductList();
@ -350,7 +356,7 @@ sub stopMonitoring {
if (@product_names == 0) {
@product_names=keys(%PRODUCT_LIST);
}
print "-------stopMonitoring: product_names=@product_names\n";
#print "-------stopMonitoring: product_names=@product_names\n";
my %ret=();
@ -381,7 +387,7 @@ sub stopMonitoring {
#stop monitoring
undef $SIG{CHLD};
no strict "refs";
my @ret2 = ${$module_name."::"}{stop}->($noderef, $scope, $callback);
my @ret2 = ${$module_name."::"}{stop}->($noderef, $scope, $callback,$grands);
$ret{$_}=\@ret2;
}
@ -403,6 +409,7 @@ sub stopMonitoring {
0 means local host only.
2 means both local host and nodes,
callback -- the callback pointer for error and status displaying. It can be null.
grands -- a hash pointer. key: "servicenode,xcatmaset", value: a array pointer of grand children nodes. This one is only set when the current node is mn and handleGrandChildren returns 1 by the monitoring plugin.
Returns:
(return_code, error_message)
@ -416,6 +423,7 @@ sub stopNodeStatusMonitoring {
my $noderef=shift,
my $scope=shift;
my $callback=shift;
my $grands=shift;
#refreshProductList();
if (!$pname) {$pname=$NODESTAT_MON_NAME;}
@ -440,7 +448,7 @@ sub stopNodeStatusMonitoring {
#}
}
no strict "refs";
my @ret2 = ${$module_name."::"}{stopNodeStatusMon}->($noderef, $scope, $callback);
my @ret2 = ${$module_name."::"}{stopNodeStatusMon}->($noderef, $scope, $callback,$grands);
return @ret2;
}
}
@ -1229,6 +1237,7 @@ sub getAllRegs
0 means local host only.
2 means both local host and nodes,
callback -- the callback pointer for error and status displaying. It can be null.
grands -- a hash pointer. key: "servicenode,xcatmaset", value: a array pointer of grand children nodes. This one is only set when the current node is mn and handleGrandChildren returns 1 by the monitoring plugin.
Returns:
ret a hash with plug-in name as the keys and the an arry of
[return code, error message] as the values.
@ -1242,6 +1251,7 @@ sub config {
my $noderef=shift,
my $scope=shift;
my $callback=shift;
my $grands=shift;
my %ret=();
my @product_names=@$nameref;
@ -1251,7 +1261,7 @@ sub config {
@product_names=keys(%all);
}
print "------config: product_names=@product_names\n";
#print "------config: product_names=@product_names\n";
foreach(@product_names) {
if (exists($all{$_})) {
@ -1268,7 +1278,7 @@ sub config {
#initialize and start monitoring
no strict "refs";
if (defined(${$module_name."::"}{config})) {
my @ret1 = ${$module_name."::"}{config}->($noderef, $scope, $callback);
my @ret1 = ${$module_name."::"}{config}->($noderef, $scope, $callback, $grands);
$ret{$_}=\@ret1;
}
} else {
@ -1291,6 +1301,7 @@ sub config {
0 means local host only.
2 means both loca lhost and nodes,
callback -- the callback pointer for error and status displaying. It can be null.
grands -- a hash pointer. key: "servicenode,xcatmaset", value: a array pointer of grand children nodes. This one is only set when the current node is mn and handleGrandChildren returns 1 by the monitoring plugin.
Returns:
ret a hash with plug-in name as the keys and the an arry of
[return code, error message] as the values.
@ -1304,6 +1315,7 @@ sub deconfig {
my $noderef=shift,
my $scope=shift;
my $callback=shift;
my $grands=shift;
my @product_names=@$nameref;
@ -1312,7 +1324,7 @@ sub deconfig {
if (@product_names == 0) {
@product_names=keys(%all);
}
print "------deconfig: product_names=@product_names\n";
#print "------deconfig: product_names=@product_names\n";
foreach(@product_names) {
@ -1330,7 +1342,7 @@ sub deconfig {
#initialize and start monitoring
no strict "refs";
if (defined(${$module_name."::"}{deconfig})) {
my @ret1 = ${$module_name."::"}{deconfig}->($noderef, $scope, $callback);
my @ret1 = ${$module_name."::"}{deconfig}->($noderef, $scope, $callback, $grands);
$ret{$_}=\@ret1;
}
} else {

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,8 @@ use xCAT::MsgUtils;
use xCAT_monitoring::monitorctrl;
use xCAT::Utils;
use Sys::Hostname;
use Data::Dumper;
1;
@ -90,7 +92,7 @@ sub preprocess_request
return;
} else {
my $allnodes=$a_ret[4];
print "allnodes=@$allnodes\n";
#print "allnodes=@$allnodes\n";
my $pname=$a_ret[1];
my $file_name="$::XCATROOT/lib/perl/xCAT_monitoring/$pname.pm";
my $module_name="xCAT_monitoring::$pname";
@ -115,6 +117,8 @@ sub preprocess_request
$mon_hierachy=xCAT_monitoring::monitorctrl->getNodeMonServerPair($allnodes, 1);
}
#print Dumper($mon_hierachy);
if (ref($mon_hierachy) eq 'ARRAY') {
my $rsp2={};
$rsp2->{data}->[0]=$mon_hierachy->[1];
@ -132,39 +136,77 @@ sub preprocess_request
foreach(@hostinfo) {$iphash{$_}=1;}
if (!$isSV) { $iphash{'noservicenode'}=1;}
foreach (@mon_servers) {
#check if we should also pass nodes that are managed by the sn to mn.
my $handleGrands=0;
if (!$isSV) {
if (defined(${$module_name."::"}{handleGrandChildren})) {
$handleGrands=${$module_name."::"}{handleGrandChildren}->();
}
}
#print "handleGrands=$handleGrands\n";
my $index=0;
my $reqcopy_grands = {%$req};
foreach my $sv_pair (@mon_servers) {
#service node come in pairs, the first one is the monserver adapter that facing the mn,
# the second one is facing the cn. we use the first one here
my @server_pair=split(':', $_);
my @server_pair=split(':', $sv_pair);
my $sv=$server_pair[0];
my $mon_nodes=$mon_hierachy->{$_};
my $sv1;
if (@server_pair>1) {
$sv1=$server_pair[1];
}
my $mon_nodes=$mon_hierachy->{$sv_pair};
if ((!$mon_nodes) || (@$mon_nodes ==0)) { next; }
print "sv=$sv, nodes=@$mon_nodes\n";
#print "sv=$sv, nodes=@$mon_nodes\n";
my $reqcopy = {%$req};
if (! $iphash{$sv}) {
if ($isSV) { next; } #if the command is issued on the monserver, only handle its children.
$reqcopy->{'_xcatdest'}=$sv;
$reqcopy->{_xcatpreprocessed}->[0] = 1;
my $rsp2={};
$rsp2->{data}->[0]="sending request to $sv..., ".join(',', @$mon_nodes);
$callback->($rsp2);
}
push @{$reqcopy->{module}}, $a_ret[1];
if ($isSV) { next; } #if the command is issued on the monserver, only handle its children.
else {
if ($handleGrands) {
$index++;
$reqcopy_grands->{"grand_$index"}="$sv,$sv1," . join(',', @$mon_nodes);
}
}
$reqcopy->{'_xcatdest'}=$sv;
$reqcopy->{_xcatpreprocessed}->[0] = 1;
my $rsp2={};
$rsp2->{data}->[0]="sending request to $sv..., ".join(',', @$mon_nodes);
$callback->($rsp2);
}
push @{$reqcopy->{module}}, $a_ret[1];
if($command eq "monshow"){
push @{$reqcopy->{priv}}, $a_ret[2];
push @{$reqcopy->{priv}}, $a_ret[3];
push @{$reqcopy->{priv}}, $a_ret[5];
push @{$reqcopy->{priv}}, $a_ret[6];
push @{$reqcopy->{priv}}, $a_ret[7];
push @{$reqcopy->{priv}}, $a_ret[2];
push @{$reqcopy->{priv}}, $a_ret[3];
push @{$reqcopy->{priv}}, $a_ret[5];
push @{$reqcopy->{priv}}, $a_ret[6];
push @{$reqcopy->{priv}}, $a_ret[7];
} else {
push @{$reqcopy->{nodestatmon}}, $a_ret[2];
push @{$reqcopy->{scope}}, $a_ret[3];
push @{$reqcopy->{nodestatmon}}, $a_ret[2];
push @{$reqcopy->{scope}}, $a_ret[3];
}
push @{$reqcopy->{nodeinfo}}, join(',', @$mon_nodes);
push @requests, $reqcopy;
}
push @{$reqcopy->{nodeinfo}}, join(',', @$mon_nodes);
push @requests, $reqcopy;
}
#add the a request for mn to handle all its grand children
if ($index > 0) {
$reqcopy_grands->{grand_total}=$index;
push @{$reqcopy_grands->{module}}, $a_ret[1];
if($command eq "monshow"){
push @{$reqcopy_grands->{priv}}, $a_ret[2];
push @{$reqcopy_grands->{priv}}, $a_ret[3];
push @{$reqcopy_grands->{priv}}, $a_ret[5];
push @{$reqcopy_grands->{priv}}, $a_ret[6];
push @{$reqcopy_grands->{priv}}, $a_ret[7];
} else {
push @{$reqcopy_grands->{nodestatmon}}, $a_ret[2];
push @{$reqcopy_grands->{scope}}, $a_ret[3];
}
push @requests, $reqcopy_grands;
}
}
} else {
my $reqcopy = {%$req};
@ -411,13 +453,32 @@ sub monstart {
my $scope=$request->{scope}->[0];
my $nodeinfo=$request->{nodeinfo}->[0];
my @nodes=split(',', $nodeinfo);
print "monstart get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=$nodeinfo\nscope=$scope\n";
my $grands={};
my $total=0;
if (exists($request->{grand_total})) {
$total=$request->{grand_total};
}
for (my $i=1; $i<= $total; $i++) {
if (exists($request->{"grand_$i"})) {
my $temp=$request->{"grand_$i"};
my @tmpnodes=split(',', $temp);
if (@tmpnodes > 2) {
my $sv=shift(@tmpnodes);
my $sv1=shift(@tmpnodes);
$grands->{"$sv,$sv1"}=\@tmpnodes;
}
}
}
#print "-------grands" . Dumper($grands);
xCAT_monitoring::monitorctrl->startMonitoring([$pname], \@nodes, $scope, $callback);
my @nodes=split(',', $nodeinfo);
#print "monstart get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=$nodeinfo\nscope=$scope\n";
xCAT_monitoring::monitorctrl->startMonitoring([$pname], \@nodes, $scope, $callback, $grands);
if ($nodestatmon) {
xCAT_monitoring::monitorctrl->startNodeStatusMonitoring($pname, \@nodes, $scope, $callback);
xCAT_monitoring::monitorctrl->startNodeStatusMonitoring($pname, \@nodes, $scope, $callback, $grands);
}
return;
}
@ -596,14 +657,34 @@ sub monstop {
my $scope=$request->{scope}->[0];
my $nodeinfo=$request->{nodeinfo}->[0];
my $grands={};
my $total=0;
if (exists($request->{grand_total})) {
$total=$request->{grand_total};
}
for (my $i=1; $i<= $total; $i++) {
if (exists($request->{"grand_$i"})) {
my $temp=$request->{"grand_$i"};
my @tmpnodes=split(',', $temp);
if (@tmpnodes > 2) {
my $sv=shift(@tmpnodes);
my $sv1=shift(@tmpnodes);
$grands->{"$sv,$sv1"}=\@tmpnodes;
}
}
}
#print "-------grands" . Dumper($grands);
my @nodes=split(',', $nodeinfo);
print "monstop get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=@nodes\nscope=$scope\n";
#print "monstop get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=@nodes\nscope=$scope\n";
if ($nodestatmon) {
xCAT_monitoring::monitorctrl->stopNodeStatusMonitoring($pname, \@nodes, $scope, $callback);
xCAT_monitoring::monitorctrl->stopNodeStatusMonitoring($pname, \@nodes, $scope, $callback, $grands);
}
xCAT_monitoring::monitorctrl->stopMonitoring([$pname], \@nodes, $scope, $callback);
xCAT_monitoring::monitorctrl->stopMonitoring([$pname], \@nodes, $scope, $callback, $grands);
return;
}
@ -1003,7 +1084,7 @@ sub monadd {
foreach my $group (@pn) {
my $posts=$postscripts_h->{$group};
if ($posts) {
(my $ref) = $table2->getAttribs({node => $group}, 'postscripts');
(my $ref) = $table2->getAttribs({node => $group}, 'postscripts');
if ($ref and $ref->{postscripts}) {
my @old_a=split(',', $ref->{postscripts});
my @new_a=split(',', $posts);
@ -1399,10 +1480,30 @@ sub moncfg
my $scope=$request->{scope}->[0];
my $nodeinfo=$request->{nodeinfo}->[0];
my @nodes=split(',', $nodeinfo);
print "moncfg get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=@nodes\nscope=$scope\n";
#print "---------monctrlcmnd::moncfg request=" . Dumper($request);
my $grands={};
my $total=0;
if (exists($request->{grand_total})) {
$total=$request->{grand_total};
}
for (my $i=1; $i<= $total; $i++) {
if (exists($request->{"grand_$i"})) {
my $temp=$request->{"grand_$i"};
my @tmpnodes=split(',', $temp);
if (@tmpnodes > 2) {
my $sv=shift(@tmpnodes);
my $sv1=shift(@tmpnodes);
$grands->{"$sv,$sv1"}=\@tmpnodes;
}
}
}
#print "-------grands" . Dumper($grands);
xCAT_monitoring::monitorctrl->config([$pname], \@nodes, $scope, $callback);
my @nodes=split(',', $nodeinfo);
#print "moncfg get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=@nodes\nscope=$scope\n";
xCAT_monitoring::monitorctrl->config([$pname], \@nodes, $scope, $callback, $grands);
return 0;
}
@ -1583,10 +1684,29 @@ sub mondecfg
my $scope=$request->{scope}->[0];
my $nodeinfo=$request->{nodeinfo}->[0];
my @nodes=split(',', $nodeinfo);
print "mondecfg get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=@nodes\nscope=$scope\n";
my $grands={};
my $total=0;
if (exists($request->{grand_total})) {
$total=$request->{grand_total};
}
for (my $i=1; $i<= $total; $i++) {
if (exists($request->{"grand_$i"})) {
my $temp=$request->{"grand_$i"};
my @tmpnodes=split(',', $temp);
if (@tmpnodes > 2) {
my $sv=shift(@tmpnodes);
my $sv1=shift(@tmpnodes);
$grands->{"$sv,$sv1"}=\@tmpnodes;
}
}
}
#print "-------grands" . Dumper($grands);
my @nodes=split(',', $nodeinfo);
#print "mondecfg get called: pname=$pname\nnodestatmon=$nodestatmon\nnodeinfo=@nodes\nscope=$scope\n";
xCAT_monitoring::monitorctrl->deconfig([$pname], \@nodes, $scope, $callback, $grands);
xCAT_monitoring::monitorctrl->deconfig([$pname], \@nodes, $scope, $callback);
return 0;
}