From 41e5425d8ca665f24df06e4d108d28e13e3a8cf6 Mon Sep 17 00:00:00 2001 From: linggao Date: Fri, 14 Mar 2008 17:18:42 +0000 Subject: [PATCH] incorporated XCATCFG and hierachy in xcatmon.pm to support node liveness status monitoring git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@785 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- .../lib/xcat/monitoring/monitorctrl.pm | 10 +++--- .../lib/xcat/monitoring/xcatmon.pm | 32 +++++++++++++++---- .../lib/xcat/plugins/monctrlcmds.pm | 8 ++--- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm b/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm index 92bf94126..8dbe6d42e 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm @@ -899,7 +899,8 @@ sub getPluginSettings { Returns: A hash reference keyed by the monitoring server nodes and each value is a ref to an array of [nodes, nodetype, status] arrays monitored by the server. So the format is: - {monserver1=>[['node1', 'osi', 'active'], ['node2', 'switch', 'booting']...], ...} + {monserver1=>[['node1', 'osi', 'active'], ['node2', 'switch', 'booting']...], ...} + If there is no service node for a node, the key will be "noservicenode". =cut #-------------------------------------------------------------------------------- sub getMonHierarchy { @@ -913,20 +914,19 @@ sub getMonHierarchy { #get monserver for each node. use "monserver" attribute from noderes table, if not #defined, use "servicenode". otherwise, use loca lhost. - my @hostinfo=xCAT::Utils->determinehostname(); - my $host=pop(@hostinfo); if (defined(@tmp1) && (@tmp1 > 0)) { foreach(@tmp1) { my $node=$_->{node}; my $status=$_->{status}; my $nodetype=$_->{nodetype}; - my $monserver=$host; + my $monserver; my $tmp2=$table2->getNodeAttribs($node, ['monserver', 'servicenode']); if (defined($tmp2) && ($tmp2)) { if ($tmp2->{monserver}) { $monserver=$tmp2->{monserver}; } elsif ($tmp2->{servicenode}) { $monserver=$tmp2->{servicenode}; } } - + #print "node=$node, monserver=$monserver\n"; + if (!$monserver) { $monserver="noservicenode"; } if (exists($ret->{$monserver})) { my $pa=$ret->{$monserver}; push(@$pa, [$node, $nodetype, $status]); diff --git a/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm b/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm index bb287f02c..70705fbd0 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm @@ -9,7 +9,7 @@ use lib "$::XCATROOT/lib/perl"; use xCAT::Utils; use xCAT::GlobalDef; use xCAT_monitoring::monitorctrl; -use Sys::Hostname; + 1; @@ -115,7 +115,7 @@ sub startNodeStatusMon { if ($reading>0) { $value=$reading;} #create the cron job, it will run the command every 3 minutes. - my $newentry="*/$value * * * * XCATROOT=$::XCATROOT $cmd"; + my $newentry="*/$value * * * * XCATROOT=$::XCATROOT PATH=$ENV{'PATH'} XCATCFG='$ENV{'XCATCFG'}' $cmd"; my ($code, $msg)=xCAT::Utils::add_cron_job($newentry); if ($code==0) { return (0, "started"); } else { return ($code, $msg); } @@ -203,11 +203,29 @@ sub getMonNodesStatus { my @unknown_nodes=(); my $monservers=xCAT_monitoring::monitorctrl->getMonHierarchy(); - - my $host=hostname(); - my $monnodes=$monservers->{$host}; - if (($monnodes) && (@$monnodes >0)) { - foreach(@$monnodes) { + my $isSV=xCAT::Utils->isServiceNode(); + + #on a service node or on ms, get the nodes that has local host as the server node + my $monnodes; + my @hostinfo=xCAT::Utils->determinehostname(); + my %iphash=(); + foreach(@hostinfo) {$iphash{$_}=1;} + foreach my $host (@hostinfo) { + $monnodes=$monservers->{$host}; + if (($monnodes) && (@$monnodes >0)) { last;} + } + foreach(@$monnodes) { + my $node=$_->[0]; + my $status=$_->[2]; + if ($status eq $::STATUS_ACTIVE) { push(@active_nodes, $node);} + elsif ($status eq $::STATUS_INACTIVE) { push(@inactive_nodes, $node);} + else { push(@unknown_nodes, $node);} + } + + #on ms, add the ones that has no service nodes + if (!$isSV) { + my $monnodes_ms=$monservers->{'noservicenode'}; + foreach(@$monnodes_ms) { my $node=$_->[0]; my $status=$_->[2]; if ($status eq $::STATUS_ACTIVE) { push(@active_nodes, $node);} diff --git a/xCAT-server-2.0/lib/xcat/plugins/monctrlcmds.pm b/xCAT-server-2.0/lib/xcat/plugins/monctrlcmds.pm index 30a407abc..86a959158 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/monctrlcmds.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/monctrlcmds.pm @@ -246,11 +246,11 @@ sub startmon { } else { #update the monsetting table - if ($settings) { + if ($settings) { my $table1=xCAT::Table->new("monsetting", -create => 1,-autocommit => 1); my %key_col1 = (name=>$pname); #parse the settings. Setting format: key="value",key="value".... - while ($settings =~ s/^\[([^\[\]\=]*)=([^\[\]]*)\](,)*//) { + while ($settings =~ s/^\[([^\[\]\=]*)=([^\[\]]*)\](,)*//) { $key_col1{key}=$1; $setting_hash{value}=$2; $table1->setAttribs(\%key_col1, \%setting_hash); @@ -278,7 +278,7 @@ sub startmon { %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} foreach (@mon_servers) { - if (! $iphash{$_}) { #if it is not this node, meaning it is ms + if (! $iphash{$_} && ($_ ne "noservicenode")) { #if it is not this node, meaning it is ms my %rsp2; $rsp2->{data}->[0]="sending request to $_..."; $callback->($rsp2); @@ -419,7 +419,7 @@ sub stopmon { %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} foreach (@mon_servers) { - if (! $iphash{$_}) { #if it is not this node, meaning it is ms + if (! $iphash{$_} && ($_ ne "noservicenode")) { #if it is not this node, meaning it is ms my %rsp2; $rsp2->{data}->[0]="sending request to $_..."; $callback->($rsp2);