From 0cec3a60d6893b8e8fe5596c38fc243b6dd067d8 Mon Sep 17 00:00:00 2001 From: phamt Date: Wed, 6 Jun 2012 14:52:35 +0000 Subject: [PATCH] Fixed bug in Ganglia to always update gmetad.conf when moncfg gangliamon -r is run. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13014 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/monitoring/gangliamon.pm | 145 ++++++++---------- 1 file changed, 66 insertions(+), 79 deletions(-) diff --git a/xCAT-server/lib/xcat/monitoring/gangliamon.pm b/xCAT-server/lib/xcat/monitoring/gangliamon.pm index 1602a2af2..c6eb7c2df 100755 --- a/xCAT-server/lib/xcat/monitoring/gangliamon.pm +++ b/xCAT-server/lib/xcat/monitoring/gangliamon.pm @@ -458,110 +458,97 @@ sub confGmetad { chomp( my $hostname = `hostname` ); - #version 3.1.0 + # version 3.1.0 if ( -e "/etc/ganglia/gmetad.conf" ) { $configure_file = '/etc/ganglia/gmetad.conf'; } - #version 3.0.7 + # version 3.0.7 elsif ( -e "/etc/gmetad.conf" ) { $configure_file = '/etc/gmetad.conf'; } - #non should install + # mon should be installed else { return; } + + # Backup the original file + `/bin/cp -f $configure_file $configure_file.orig`; - my $tmp = `/bin/grep "xCAT gmetad settings done" $configure_file`; - if (!$tmp) { #openinf if ? + # Create new file from scratch + `/bin/rm -f $configure_file`; + `/bin/touch $configure_file`; + + open( OUTFILE, "+>>$configure_file" ) + or die("Cannot open file \n"); + print( OUTFILE "# Setting up GMETAD configuration file \n" ); + + if ( -e "/etc/xCATMN" ) { + print( OUTFILE "data_source \"$hostname\" localhost \n" ); + } + + my $noderef = xCAT_monitoring::monitorctrl->getMonHierarchy(); + if ( ref($noderef) eq 'ARRAY' ) { if ($callback) { my $resp = {}; - $resp->{data}->[0] = "$localhost: $tmp"; + $resp->{data}->[0] = $noderef->[1]; $callback->($resp); + } else { + xCAT::MsgUtils->message( 'S', "[mon]: " . $noderef->[1] ); } - else { - xCAT::MsgUtils->message( 'S', "Gmetad not configured $tmp\n" ); + return ( 1, "" ); + } + + my @hostinfo = xCAT::Utils->determinehostname(); + my $isSV = xCAT::Utils->isServiceNode(); + my %iphash = (); + foreach (@hostinfo) { $iphash{$_} = 1; } + if ( !$isSV ) { + $iphash{'noservicenode'} = 1; + } + + my @children; + my $cluster; + foreach my $key ( keys(%$noderef) ) { + my @key_g = split( ':', $key ); + if ( !$iphash{ $key_g[0] } ) { + next; } - # Backup the original file - `/bin/cp -f $configure_file $configure_file.orig`; - - # Create new file from scratch - `/bin/rm -f $configure_file`; - `/bin/touch $configure_file`; - - open( OUTFILE, "+>>$configure_file" ) - or die("Cannot open file \n"); - print( OUTFILE "# Setting up GMETAD configuration file \n" ); - - if ( -e "/etc/xCATMN" ) { - print( OUTFILE "data_source \"$hostname\" localhost \n" ); + my $mon_nodes = $noderef->{$key}; + 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]; } - my $noderef = xCAT_monitoring::monitorctrl->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(); - my $isSV = xCAT::Utils->isServiceNode(); - my %iphash = (); - foreach (@hostinfo) { $iphash{$_} = 1; } - if ( !$isSV ) { - $iphash{'noservicenode'} = 1; - } - - my @children; - my $cluster; - foreach my $key ( keys(%$noderef) ) { - my @key_g = split( ':', $key ); - if ( !$iphash{ $key_g[0] } ) { - next; - } - - my $mon_nodes = $noderef->{$key}; - 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]; - } - - foreach (@$mon_nodes) { - my $node = $_->[0]; - my $nodetype = $_->[1]; - if ( ($nodetype) && ( $nodetype =~ /$::NODETYPE_OSI/ ) ) { - push( @children, $node ); - } + foreach (@$mon_nodes) { + my $node = $_->[0]; + my $nodetype = $_->[1]; + if ( ($nodetype) && ( $nodetype =~ /$::NODETYPE_OSI/ ) ) { + push( @children, $node ); } } + } - my $num = @children; - if ( -e "/etc/xCATSN" ) { - print( OUTFILE "gridname \"$cluster\"\n" ); - print( OUTFILE "data_source \"$cluster\" localhost\n" ); - my $master = xCAT::Utils->get_site_Master(); - print( OUTFILE "trusted_hosts $master\n" ); - } - else { - for ( my $j = 0 ; $j < $num ; $j++ ) { - print( OUTFILE - "data_source \"$children[ $j ]\" $children[ $j ]:8651 \n" - ); - } + my $num = @children; + if ( -e "/etc/xCATSN" ) { + print( OUTFILE "gridname \"$cluster\"\n" ); + print( OUTFILE "data_source \"$cluster\" localhost\n" ); + my $master = xCAT::Utils->get_site_Master(); + print( OUTFILE "trusted_hosts $master\n" ); + } + else { + for ( my $j = 0 ; $j < $num ; $j++ ) { + print( OUTFILE + "data_source \"$children[ $j ]\" $children[ $j ]:8651 \n" + ); } + } - print( OUTFILE "# xCAT gmetad settings done \n" ); - close(OUTFILE); - } #closing if? + print( OUTFILE "# xCAT gmetad settings done \n" ); + close(OUTFILE); } # closing subrouting #--------------------------------------------------------------