diff --git a/xCAT-rmc/plugin/rmcmon.pm b/xCAT-rmc/plugin/rmcmon.pm index 3ef9f48f1..6887489e9 100644 --- a/xCAT-rmc/plugin/rmcmon.pm +++ b/xCAT-rmc/plugin/rmcmon.pm @@ -300,6 +300,11 @@ sub stop { if ($scope) { my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + reportError($pPairHash->[1], $callback); + return (1, ""); + } + #the identification of this node my @hostinfo=xCAT::Utils->determinehostname(); @@ -309,10 +314,10 @@ sub stop { if (!$isSV) { $iphash{'noservicenode'}=1;} foreach my $key (keys (%$pPairHash)) { - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next;} my $mon_nodes=$pPairHash->{$key}; - + #figure out what nodes to stop my @nodes_to_stop=(); if ($mon_nodes) { @@ -398,6 +403,11 @@ sub config { `/usr/bin/rmcctrl -p`; my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + reportError($pPairHash->[1], $callback); + return (1, ""); + } + #the identification of this node my @hostinfo=xCAT::Utils->determinehostname(); @@ -407,9 +417,10 @@ sub config { if (!$isSV) { $iphash{'noservicenode'}=1;} foreach my $key (keys (%$pPairHash)) { - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next;} my $mon_nodes=$pPairHash->{$key}; + my $master=$key_a[1]; #figure out what nodes to add @@ -491,6 +502,10 @@ sub deconfig { my $callback=shift; my $localhostname=hostname(); my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + reportError($pPairHash->[1], $callback); + return (1, ""); + } #the identification of this node my @hostinfo=xCAT::Utils->determinehostname(); @@ -500,9 +515,10 @@ sub deconfig { if (!$isSV) { $iphash{'noservicenode'}=1;} foreach my $key (keys (%$pPairHash)) { - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next;} my $mon_nodes=$pPairHash->{$key}; + my $master=$key_a[1]; #figure out what nodes to remove @@ -585,6 +601,10 @@ sub startNodeStatusMon { #get all the nodes status from IBM.MngNode class of local host and #the identification of this node my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + reportError($pPairHash->[1], $callback); + return (1, ""); + } my @hostinfo=xCAT::Utils->determinehostname(); my %iphash=(); @@ -594,9 +614,10 @@ sub startNodeStatusMon { my @servicenodes=(); my %status_hash=(); foreach my $key (keys (%$pPairHash)) { - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next; } + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next;} my $mon_nodes=$pPairHash->{$key}; + foreach(@$mon_nodes) { my $nodetype=$_->[1]; if ($nodetype) { diff --git a/xCAT-server/lib/xcat/monitoring/gangliamon.pm b/xCAT-server/lib/xcat/monitoring/gangliamon.pm index 20f2772be..de304ea96 100755 --- a/xCAT-server/lib/xcat/monitoring/gangliamon.pm +++ b/xCAT-server/lib/xcat/monitoring/gangliamon.pm @@ -50,31 +50,20 @@ sub start $noderef=shift; } my $scope=shift; - print "scope is: $scope \n"; my $callback=shift; my $localhost=hostname(); - print "local host is $localhost \n"; my $OS=`uname`; - print "OS is $OS \n"; - print "starting gmond locally \n"; my $res_gmond; if ( $OS =~ /AIX/ ) { - print "OS is AIX \n"; $res_gmond = `/etc/rc.d/init.d/gmond restart 2>&1`; - print "res_gmond=$res_gmond\n"; - print "the result gmond before is $? \n"; } else { - print "OS is not AIX \n"; $res_gmond = `/etc/init.d/gmond restart 2>&1`; - print "res_gmond=$res_gmond\n"; - print "the result gmond before is $? \n"; } if ($?) { - print "gmond result after is $? \n"; if ($callback) { my $resp={}; @@ -89,26 +78,18 @@ sub start return(1,"Ganglia Gmond not started successfully. \n"); } - print "starting gmetad locally \n"; my $res_gmetad; if ( $OS =~ /AIX/ ) { - print "OS is AIX \n"; $res_gmetad = `/etc/rc.d/init.d/gmetad restart 2>&1`; - print "res_gmetad=$res_gmetad\n"; - print "the result gmetad before is $? \n"; } else { - print "OS is not AIX \n"; $res_gmetad = `/etc/init.d/gmetad restart 2>&1`; - print "res_gmetad=$res_gmetad\n"; - print "the result gmetad before is $? \n"; } if ($?) { - print "gmetad result after is $? \n"; if ($callback) { my $resp={}; @@ -128,17 +109,21 @@ sub start if ($scope) { #opening if scope my $OS=`uname`; - print "OS is $OS \n"; - print "opening scope \n"; - print "inside scope is:$scope"; - print "noderef is: @$noderef \n"; my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); - print "pairhash: $pPairHash\n"; + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } + #identification of this node my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; my $isSV=xCAT::Utils->isServiceNode(); - print "is sv is:$isSV \n"; my %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} if (!$isSV) { $iphash{'noservicenode'}=1;} @@ -146,39 +131,29 @@ sub start my @children; foreach my $key (keys (%$pPairHash)) { #opening foreach1 - print "opening foreach1 \n"; - print "key is: $key \n"; - my @key_a=split(',', $key); - print "a[0] is: $key_a[0] \n"; - print "a[1] is: $key_a[1] \n"; - if (! $iphash{$key_a[0]}) { next;} + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } my $mon_nodes=$pPairHash->{$key}; + foreach(@$mon_nodes) { #opening foreach2 my $node=$_->[0]; my $nodetype=$_->[1]; - print "node=$node, nodetype=$nodetype\n"; if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) { push(@children,$node); } } #closing foreach2 } #closing foreach1 - print "children:@children\n"; my $rec = join(',',@children); - print "the string is $rec"; my $result; if ( $OS =~ /AIX/ ) { - print "OS is AIX \n"; - print "XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/rc.d/init.d/gmond restart 2>& \n"; $result = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/rc.d/init.d/gmond restart 2>&1`; } else { - print "OS is not AIX \n"; - print "XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/gmond restart 2>& \n"; $result = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/gmond restart 2>&1`; } @@ -233,7 +208,6 @@ sub config $noderef=shift; } my $scope=shift; - print "scope is $scope \n"; my $callback=shift; confGmond($noderef,$scope,$callback); @@ -256,279 +230,260 @@ sub config #-------------------------------------------------------------- sub confGmond - { +{ print "gangliamon:confGmond called \n"; - no warnings; - # no strict 'vars'; + no warnings; + # no strict 'vars'; my $noderef=shift; if ($noderef =~ /xCAT_monitoring::gangliamon/) { - $noderef=shift; + $noderef=shift; } my $scope=shift; - print "scope inside Gmonc is $scope \n"; my $callback=shift; - - my $localhost=hostname(); - - chomp(my $hostname = `hostname`); - print "cluster is: $hostname \n"; - - print "checking gmond settings \n"; - if (-e "/etc/ganglia/gmond.conf") - { #opening if 3.1.0 - print "ganglia version 3.1.0 \n"; - `/bin/grep "xCAT gmond settings done" /etc/ganglia/gmond.conf`; - print "result in V3.1.0 is $? \n"; - - if($?) - { #openinf if ? - if($callback) { - my $resp={}; - $resp->{data}->[0]="$localhost: $?"; - $callback->($resp); - } else { xCAT::MsgUtils->message('S', "Gmond not configured $? \n"); } - - #backup the original file - print "backing up original gmond file \n"; - `/bin/cp -f /etc/ganglia/gmond.conf /etc/ganglia/gmond.conf.orig`; - print "original file backed up \n"; - my $master=xCAT::Utils->get_site_Master(); - print "obtained site master: $master \n"; - open(FILE1, "/etc/ganglia/gmond.conf.tmp"); - print "files opened for config \n"; - my $fname = "/etc/ganglia/gmond.conf"; - unless ( open( CONF, $fname )) - { - return(0); - } - - my @raw_data = ; - close( CONF ); - print "trying to pattern matching \n"; - my $str = join('',@raw_data); - $str =~ s/setuid = yes/setuid = no/; - $str =~ s/bind/#bind/; - $str =~ s/mcast_join = .*/host = $master/; - print "Phase 1 pattern matching done and trying to use monitoctrl \n"; - my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); - print "pair has obtained \n"; - print "pairHash: $pPairHash \n"; - #identification of this node - my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; - my $isSV=xCAT::Utils->isServiceNode(); - my %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - if (!$isSV) { $iphash{'noservicenode'}=1;} - - # my @children; - foreach my $key (keys (%$pPairHash)) - { #opening for each - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} - print "a[0] is: $key_a[0] \n"; - print "a[1] is: $key_a[1] \n"; - my $pattern = '^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'; - if ( $key_a[0]!~/$pattern/ ) - { - my $cluster = $key_a[0]; - print "it workrd cluster is: $cluster \n"; - if (-e "/etc/xCATSN") - { - $str =~ s/name = "unspecified"/name="$cluster"/; - } - } - - } #closing for each - - $str =~ s/name = "unspecified"/name="$hostname"/; - $str =~ s/mcast_join/# mcast_join/; - print FILE $str; - print FILE "# xCAT gmond settings done \n"; - print "Gmond conf succ \n"; - close(FILE1); - close(FILE); - print "files closed \n"; - `/bin/cp -f /etc/ganglia/gmond.conf.tmp /etc/ganglia/gmond.conf`; - - # } #closing for each - - } #closing if ? - - } #closing if 3.1.0 - - else - { #opening if 3.0.7 - print "ganglia version 3.0.7 \n"; - `/bin/grep "xCAT gmond settings done" /etc/gmond.conf`; - print "result in V3.0.7 is $? \n"; - - if($?) - { #openinf if ? - if($callback) { - my $resp={}; - $resp->{data}->[0]="$localhost: $?"; - $callback->($resp); - } else { xCAT::MsgUtils->message('S', "Gmond not configured $? \n"); } - - #backup the original file - print "backing up original gmond file \n"; - `/bin/cp -f /etc/gmond.conf /etc/gmond.conf.orig`; - print "original file backed up \n"; - my $master=xCAT::Utils->get_site_Master(); - print "obtained site master: $master \n"; - open(FILE1, "/etc/gmond.conf.tmp"); - print "files opened for config \n"; - my $fname = "/etc/gmond.conf"; - unless ( open( CONF, $fname )) - { - return(0); - } - - my @raw_data = ; - close( CONF ); - print "trying to pattern matching \n"; - my $str = join('',@raw_data); - $str =~ s/setuid = yes/setuid = no/; - $str =~ s/bind/#bind/; - $str =~ s/mcast_join = .*/host = $master/; - print "Phase 1 pattern matching done and trying to use monitoctrl \n"; - my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); - print "pair has obtained \n"; - print "pairHash: $pPairHash \n"; - #identification of this node - my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; - my $isSV=xCAT::Utils->isServiceNode(); - my %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - if (!$isSV) { $iphash{'noservicenode'}=1;} - - # my @children; - foreach my $key (keys (%$pPairHash)) - { #opening for each - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} - print "a[0] is: $key_a[0] \n"; - print "a[1] is: $key_a[1] \n"; - my $pattern = '^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'; - if ( $key_a[0]!~/$pattern/ ) - { - my $cluster = $key_a[0]; - print "it workrd cluster is: $cluster \n"; - if (-e "/etc/xCATSN") - { - $str =~ s/name = "unspecified"/name="$cluster"/; - } - } - - } #closing for each - - $str =~ s/name = "unspecified"/name="$hostname"/; - $str =~ s/mcast_join/# mcast_join/; - print FILE $str; - print FILE "# xCAT gmond settings done \n"; - print "Gmond conf succ \n"; - close(FILE1); - close(FILE); - print "files closed \n"; - `/bin/cp -f /etc/gmond.conf.tmp /etc/gmond.conf`; - - # } #closing for each - - } #closing if ? - } #closing if 3.0.7 + my $localhost=hostname(); + + chomp(my $hostname = `hostname`); + if (-e "/etc/ganglia/gmond.conf") + { #opening if 3.1.0 + `/bin/grep "xCAT gmond settings done" /etc/ganglia/gmond.conf`; + + if($?) + { #openinf if ? + if($callback) { + my $resp={}; + $resp->{data}->[0]="$localhost: $?"; + $callback->($resp); + } else { xCAT::MsgUtils->message('S', "Gmond not configured $? \n"); } + + #backup the original file + `/bin/cp -f /etc/ganglia/gmond.conf /etc/ganglia/gmond.conf.orig`; + my $master=xCAT::Utils->get_site_Master(); + open(FILE1, "/etc/ganglia/gmond.conf.tmp"); + my $fname = "/etc/ganglia/gmond.conf"; + unless ( open( CONF, $fname )) + { + return(0); + } + + my @raw_data = ; + close( CONF ); + my $str = join('',@raw_data); + $str =~ s/setuid = yes/setuid = no/; + $str =~ s/bind/#bind/; + $str =~ s/mcast_join = .*/host = $master/; + my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } - - if ($scope) - {#opening if scope of confGmond - print "opening scope \n"; - print "inside scope is:$scope"; + #identification of this node + my @hostinfo=xCAT::Utils->determinehostname(); + my $isSV=xCAT::Utils->isServiceNode(); + my %iphash=(); + foreach(@hostinfo) {$iphash{$_}=1;} + if (!$isSV) { $iphash{'noservicenode'}=1;} + + # my @children; + foreach my $key (keys (%$pPairHash)) + { #opening for each + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } + my $pattern = '^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'; + if ( $key_a[0]!~/$pattern/ ) + { + my $cluster = $key_a[0]; + if (-e "/etc/xCATSN") + { + $str =~ s/name = "unspecified"/name="$cluster"/; + } + } + + } #closing for each + + $str =~ s/name = "unspecified"/name="$hostname"/; + $str =~ s/mcast_join/# mcast_join/; + print FILE $str; + print FILE "# xCAT gmond settings done \n"; + close(FILE1); + close(FILE); + `/bin/cp -f /etc/ganglia/gmond.conf.tmp /etc/ganglia/gmond.conf`; + + # } #closing for each + + } #closing if ? + + } #closing if 3.1.0 + + else + { #opening if 3.0.7 + `/bin/grep "xCAT gmond settings done" /etc/gmond.conf`; + + if($?) + { #openinf if ? + if($callback) { + my $resp={}; + $resp->{data}->[0]="$localhost: $?"; + $callback->($resp); + } else { xCAT::MsgUtils->message('S', "Gmond not configured $? \n"); } + + #backup the original file + `/bin/cp -f /etc/gmond.conf /etc/gmond.conf.orig`; + my $master=xCAT::Utils->get_site_Master(); + open(FILE1, "/etc/gmond.conf.tmp"); + my $fname = "/etc/gmond.conf"; + unless ( open( CONF, $fname )) + { + return(0); + } + + my @raw_data = ; + close( CONF ); + my $str = join('',@raw_data); + $str =~ s/setuid = yes/setuid = no/; + $str =~ s/bind/#bind/; + $str =~ s/mcast_join = .*/host = $master/; + my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } + + #identification of this node + my @hostinfo=xCAT::Utils->determinehostname(); + my $isSV=xCAT::Utils->isServiceNode(); + my %iphash=(); + foreach(@hostinfo) {$iphash{$_}=1;} + if (!$isSV) { $iphash{'noservicenode'}=1;} + + # my @children; + foreach my $key (keys (%$pPairHash)) + { #opening for each + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } + + my $pattern = '^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'; + if ( $key_a[0]!~/$pattern/ ) + { + my $cluster = $key_a[0]; + if (-e "/etc/xCATSN") + { + $str =~ s/name = "unspecified"/name="$cluster"/; + } + } + + } #closing for each + + $str =~ s/name = "unspecified"/name="$hostname"/; + $str =~ s/mcast_join/# mcast_join/; + print FILE $str; + print FILE "# xCAT gmond settings done \n"; + close(FILE1); + close(FILE); + `/bin/cp -f /etc/gmond.conf.tmp /etc/gmond.conf`; + + # } #closing for each + + } #closing if ? + + } #closing if 3.0.7 + + + + if ($scope) + {#opening if scope of confGmond chomp(my $hostname = `hostname`); my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); - - print "pairHash: $pPairHash \n"; + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } + #identification of this node my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; my $isSV=xCAT::Utils->isServiceNode(); my %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} if (!$isSV) { $iphash{'noservicenode'}=1;} - - my @children; - foreach my $key (keys (%$pPairHash)) + + my @children; + foreach my $key (keys (%$pPairHash)) { #opening for each - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} - print "a[0] is: $key_a[0] \n"; - print "a[1] is: $key_a[1] \n"; - if (! $iphash{$key_a[0]}) { next;} - my $mon_nodes=$pPairHash->{$key}; - - foreach(@$mon_nodes) - { #opening foreach2 - my $node=$_->[0]; - my $nodetype=$_->[1]; - #print "node=$node, nodetype=$nodetype\n"; - if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) - { - push(@children,$node); - } - } #closing foreach2 - - my $node = join(',',@children); - print "the children are: $node \n"; - print "copying into CP node \n"; - my $res_cp = `XCATBYPASS=Y $::XCATROOT/bin/xdcp $node /install/postscripts/confGang /tmp 2>&1`; - if($?) - { #openinf if ? - if($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: $res_cp"; - $callback->($resp); - } - else { xCAT::MsgUtils->message('S', "Cannot copy confGang into /tmp: $res_cp \n"); } - } #closing if ? - - - print "shell script time \n"; - print "MONSERVER is $key_a[0] \n"; - print "MONMASTER is $key_a[1] \n"; - my $res_conf; - if ( $key_a[0] =~ /noservicenode/ ) - { - $res_conf=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $node MONSERVER=$hostname MONMASTER=$key_a[1] /tmp/confGang 2>&1`; - } - - else - { - $res_conf=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $node MONSERVER=$key_a[0] MONMASTER=$key_a[1] /tmp/confGang 2>&1`; - } - if($?) - { #openinf if ? - if($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: $res_conf"; - $callback->($resp); - } - else { xCAT::MsgUtils->message('S', "Cannot configure gmond in nodes: $res_conf \n"); } - } #closing if ? - } #closing for each + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } + my $mon_nodes=$pPairHash->{$key}; + + foreach(@$mon_nodes) + { #opening foreach2 + my $node=$_->[0]; + my $nodetype=$_->[1]; + #print "node=$node, nodetype=$nodetype\n"; + if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) + { + push(@children,$node); + } + } #closing foreach2 + + my $node = join(',',@children); + my $res_cp = `XCATBYPASS=Y $::XCATROOT/bin/xdcp $node /install/postscripts/confGang /tmp 2>&1`; + if($?) + { #openinf if ? + if($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: $res_cp"; + $callback->($resp); + } + else { xCAT::MsgUtils->message('S', "Cannot copy confGang into /tmp: $res_cp \n"); } + } #closing if ? + + + my $res_conf; + if ( $key_a[0] =~ /noservicenode/ ) + { + $res_conf=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $node MONSERVER=$hostname MONMASTER=$key_a[1] /tmp/confGang 2>&1`; + } + + else + { + $res_conf=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $node MONSERVER=$key_a[0] MONMASTER=$key_a[1] /tmp/confGang 2>&1`; + } + if($?) + { #openinf if ? + if($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: $res_conf"; + $callback->($resp); + } + else { xCAT::MsgUtils->message('S', "Cannot configure gmond in nodes: $res_conf \n"); } + } #closing if ? + } #closing for each - }#closing if scope - - - - - - } # closing subroutine + }#closing if scope +} # closing subroutine #-------------------------------------------------------------- =head3 confGmetad @@ -553,20 +508,14 @@ sub confGmetad $noderef=shift; } my $scope=shift; - print "scope inside confGmetad is $scope \n"; my $callback=shift; my $localhost=hostname(); chomp(my $hostname = `hostname`); - print "cluster is: $hostname \n"; - - print "checking gmetad settings \n"; if (-e "/etc/ganglia/gmetad.conf") { #opening if 3.1.0 - print "ganglia version 3.1.0 \n"; `/bin/grep "xCAT gmetad settings done" /etc/ganglia/gmetad.conf`; - print "result V3.1.0 is $? \n"; if($?) { #openinf if ? @@ -576,7 +525,6 @@ sub confGmetad $callback->($resp); } else { xCAT::MsgUtils->message('S', "Gmetad not configured $? \n"); } # backup the original file - print "backing up original gmetad file \n"; `/bin/cp -f /etc/ganglia/gmetad.conf /etc/ganglia/gmetad.conf.orig`; open(FILE1, "getMonHierarchy(); + if (ref($noderef) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$noderef->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $noderef->[1]); + } + return (1, ""); + } + + my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; my $isSV=xCAT::Utils->isServiceNode(); my %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} @@ -614,23 +572,19 @@ sub confGmetad my $cluster; foreach my $key (keys (%$noderef)) { - my @key_g=split(',', $key); - # print "a[0] is: $key_g[0] \n"; + my @key_g=split(':', $key); if (! $iphash{$key_g[0]}) { next;} my $mon_nodes=$noderef->{$key}; - print "a[0] is hi: $key_g[0] \n"; my $pattern = '^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'; if ( $key_g[0]!~/$pattern/ ) { no warnings; $cluster = $key_g[0]; - print "found cluster: $cluster \n"; } foreach(@$mon_nodes) { my $node=$_->[0]; my $nodetype=$_->[1]; - print "node=$node, nodetype=$nodetype\n"; if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) { push(@children,$node); @@ -638,17 +592,12 @@ sub confGmetad } } - print "children:@children\n"; my $num=@children; - print "the number of children is: $num \n"; if (-e "/etc/xCATSN") { - print "cluster hi is $cluster \n"; for (my $i = 0; $i < $num; $i++) { - print "childred is $children[ $i ] \n"; print ( OUTFILE "data_source \"$cluster\" $children[ $i ] \n"); - print "children printed \n"; } } @@ -656,9 +605,7 @@ sub confGmetad { for (my $j = 0; $j < $num; $j++) { - print "childred is $children[ $j ] \n"; print ( OUTFILE "data_source \"$children[ $j ]\" $children[ $j ] \n"); - print "children printed \n"; } } print(OUTFILE "# xCAT gmetad settings done \n"); @@ -669,9 +616,7 @@ sub confGmetad else {#opening if 3.0.7 - print "ganglia version 3.0.7 \n"; `/bin/grep "xCAT gmetad settings done" /etc/gmetad.conf`; - print "result in V3.0.7 is $? \n"; if($?) { #openinf if ? if($callback) { @@ -680,7 +625,6 @@ else $callback->($resp); } else { xCAT::MsgUtils->message('S', "Gmetad not configured $? \n"); } # backup the original file - print "backing up original gmetad file \n"; `/bin/cp -f /etc/gmetad.conf /etc/gmetad.conf.orig`; open(FILE1, "getMonHierarchy(); + if (ref($noderef) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$noderef->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $noderef->[1]); + } + return (1, ""); + } + my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; my $isSV=xCAT::Utils->isServiceNode(); my %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} @@ -718,23 +669,20 @@ else my $cluster; foreach my $key (keys (%$noderef)) { - my @key_g=split(',', $key); + my @key_g=split(':', $key); # print "a[0] is: $key_g[0] \n"; if (! $iphash{$key_g[0]}) { next;} my $mon_nodes=$noderef->{$key}; - print "a[0] is hi: $key_g[0] \n"; my $pattern = '^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'; if ( $key_g[0]!~/$pattern/ ) { no warnings; $cluster = $key_g[0]; - print "found cluster: $cluster \n"; } foreach(@$mon_nodes) { my $node=$_->[0]; my $nodetype=$_->[1]; - print "node=$node, nodetype=$nodetype\n"; if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) { push(@children,$node); @@ -742,17 +690,12 @@ else } } - print "children:@children\n"; my $num=@children; - print "the number of children is: $num \n"; if (-e "/etc/xCATSN") { - print "culster hi is $cluster \n"; for (my $i = 0; $i < $num; $i++) { - print "childred is $children[ $i ] \n"; print ( OUTFILE "data_source \"$cluster\" $children[ $i ] \n"); - print "children printed \n"; } } @@ -760,9 +703,7 @@ else { for (my $j = 0; $j < $num; $j++) { - print "childred is $children[ $j ] \n"; print ( OUTFILE "data_source \"$children[ $j ]\" $children[ $j ] \n"); - print "children printed \n"; } } print(OUTFILE "# xCAT gmetad settings done \n"); @@ -801,7 +742,6 @@ sub deconfig $noderef=shift; } my $scope=shift; - print "scope is $scope \n"; my $callback=shift; deconfGmond($noderef,$scope,$callback); @@ -832,17 +772,13 @@ sub deconfGmond $noderef=shift; } my $scope=shift; - print "scope inside Gmond is $scope \n"; my $callback=shift; my $localhost=hostname(); - print "saving configured Gmond file \n"; if (-e "/etc/ganglia/gmond.conf") { #opening if V3.1.0 - print "Ganglia V 3.1.0 \n"; `/bin/cp -f /etc/ganglia/gmond.conf /etc/ganglia/gmond.conf.save`; - print "deconfiguring Ganglia Gmond \n"; my $decon_gmond=`/bin/cp -f /etc/ganglia/gmond.conf.orig /etc/ganglia/gmond.conf`; if($?) { #openinf if ? @@ -856,9 +792,7 @@ sub deconfGmond else { #opening V3.0.7 - print "Ganglia V 3.0.7 \n"; `/bin/cp -f /etc/gmond.conf /etc/gmond.conf.save`; - print "deconfiguring Ganglia Gmond \n"; my $decon_gmond=`/bin/cp -f /etc/gmond.conf.orig /etc/gmond.conf`; if($?) { #openinf if ? @@ -872,34 +806,36 @@ sub deconfGmond if ($scope) {#opening if scope of confGmond - print "opening scope \n"; - print "inside scope is:$scope"; my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } - print "pairHash: $pPairHash \n"; #identification of this node my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; my $isSV=xCAT::Utils->isServiceNode(); my %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} if (!$isSV) { $iphash{'noservicenode'}=1;} - my @children; - foreach my $key (keys (%$pPairHash)) + my @children; + foreach my $key (keys (%$pPairHash)) { #opening for each - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} - print "a[0] is: $key_a[0] \n"; - print "a[1] is: $key_a[1] \n"; - if (! $iphash{$key_a[0]}) { next;} - my $mon_nodes=$pPairHash->{$key}; - + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } + my $mon_nodes=$pPairHash->{$key}; + foreach(@$mon_nodes) { #opening foreach2 my $node=$_->[0]; my $nodetype=$_->[1]; - #print "node=$node, nodetype=$nodetype\n"; if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) { push(@children,$node); @@ -907,11 +843,8 @@ sub deconfGmond } #closing foreach2 my $node = join(',',@children); - print "the children are: $node \n"; - print "saving the configured Gmond file in childern \n"; if (-e "/etc/ganglia/gmond.conf") { # opening if V3.1.0 - print "Ganglia V 3.1.0 \n"; my $res_sv = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $node /bin/cp -f /etc/ganglia/gmond.conf /etc/ganglia/gmond.conf.save`; my $res_cp = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $node /bin/cp -f /etc/ganglia/gmond.conf.orig /etc/ganglia/gmond.conf`; @@ -929,7 +862,6 @@ sub deconfGmond else { - print "Ganglia V 3.0.7 \n"; my $res_sv = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $node /bin/cp -f /etc/gmond.conf /etc/gmond.conf.save`; my $res_cp = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $node /bin/cp -f /etc/gmond.conf.orig /etc/gmond.conf`; @@ -973,17 +905,13 @@ sub deconfGmetad $noderef=shift; } my $scope=shift; - print "scope inside Gmetad is $scope \n"; my $callback=shift; my $localhost=hostname(); - print "saving configured Gmetad file \n"; if (-e "/etc/ganglia/gmetad.conf") { #opening V3.1.0 - print "Ganglia V 3.1.0 \n"; `/bin/cp -f /etc/ganglia/gmetad.conf /etc/ganglia/gmetad.conf.save`; - print "deconfiguring Ganglia Gmetad \n"; my $decon_gmetad=`/bin/cp -f /etc/ganglia/gmetad.conf.orig /etc/ganglia/gmetad.conf`; if($?) { #openinf if ? @@ -997,9 +925,7 @@ sub deconfGmetad else { #opening V3.0.7 - print "Ganglia V 3.0.7 \n"; `/bin/cp -f /etc/gmetad.conf /etc/gmetad.conf.save`; - print "deconfiguring Ganglia Gmetad \n"; my $decon_gmetad=`/bin/cp -f /etc/gmetad.conf.orig /etc/gmetad.conf`; if($?) { #openinf if ? @@ -1044,28 +970,19 @@ sub stop my $scope=shift; my $callback=shift; my $localhost=hostname(); - print "local host is $localhost \n"; my $OS=`uname`; - print "stopping gmond locally \n"; my $res_gmond; if ( $OS =~ /AIX/ ) { - print "OS is AIX \n"; $res_gmond = `/etc/rc.d/init.d/gmond stop 2>&1`; - print "res_gmond=$res_gmond\n"; - print "the result gmond before is $? \n"; } else { - print "OS is not AIX \n"; $res_gmond = `/etc/init.d/gmond stop 2>&1`; - print "res_gmond=$res_gmond\n"; - print "the result gmond before is $? \n"; } if ($?) { - print "gmond result after is $? \n"; if ($callback) { my $resp={}; @@ -1080,26 +997,18 @@ sub stop return(1,"Ganglia Gmond not stopped successfully. \n"); } - print "stopping gmetad locally \n"; my $res_gmetad; if ( $OS =~ /AIX/ ) { - print "OS is AIX \n"; $res_gmetad = `/etc/rc.d/init.d/gmetad stop 2>&1`; - print "res_gmetad=$res_gmetad\n"; - print "the result gmetad before is $? \n"; } else { - print "OS is not AIX \n"; $res_gmetad = `/etc/init.d/gmetad stop 2>&1`; - print "res_gmetad=$res_gmetad\n"; - print "the result gmetad before is $? \n"; } if ($?) { - print "gmetad result after is $? \n"; if ($callback) { my $resp={}; @@ -1116,19 +1025,23 @@ sub stop - if ($scope) - { #opening if scope - my $OS=`uname`; - print "the OS is $OS \n"; - print "opening scope \n"; - print "noderef is: @$noderef \n"; - my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); - print "pairhash: $pPairHash\n"; + if ($scope) { #opening if scope + my $OS=`uname`; + my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } + #identification of this node my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; my $isSV=xCAT::Utils->isServiceNode(); - print "is sv is:$isSV \n"; my %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} if (!$isSV) { $iphash{'noservicenode'}=1;} @@ -1136,39 +1049,29 @@ sub stop my @children; foreach my $key (keys (%$pPairHash)) { #opening foreach1 - print "opening foreach1 \n"; - print "key is: $key \n"; - my @key_a=split(',', $key); - print "a[1] is: $key_a[1] \n"; - if (! $iphash{$key_a[0]}) { next;} + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } my $mon_nodes=$pPairHash->{$key}; foreach(@$mon_nodes) { #opening foreach2 my $node=$_->[0]; my $nodetype=$_->[1]; - print "node=$node, nodetype=$nodetype\n"; if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) { push(@children,$node); } } #closing foreach2 } #closing foreach1 - print "children:@children\n"; my $rec = join(',',@children); - print "the string is $rec"; my $result; if ( $OS =~ /AIX/ ) { - print "OS is AIX \n"; - print "XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/rc.d/init.d/gmond stop 2>& \n"; $result = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/rc.d/init.d/gmond stop 2>&1`; } else { - print "OS is not AIX \n"; - print "XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/gmond stop 2>& \n"; $result = `XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/gmond stop 2>&1`; } diff --git a/xCAT-server/lib/xcat/monitoring/monitorctrl.pm b/xCAT-server/lib/xcat/monitoring/monitorctrl.pm index 5c4d88f6c..35d4105d0 100644 --- a/xCAT-server/lib/xcat/monitoring/monitorctrl.pm +++ b/xCAT-server/lib/xcat/monitoring/monitorctrl.pm @@ -789,14 +789,16 @@ sub getPluginSettings { sub isMonServer { my $pHash=getNodeMonServerPair([], 1); + if (ref($pHash) eq 'ARRAY') { return 0; } + my @hostinfo=xCAT::Utils->determinehostname(); my $isSV=xCAT::Utils->isServiceNode(); my %iphash=(); foreach(@hostinfo) {$iphash{$_}=1;} if (!$isSV) { $iphash{'noservicenode'}=1;} - + foreach my $pair (keys(%$pHash)) { - my @a=split(',', $pair); + my @a=split(':', $pair); if ($iphash{$a[0]} || $iphash{$a[1]}) { return 1;} } @@ -810,10 +812,10 @@ sub isMonServer { nodelist table will be used. retfromat 0-- A pointer to a hash table with node as the key and a the monserver pairs string as the value. - For example: { node1=>"sv1,ma1", node2=>"sv1,ma1", node3=>"sv2,ma2"...} + For example: { node1=>"sv1:ma1", node2=>"sv2:ma2", node3=>"sv2:ma2"...} 1-- A pointer to a hash table with monserver pairs as the key and an array pointer of nodes as the value. - For example: { "sv1,ma1"=>[node1,node2], "sv2,ma2"=>node3...} + For example: { "sv1:ma1"=>[node1,node2], "sv2:ma2"=>node3...} The pair is in the format of "monserver,monmaser". First one is the monitoring service node ip/hostname that faces the mn and the second one is the monitoring service @@ -822,6 +824,7 @@ sub isMonServer { for that node. In this case the second one is the site master. Returns: An pointer to a hash. + It retuens a pointer to an array if there is an error. Format is [code, message]. =cut #-------------------------------------------------------------------------------- sub getNodeMonServerPair { @@ -852,9 +855,10 @@ sub getNodeMonServerPair { my $tmp2 = $tabdata->{$node}->[0]; if ($tmp2 && $tmp2->{monserver}) { $pairs=$tmp2->{monserver}; + $pairs =~ s/,/:/; #for backward conmpatibility. used to be aa,bb not the format is aa:bb #when there is only one hostname specified in noderes.monserver, #both monserver and monmaster take the same hostname. - if ($pairs !~ /,/) { $pairs=$tmp2->{monserver}.','.$tmp2->{monserver}; } + if ($pairs !~ /:/) { $pairs=$tmp2->{monserver}.':'.$tmp2->{monserver}; } } if (!$pairs) { @@ -862,10 +866,14 @@ sub getNodeMonServerPair { if ($tmp2->{xcatmaster}) { $monmaster=$tmp2->{xcatmaster}; } if (!$monserver) { $monserver="noservicenode"; } if (!$monmaster) { $monmaster=xCAT::Utils->get_site_attribute('master'); } - $pairs="$monserver,$monmaster"; + $pairs="$monserver:$monmaster"; } #print "node=$node, pairs=$pairs\n"; + if ($monserver =~ /,/) { #monserver in noderes table must be defined in the service node pool case + return [1, "Please specify 'monserver' on the noderes table for the node $node because the service node pools are used."]; + } + if ($retformat) { if (exists($ret->{$pairs})) { my $pa=$ret->{$pairs}; @@ -896,6 +904,7 @@ sub getNodeMonServerPair { that faces the mn and the second one being the service node ip/hostname that faces the cn. The value of the first one can be "noservicenode" meaning that there is no service node for that node. In this case the second one is the site master. + It returns a pointer to an array if there is an error. Format is [code, message]. =cut #-------------------------------------------------------------------------------- sub getMonHierarchy { @@ -938,9 +947,10 @@ sub getMonHierarchy { if (defined($row2) && ($row2)) { if ($row2->{monserver}) { $pairs=$row2->{monserver}; + $pairs =~ s/,/:/; #for backward conmpatibility. used to be aa,bb not the format is aa:bb #when there is only one hostname specified in noderes.monserver, #both monserver and monmaster take the same hostname. - if ($pairs !~ /,/) { $pairs=$row2->{monserver}.','.$row2->{monserver}; } + if ($pairs !~ /:/) { $pairs=$row2->{monserver}.':'.$row2->{monserver}; } } } @@ -948,8 +958,12 @@ sub getMonHierarchy { if ($row2->{servicenode}) { $monserver=$row2->{servicenode}; } if ($row2->{xcatmaster}) { $monmaster=$row2->{xcatmaster}; } if (!$monserver) { $monserver="noservicenode"; } - if (!$monmaster) { $monmaster=$sitemaster; } - $pairs="$monserver,$monmaster"; + if(!$monmaster) { $monmaster=$sitemaster; } + $pairs="$monserver:$monmaster"; + } + + if ($monserver =~ /,/) { #monserver in noderes table must be defined in the service node pool case + return [1, "Please specify 'monserver' on the noderes table for the node $node because the service node pools are used."]; } #print "node=$node, pairs=$pairs\n"; @@ -984,10 +998,12 @@ sub getMonHierarchy { 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', 'alive'], ['node2', 'switch', 'booting']...], ...} - A key is a pair of hostnames with the first one being the service node ip/hostname + A key is pair of hostnames with the first one being the service node ip/hostname that faces the mn and the second one being the service node ip/hostname that faces the cn. The value of the first one can be "noservicenode" meaning that there is no service node for that node. In this case the second one is the site master. + It retuens a pointer to an array if there is an error. Format is [code, message]. + =cut #-------------------------------------------------------------------------------- sub getMonServerWithInfo { @@ -1009,6 +1025,8 @@ sub getMonServerWithInfo { my $tabdata=$table3->getNodesAttribs(\@allnodes,['nodetype']); my $pPairHash=getNodeMonServerPair(\@allnodes, 0); + if (ref($pPairHash) eq 'ARRAY') { return $pPairHash; } + foreach (@in_nodes) { my $node=$_->[0]; my $status=$_->[2]; @@ -1051,6 +1069,7 @@ sub getMonServerWithInfo { that faces the mn and the second one being the service node ip/hostname that faces the cn. The value of the first one can be "noservicenode" meaning that there is no service node for that node. In this case the second one is the site master. + It retuens a pointer to an array if there is an error. Format is [code, message]. =cut #-------------------------------------------------------------------------------- sub getMonServer { @@ -1061,6 +1080,10 @@ sub getMonServer { my @allnodes=@$p_input; my $pPairHash=getNodeMonServerPair(\@allnodes, 0); + + if (ref($pPairHash) eq 'ARRAY') { return $pPairHash; } + + if (@allnodes==0) { @allnodes= keys(%$pPairHash); } @@ -1302,7 +1325,7 @@ sub getNodeConfData { my %ret=(); #get monitoring server my $pHash=xCAT_monitoring::monitorctrl->getNodeMonServerPair([$node], 0); - my @pair_array=split(',', $pHash->{$node}); + my @pair_array=split(':', $pHash->{$node}); my $monserver=$pair_array[0]; if ($monserver eq 'noservicenode') { $monserver=hostname(); } $ret{MONSERVER}=$monserver; diff --git a/xCAT-server/lib/xcat/monitoring/pcpmon.pm b/xCAT-server/lib/xcat/monitoring/pcpmon.pm index e0de6546c..3b7731590 100644 --- a/xCAT-server/lib/xcat/monitoring/pcpmon.pm +++ b/xCAT-server/lib/xcat/monitoring/pcpmon.pm @@ -1,437 +1,422 @@ -#!/usr/bin/env perl -# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html -package xCAT_monitoring::pcpmon; -BEGIN -{ - $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; -} -use lib "$::XCATROOT/lib/perl"; -use xCAT::NodeRange; -use Sys::Hostname; -use Socket; -use xCAT::Utils; -use xCAT::GlobalDef; -use xCAT_monitoring::monitorctrl; -use xCAT::MsgUtils; -use strict; -use warnings; -1; - -#------------------------------------------------------------------------------- -=head1 xCAT_monitoring:pcpmon -=head2 Package Description - xCAT monitoring plugin package to handle PCP monitoring. -=cut -#------------------------------------------------------------------------------- - -#-------------------------------------------------------------------------------- -=head3 start - This function gets called by the monitorctrl module when xcatd starts and - when monstart command is issued by the user. It starts the daemons and - does necessary startup process for the PCP monitoring. - p_nodes -- a pointer to an arrays of nodes to be monitored. null means all. - scope -- the action scope, it indicates the node type the action will take place. - 0 means localhost only. - 2 means both localhost and nodes, - callback -- the callback pointer for error and status displaying. It can be null. - Returns: - (return code, message) - if the callback is set, use callback to display the status and error. -=cut - - -#-------------------------------------------------------------------------------- -sub start - { # starting sub routine - print "pcp::start called\n"; - my $noderef=shift; - if ($noderef =~ /xCAT_monitoring::pcpmon/) - { - $noderef=shift; - } - my $scope=shift; - print "scope is: $scope \n"; - my $callback=shift; - - my $cmd="$::XCATROOT/sbin/pcp_collect"; - #figure out the ping-intercal setting - my $value=5; #default - my %settings=xCAT_monitoring::monitorctrl->getPluginSettings("pcpmon"); - - my $reading=$settings{'ping-interval'}; - print "reading is $reading \n"; - if ($reading>0) { $value=$reading;} - - #create the cron job, it will run the command every 5 minutes(default and can be changed). - my $newentry; - if (xCAT::Utils->isAIX()) { - #AIX does not support */value format, have to list them all. - my $minutes; - if ($value==1) { $minutes='*';} - elsif ($value<=30) { - my @temp_a=(0..59); - foreach (@temp_a) { - if (($_ % $value) == 0) { $minutes .= "$_,";} - } - chop($minutes); - } else { - $minutes="0"; - } - $newentry="$minutes * * * * XCATROOT=$::XCATROOT PATH=$ENV{'PATH'} XCATCFG='$ENV{'XCATCFG'}' $cmd"; - } else { - $newentry="*/$value * * * * XCATROOT=$::XCATROOT PATH=$ENV{'PATH'} XCATCFG='$ENV{'XCATCFG'}' $cmd"; - } - my ($code, $msg)=xCAT::Utils::add_cron_job($newentry); - my $localhostname=hostname(); - if ($code==0) { - if ($callback) { - my $rsp={}; - $rsp->{data}->[0]="$localhostname: started. Refresh interval is $value minute(s)"; - $callback->($rsp); - } - #return (0, "started"); - } - else { - if ($callback) { - my $rsp={}; - $rsp->{data}->[0]="$localhostname: $code $msg"; - $callback->($rsp); - } - - #return ($code, $msg); - } - - my $localhost=hostname(); - print "local host is $localhost \n"; - print "starting pcp locally \n"; - my $res_pcp = `/etc/init.d/pcp restart 2>&1`; - print "res_pcp=$res_pcp\n"; - print "the result cp before is $? \n"; - if ($?) - { - print "pcp result after is $? \n"; - if ($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: PCP not started successfully: $res_pcp \n"; - $callback->($resp); - } - else - { - xCAT::MsgUtils->message('S', "[mon]: $res_pcp \n"); - } - - return(1,"PCP not started successfully. \n"); - } - - if ($scope) - { #opening if scope - print "opening scope \n"; - print "inside scope is:$scope"; - print "noderef is: @$noderef \n"; - my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); - print "pairhash: $pPairHash\n"; - #identification of this node - my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; - my $isSV=xCAT::Utils->isServiceNode(); - print "is sv is:$isSV \n"; - my %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - if (!$isSV) { $iphash{'noservicenode'}=1;} - - my @children; - foreach my $key (keys (%$pPairHash)) - { #opening foreach1 - print "opening foreach1 \n"; - print "key is: $key \n"; - my @key_a=split(',', $key); - print "a[0] is: $key_a[0] \n"; - print "a[1] is: $key_a[1] \n"; - if (! $iphash{$key_a[0]}) { next;} - my $mon_nodes=$pPairHash->{$key}; - - foreach(@$mon_nodes) - { #opening foreach2 - my $node=$_->[0]; - my $nodetype=$_->[1]; - print "node=$node, nodetype=$nodetype\n"; - if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) - { - push(@children,$node); - } - } #closing foreach2 - } #closing foreach1 - print "children:@children\n"; - my $rec = join(',',@children); - print "the string is $rec"; - print "XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/pcp restart 2>& \n"; - my $result=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/pcp restart 2>&1`; - if ($result) - { - if ($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: $result\n"; - $callback->($resp); - } - else - { - xCAT::MsgUtils->message('S', "[mon]: $result\n"); - } - } - - } #closing if scope - - if ($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: started. \n"; - $callback->($resp); - } - - return (0, "started"); - - } # closing sub routine -#-------------------------------------------------------------- -=head3 config - This function configures the cluster for the given nodes. This function is called - when moncfg command is issued or when xcatd starts on the service node. - Returns: 1 -=cut -#-------------------------------------------------------------- -sub config - { - return 1; - } - - -#-------------------------------------------------------------- -=head3 deconfig - This function de-configures the cluster for the given nodes. This function is called - when mondecfg command is issued by the user. - Returns: 1 -=cut -#-------------------------------------------------------------- -sub deconfig - { - return 1; - } - - -#-------------------------------------------------------------------------------- -=head3 stop - This function gets called by the monitorctrl module when - xcatd stops or when monstop command is issued by the user. - It stops the monitoring on all nodes, stops - the daemons and does necessary cleanup process for the - PCP monitoring. - Arguments: - p_nodes -- a pointer to an arrays of nodes to be stoped for monitoring. null means all. - scope -- the action scope, it indicates the node type the action will take place. - 0 means localhost only. - 2 means both monservers and nodes, - callback -- the callback pointer for error and status displaying. It can be null. - Returns: - (return code, message) - if the callback is set, use callback to display the status and error. -=cut - - -#-------------------------------------------------------------------------------- -sub stop - { # starting sub routine - print "pcpmon::stop called\n"; - my $noderef=shift; - if ($noderef =~ /xCAT_monitoring::pcpmon/) - { - $noderef=shift; - } - my $scope=shift; - my $callback=shift; - - my $job="$::XCATROOT/sbin/pcp_collect"; - my ($code, $msg)=xCAT::Utils::remove_cron_job($job); - my $localhostname=hostname(); - if ($code==0) { - if ($callback) { - my $rsp={}; - $rsp->{data}->[0]="$localhostname: stopped."; - $callback->($rsp); - } - #return (0, "stopped"); - } - else { - if ($callback) { - my $rsp={}; - $rsp->{data}->[0]="$localhostname: $code $msg"; - $callback->($rsp); - } - #return ($code, $msg); - } - - - my $localhost=hostname(); - print "local host is $localhost \n"; - print "stopping pcp locally \n"; - my $res_pcp = `/etc/init.d/pcp stop 2>&1`; - print "res_pcp=$res_pcp\n"; - print "the result pcp before is $? \n"; - if ($?) - { - print "pcp result after is $? \n"; - if ($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: PCP not stopped successfully: $res_pcp \n"; - $callback->($resp); - } - else - { - xCAT::MsgUtils->message('S', "[mon]: $res_pcp \n"); - } - - return(1,"PCP not stopped successfully. \n"); - } - - - if ($scope) - { #opening if scope - print "opening scope \n"; - print "noderef is: @$noderef \n"; - my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); - print "pairhash: $pPairHash\n"; - #identification of this node - my @hostinfo=xCAT::Utils->determinehostname(); - print "host:@hostinfo\n"; - my $isSV=xCAT::Utils->isServiceNode(); - print "is sv is:$isSV \n"; - my %iphash=(); - foreach(@hostinfo) {$iphash{$_}=1;} - if (!$isSV) { $iphash{'noservicenode'}=1;} - - my @children; - foreach my $key (keys (%$pPairHash)) - { #opening foreach1 - print "opening foreach1 \n"; - print "key is: $key \n"; - my @key_a=split(',', $key); - print "a[1] is: $key_a[1] \n"; - if (! $iphash{$key_a[0]}) { next;} - my $mon_nodes=$pPairHash->{$key}; - - foreach(@$mon_nodes) - { #opening foreach2 - my $node=$_->[0]; - my $nodetype=$_->[1]; - print "node=$node, nodetype=$nodetype\n"; - if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) - { - push(@children,$node); - } - } #closing foreach2 - } #closing foreach1 - print "children:@children\n"; - my $rec = join(',',@children); - print "the string is $rec"; - print "XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/pcp stop 2>& \n"; - my $result=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/pcp stop 2>&1`; - if ($result) - { - if ($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: $result\n"; - $callback->($resp); - } - else - { - xCAT::MsgUtils->message('S', "[mon]: $result\n"); - } - } - - } #closing if scope - - if ($callback) - { - my $resp={}; - $resp->{data}->[0]="$localhost: stopped. \n"; - $callback->($resp); - } - - return (0, "stopped"); - } - - -#-------------------------------------------------------------------------------- -=head3 supportNodeStatusMon - This function is called by the monitorctrl module to check - if PCP can help monitoring and returning the node status. - - Arguments: - none - Returns: - 1 -=cut - -#-------------------------------------------------------------------------------- -sub supportNodeStatusMon { - #print "pcpmon::supportNodeStatusMon called\n"; - return 1; -} - - - -#-------------------------------------------------------------------------------- -=head3 startNodeStatusMon - This function is called by the monitorctrl module to tell - PCP to start monitoring the node status and feed them back - to xCAT. PCP will start setting up the condition/response - to monitor the node status changes. - - Arguments: - None. - Returns: - (return code, message) - -=cut -#-------------------------------------------------------------------------------- -sub startNodeStatusMon { - #print "pcpmon::startNodeStatusMon called\n"; - return (0, "started"); -} - - -#-------------------------------------------------------------------------------- -=head3 stopNodeStatusMon - This function is called by the monitorctrl module to tell - PCP to stop feeding the node status info back to xCAT. It will - stop the condition/response that is monitoring the node status. - - Arguments: - none - Returns: - (return code, message) -=cut -#-------------------------------------------------------------------------------- -sub stopNodeStatusMon { - #print "pcpmon::stopNodeStatusMon called\n"; - return (0, "stopped"); -} - -#-------------------------------------------------------------------------------- -=head3 getDiscription - This function returns the detailed description of the plugin inluding the - valid values for its settings in the monsetting tabel. - Arguments: - none - Returns: - The description. -=cut -#-------------------------------------------------------------------------------- -sub getDescription -{ - return "Description: This plugin will help interface the xCAT cluster with PCP monitoring software - ping-interval: the number of minutes between the metric collection operation. - The default value is 5 \n "; -} +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +package xCAT_monitoring::pcpmon; +BEGIN +{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; +} +use lib "$::XCATROOT/lib/perl"; +use xCAT::NodeRange; +use Sys::Hostname; +use Socket; +use xCAT::Utils; +use xCAT::GlobalDef; +use xCAT_monitoring::monitorctrl; +use xCAT::MsgUtils; +use strict; +use warnings; +1; + +#------------------------------------------------------------------------------- +=head1 xCAT_monitoring:pcpmon +=head2 Package Description + xCAT monitoring plugin package to handle PCP monitoring. +=cut +#------------------------------------------------------------------------------- + +#-------------------------------------------------------------------------------- +=head3 start + This function gets called by the monitorctrl module when xcatd starts and + when monstart command is issued by the user. It starts the daemons and + does necessary startup process for the PCP monitoring. + p_nodes -- a pointer to an arrays of nodes to be monitored. null means all. + scope -- the action scope, it indicates the node type the action will take place. + 0 means localhost only. + 2 means both localhost and nodes, + callback -- the callback pointer for error and status displaying. It can be null. + Returns: + (return code, message) + if the callback is set, use callback to display the status and error. +=cut + + +#-------------------------------------------------------------------------------- +sub start +{ # starting sub routine + print "pcp::start called\n"; + my $noderef=shift; + if ($noderef =~ /xCAT_monitoring::pcpmon/) + { + $noderef=shift; + } + my $scope=shift; + my $callback=shift; + + my $cmd="$::XCATROOT/sbin/pcp_collect"; + #figure out the ping-intercal setting + my $value=5; #default + my %settings=xCAT_monitoring::monitorctrl->getPluginSettings("pcpmon"); + + my $reading=$settings{'ping-interval'}; + if ($reading>0) { $value=$reading;} + + #create the cron job, it will run the command every 5 minutes(default and can be changed). + my $newentry; + if (xCAT::Utils->isAIX()) { + #AIX does not support */value format, have to list them all. + my $minutes; + if ($value==1) { $minutes='*';} + elsif ($value<=30) { + my @temp_a=(0..59); + foreach (@temp_a) { + if (($_ % $value) == 0) { $minutes .= "$_,";} + } + chop($minutes); + } else { + $minutes="0"; + } + $newentry="$minutes * * * * XCATROOT=$::XCATROOT PATH=$ENV{'PATH'} XCATCFG='$ENV{'XCATCFG'}' $cmd"; + } else { + $newentry="*/$value * * * * XCATROOT=$::XCATROOT PATH=$ENV{'PATH'} XCATCFG='$ENV{'XCATCFG'}' $cmd"; + } + my ($code, $msg)=xCAT::Utils::add_cron_job($newentry); + my $localhostname=hostname(); + if ($code==0) { + if ($callback) { + my $rsp={}; + $rsp->{data}->[0]="$localhostname: started. Refresh interval is $value minute(s)"; + $callback->($rsp); + } + #return (0, "started"); + } + else { + if ($callback) { + my $rsp={}; + $rsp->{data}->[0]="$localhostname: $code $msg"; + $callback->($rsp); + } + + #return ($code, $msg); + } + + my $localhost=hostname(); + my $res_pcp = `/etc/init.d/pcp restart 2>&1`; + if ($?) + { + if ($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: PCP not started successfully: $res_pcp \n"; + $callback->($resp); + } + else + { + xCAT::MsgUtils->message('S', "[mon]: $res_pcp \n"); + } + + return(1,"PCP not started successfully. \n"); + } + + if ($scope) + { #opening if scope + my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } + + #identification of this node + my @hostinfo=xCAT::Utils->determinehostname(); + my $isSV=xCAT::Utils->isServiceNode(); + my %iphash=(); + foreach(@hostinfo) {$iphash{$_}=1;} + if (!$isSV) { $iphash{'noservicenode'}=1;} + + my @children; + foreach my $key (keys (%$pPairHash)) + { #opening foreach1 + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } + my $mon_nodes=$pPairHash->{$key}; + + foreach(@$mon_nodes) + { #opening foreach2 + my $node=$_->[0]; + my $nodetype=$_->[1]; + if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) + { + push(@children,$node); + } + } #closing foreach2 + } #closing foreach1 + my $rec = join(',',@children); + my $result=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/pcp restart 2>&1`; + if ($result) + { + if ($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: $result\n"; + $callback->($resp); + } + else + { + xCAT::MsgUtils->message('S', "[mon]: $result\n"); + } + } + + } #closing if scope + + if ($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: started. \n"; + $callback->($resp); + } + + return (0, "started"); + +} # closing sub routine +#-------------------------------------------------------------- +=head3 config + This function configures the cluster for the given nodes. This function is called + when moncfg command is issued or when xcatd starts on the service node. + Returns: 1 +=cut +#-------------------------------------------------------------- +sub config + { + return 1; + } + + +#-------------------------------------------------------------- +=head3 deconfig + This function de-configures the cluster for the given nodes. This function is called + when mondecfg command is issued by the user. + Returns: 1 +=cut +#-------------------------------------------------------------- +sub deconfig + { + return 1; + } + + +#-------------------------------------------------------------------------------- +=head3 stop + This function gets called by the monitorctrl module when + xcatd stops or when monstop command is issued by the user. + It stops the monitoring on all nodes, stops + the daemons and does necessary cleanup process for the + PCP monitoring. + Arguments: + p_nodes -- a pointer to an arrays of nodes to be stoped for monitoring. null means all. + scope -- the action scope, it indicates the node type the action will take place. + 0 means localhost only. + 2 means both monservers and nodes, + callback -- the callback pointer for error and status displaying. It can be null. + Returns: + (return code, message) + if the callback is set, use callback to display the status and error. +=cut + + +#-------------------------------------------------------------------------------- +sub stop + { # starting sub routine + print "pcpmon::stop called\n"; + my $noderef=shift; + if ($noderef =~ /xCAT_monitoring::pcpmon/) + { + $noderef=shift; + } + my $scope=shift; + my $callback=shift; + + my $job="$::XCATROOT/sbin/pcp_collect"; + my ($code, $msg)=xCAT::Utils::remove_cron_job($job); + my $localhostname=hostname(); + if ($code==0) { + if ($callback) { + my $rsp={}; + $rsp->{data}->[0]="$localhostname: stopped."; + $callback->($rsp); + } + #return (0, "stopped"); + } + else { + if ($callback) { + my $rsp={}; + $rsp->{data}->[0]="$localhostname: $code $msg"; + $callback->($rsp); + } + #return ($code, $msg); + } + + + my $localhost=hostname(); + my $res_pcp = `/etc/init.d/pcp stop 2>&1`; + if ($?) + { + if ($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: PCP not stopped successfully: $res_pcp \n"; + $callback->($resp); + } + else + { + xCAT::MsgUtils->message('S', "[mon]: $res_pcp \n"); + } + + return(1,"PCP not stopped successfully. \n"); + } + + + if ($scope) + { #opening if scope + my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } + + + #identification of this node + my @hostinfo=xCAT::Utils->determinehostname(); + my $isSV=xCAT::Utils->isServiceNode(); + my %iphash=(); + foreach(@hostinfo) {$iphash{$_}=1;} + if (!$isSV) { $iphash{'noservicenode'}=1;} + + my @children; + foreach my $key (keys (%$pPairHash)) + { #opening foreach1 + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } + my $mon_nodes=$pPairHash->{$key}; + + foreach(@$mon_nodes) + { #opening foreach2 + my $node=$_->[0]; + my $nodetype=$_->[1]; + if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/)) + { + push(@children,$node); + } + } #closing foreach2 + } #closing foreach1 + my $rec = join(',',@children); + my $result=`XCATBYPASS=Y $::XCATROOT/bin/xdsh $rec /etc/init.d/pcp stop 2>&1`; + if ($result) + { + if ($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: $result\n"; + $callback->($resp); + } + else + { + xCAT::MsgUtils->message('S', "[mon]: $result\n"); + } + } + + } #closing if scope + + if ($callback) + { + my $resp={}; + $resp->{data}->[0]="$localhost: stopped. \n"; + $callback->($resp); + } + + return (0, "stopped"); + } + + +#-------------------------------------------------------------------------------- +=head3 supportNodeStatusMon + This function is called by the monitorctrl module to check + if PCP can help monitoring and returning the node status. + + Arguments: + none + Returns: + 1 +=cut + +#-------------------------------------------------------------------------------- +sub supportNodeStatusMon { + #print "pcpmon::supportNodeStatusMon called\n"; + return 1; +} + + + +#-------------------------------------------------------------------------------- +=head3 startNodeStatusMon + This function is called by the monitorctrl module to tell + PCP to start monitoring the node status and feed them back + to xCAT. PCP will start setting up the condition/response + to monitor the node status changes. + + Arguments: + None. + Returns: + (return code, message) + +=cut +#-------------------------------------------------------------------------------- +sub startNodeStatusMon { + #print "pcpmon::startNodeStatusMon called\n"; + return (0, "started"); +} + + +#-------------------------------------------------------------------------------- +=head3 stopNodeStatusMon + This function is called by the monitorctrl module to tell + PCP to stop feeding the node status info back to xCAT. It will + stop the condition/response that is monitoring the node status. + + Arguments: + none + Returns: + (return code, message) +=cut +#-------------------------------------------------------------------------------- +sub stopNodeStatusMon { + #print "pcpmon::stopNodeStatusMon called\n"; + return (0, "stopped"); +} + +#-------------------------------------------------------------------------------- +=head3 getDiscription + This function returns the detailed description of the plugin inluding the + valid values for its settings in the monsetting tabel. + Arguments: + none + Returns: + The description. +=cut +#-------------------------------------------------------------------------------- +sub getDescription +{ + return "Description: This plugin will help interface the xCAT cluster with PCP monitoring software + ping-interval: the number of minutes between the metric collection operation. + The default value is 5 \n "; +} diff --git a/xCAT-server/lib/xcat/monitoring/samples/templatemon.pm b/xCAT-server/lib/xcat/monitoring/samples/templatemon.pm index b2ba93e9c..2c6dc1d67 100644 --- a/xCAT-server/lib/xcat/monitoring/samples/templatemon.pm +++ b/xCAT-server/lib/xcat/monitoring/samples/templatemon.pm @@ -9,6 +9,7 @@ BEGIN use lib "$::XCATROOT/lib/perl"; use strict; use xCAT_monitoring::monitorctrl; +use xCAT::Utils; 1; #------------------------------------------------------------------------------- @@ -101,12 +102,22 @@ sub start { foreach(@hostinfo) {$iphash{$_}=1;} if (!$isSV) { $iphash{'noservicenode'}=1;} my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } foreach my $key (keys(%$pPairHash)) { - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} - + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } my $mon_nodes=$pPairHash->{$key}; + foreach(@$mon_nodes) { my $node_info=$_; print " node=$node_info->[0], nodetype=$node_info->[1], status=$node_info->[2]\n"; @@ -159,12 +170,22 @@ sub stop { foreach(@hostinfo) {$iphash{$_}=1;} if (!$isSV) { $iphash{'noservicenode'}=1;} my $pPairHash=xCAT_monitoring::monitorctrl->getMonServer($noderef); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $resp={}; + $resp->{data}->[0]=$pPairHash->[1]; + $callback->($resp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (1, ""); + } foreach my $key (keys(%$pPairHash)) { - my @key_a=split(',', $key); - if (! $iphash{$key_a[0]}) { next;} - + my @key_a=split(':', $key); + if (! $iphash{$key_a[0]}) { next; } my $mon_nodes=$pPairHash->{$key}; + foreach(@$mon_nodes) { my $node_info=$_; print " node=$node_info->[0], nodetype=$node_info->[1], status=$node_info->[2]\n"; @@ -373,6 +394,7 @@ sub getDescription { node ip/hostname that faces the cn. The value of the first one can be "noservicenode" meaning that there is no service node for that node. In this case the second one is the site master. + It returns a pointer to an array if there is an error. Format is [code, message]. =cut #-------------------------------------------------------------------------------- sub getNodesMonServers diff --git a/xCAT-server/lib/xcat/monitoring/snmpmon.pm b/xCAT-server/lib/xcat/monitoring/snmpmon.pm index 934527165..a2736938b 100644 --- a/xCAT-server/lib/xcat/monitoring/snmpmon.pm +++ b/xCAT-server/lib/xcat/monitoring/snmpmon.pm @@ -368,6 +368,19 @@ sub configBMC { if (!$isSV) { $iphash{'noservicenode'}=1;} my $pPairHash=xCAT_monitoring::monitorctrl->getNodeMonServerPair($noderef, 0); + if (ref($pPairHash) eq 'ARRAY') { + if ($callback) { + my $rsp={}; + if ($ret_val) { + $rsp->{data}->[0]=$pPairHash->[1]; + } + $callback->($rsp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pPairHash->[1]); + } + return (0, ""); + } + my %masterhash=(); my @node_a=(); @@ -381,7 +394,7 @@ sub configBMC { if (! exists($pPairHash->{$node})) {next;} my $pairs=$pPairHash->{$node}; - my @a_temp=split(',',$pairs); + my @a_temp=split(':',$pairs); my $monserver=$a_temp[0]; my $master=$a_temp[1]; @@ -510,8 +523,21 @@ sub configMPA { $mpa_hash{$mpa}=1; my $pHash=xCAT_monitoring::monitorctrl->getNodeMonServerPair([$mpa], 0); + if (ref($pHash) eq 'ARRAY') { + if ($callback) { + my $rsp={}; + if ($ret_val) { + $rsp->{data}->[0]=$pHash->[1]; + } + $callback->($rsp); + } else { + xCAT::MsgUtils->message('S', "[mon]: " . $pHash->[1]); + } + return (0, ""); + } + my $pairs=$pHash->{$mpa}; - my @a_temp=split(',',$pairs); + my @a_temp=split(':',$pairs); my $monserver=$a_temp[0]; my $master=$a_temp[1]; @@ -791,6 +817,7 @@ sub getDescription { node ip/hostname that faces the cn. The value of the first one can be "noservicenode" meaning that there is no service node for that node. In this case the second one is the site master. + It retuens a pointer to an array if there is an error. Format is [code, message]. =cut #-------------------------------------------------------------------------------- sub getNodesMonServers @@ -806,6 +833,11 @@ sub getNodesMonServers my $localhostname=hostname(); my $pPairHash=xCAT_monitoring::monitorctrl->getNodeMonServerPair($noderef, 0); + if (ref($pPairHash) eq 'ARRAY') { + return $pPairHash; + } + + #check for blades, only returns the MPAs and their monservers my %mpa_hash=(); my $table=xCAT::Table->new("mp"); @@ -827,6 +859,10 @@ sub getNodesMonServers $pairs=$pPairHash->{$mpa}; } else { my $pHash=xCAT_monitoring::monitorctrl->getNodeMonServerPair([$mpa], 0); + if (ref($pHash) eq 'ARRAY') { + return $pHash; + } + $pairs=$pHash->{$mpa}; } diff --git a/xCAT-server/lib/xcat/monitoring/xcatmon.pm b/xCAT-server/lib/xcat/monitoring/xcatmon.pm index cd33dea19..60ed67808 100644 --- a/xCAT-server/lib/xcat/monitoring/xcatmon.pm +++ b/xCAT-server/lib/xcat/monitoring/xcatmon.pm @@ -283,6 +283,12 @@ sub getMonNodesStatus { my @unknown_nodes=(); my $hierachy=xCAT_monitoring::monitorctrl->getMonHierarchy(); + if (ref($hierachy) eq 'ARRAY') { + xCAT::MsgUtils->message('S', "[mon]: " . $hierachy->[1]); + return %status; + } + + my @mon_servers=keys(%$hierachy); my $isSV=xCAT::Utils->isServiceNode(); diff --git a/xCAT-server/lib/xcat/plugins/monctrlcmds.pm b/xCAT-server/lib/xcat/plugins/monctrlcmds.pm index 91798a364..4d4640f17 100644 --- a/xCAT-server/lib/xcat/plugins/monctrlcmds.pm +++ b/xCAT-server/lib/xcat/plugins/monctrlcmds.pm @@ -97,7 +97,16 @@ sub preprocess_request } else { $mon_hierachy=xCAT_monitoring::monitorctrl->getNodeMonServerPair($allnodes, 1); } + + if (ref($mon_hierachy) eq 'ARRAY') { + my $rsp2={}; + $rsp2->{data}->[0]=$mon_hierachy->[1]; + $callback->($rsp2); + $req = {}; + return; + } + my @mon_servers=keys(%$mon_hierachy); my @hostinfo=xCAT::Utils->determinehostname(); #print "hostinfo=@hostinfo\n"; @@ -109,7 +118,7 @@ sub preprocess_request foreach (@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(':', $_); my $sv=$server_pair[0]; my $mon_nodes=$mon_hierachy->{$_}; if ((!$mon_nodes) || (@$mon_nodes ==0)) { next; } @@ -117,12 +126,11 @@ sub preprocess_request my $reqcopy = {%$req}; if (! $iphash{$sv}) { - if ($isSV) { next; } #if the command is issued on the monserver, - # only handle its children. - $reqcopy->{'_xcatdest'}=$sv; - my $rsp2={}; - $rsp2->{data}->[0]="sending request to $sv..."; - $callback->($rsp2); + if ($isSV) { next; } #if the command is issued on the monserver, only handle its children. + $reqcopy->{'_xcatdest'}=$sv; + my $rsp2={}; + $rsp2->{data}->[0]="sending request to $sv..."; + $callback->($rsp2); } push @{$reqcopy->{module}}, $a_ret[1];