From 34c19ca896e62f27f46421dfc40f3981002d0cb3 Mon Sep 17 00:00:00 2001 From: linggao Date: Wed, 25 Jun 2008 02:16:26 +0000 Subject: [PATCH] Put monitoring conf data for nodes in Postage.pm git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1756 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Postage.pm | 7 +++ xCAT-rmc/plugin/rmcmon.pm | 56 +++++++++++++++++++ .../lib/xcat/monitoring/monitorctrl.pm | 55 +++++++++++++++++- 3 files changed, 115 insertions(+), 3 deletions(-) diff --git a/perl-xCAT/xCAT/Postage.pm b/perl-xCAT/xCAT/Postage.pm index 55e316ccd..257d7de80 100644 --- a/perl-xCAT/xCAT/Postage.pm +++ b/perl-xCAT/xCAT/Postage.pm @@ -191,6 +191,13 @@ sub makescript { } push @scriptd, "export NTYPE\n"; + #get monitoring server and other configuration data for monitoring setup on nodes + my %mon_conf=xCAT_monitoring::monitorctrl->getNodeConfData($node); + foreach (keys(%mon_conf)) { + push @scriptd, "$_=" . $mon_conf{$_}. "\n"; + push @scriptd, "export $_\n"; + } + # get the xcatdefaults entry in the postscripts table my $et = $posttab->getAttribs({node=>"xcatdefaults"},'postscripts'); my $defscripts = $et->{'postscripts'}; diff --git a/xCAT-rmc/plugin/rmcmon.pm b/xCAT-rmc/plugin/rmcmon.pm index 1ebd3322a..d41916c29 100644 --- a/xCAT-rmc/plugin/rmcmon.pm +++ b/xCAT-rmc/plugin/rmcmon.pm @@ -451,6 +451,26 @@ sub getNodeID { return undef; } +#-------------------------------------------------------------------------------- +=head3 getLocalNodeID + This function goes to RMC and gets the nodeid for the local host. + + Arguments: + node + Returns: + node id for the local host. +=cut +#-------------------------------------------------------------------------------- +sub getLocalNodeID { + my $node_id=`/usr/sbin/rsct/bin/lsnodeid`; + if ($?==0) { + chomp($node_id); + return $node_id; + } else { + return undef; + } +} + #-------------------------------------------------------------------------------- =head3 addNodes This function adds the nodes into the RMC cluster. @@ -704,3 +724,39 @@ sub getDescription { none.\n"; } +#-------------------------------------------------------------------------------- +=head3 getNodeConfData + This function gets a list of configuration data that is needed by setting up + node monitoring. These data-value pairs will be used as environmental variables + on the given node. + Arguments: + node + pointer to a hash that will take the data. + Returns: + none +=cut +#-------------------------------------------------------------------------------- +sub getNodeConfData { + #check if rsct is installed or not + if (! -e "/usr/bin/lsrsrc") { + return; + } + + my $node=shift; + if ($node =~ /xCAT_monitoring::rmcmon/) { + $node=shift; + } + my $ref_ret=shift; + + #get node ids for RMC monitoring + my $nodeid=xCAT_monitoring::rmcmon->getNodeID($node); + if (defined($nodeid)) { + $ref_ret->{NODEID}=$nodeid; + } + my $ms_nodeid=xCAT_monitoring::rmcmon->getLocalNodeID(); + if (defined($ms_nodeid)) { + $ref_ret->{MS_NODEID}=$ms_nodeid; + } + return; +} + diff --git a/xCAT-server/lib/xcat/monitoring/monitorctrl.pm b/xCAT-server/lib/xcat/monitoring/monitorctrl.pm index fceae58a1..4536203a2 100644 --- a/xCAT-server/lib/xcat/monitoring/monitorctrl.pm +++ b/xCAT-server/lib/xcat/monitoring/monitorctrl.pm @@ -15,6 +15,7 @@ use xCAT::Client; use xCAT_plugin::notification; use xCAT_monitoring::montbhandler; + #the list stores the names of the monitoring plug-in and the file name and module names. #the names are stored in the "name" column of the monitoring table. #the format is: (name=>[filename, modulename], ...) @@ -1227,9 +1228,57 @@ sub removeNodes { } - - - +#-------------------------------------------------------------------------------- +=head3 getNodeConfData + This function goes to every monitoring plug-in module and returns a list of + configuration data that is needed by setting up node monitoring. + These data-value pairs will be used as environmental variables + on the given node. + Arguments: + node + Returns: + ret a hash with enviromental variable name as the key. +=cut +#-------------------------------------------------------------------------------- +sub getNodeConfData { + my $node=shift; + if ($node =~ /xCAT_monitoring::monitorctrl/) { + $node=shift; + } + + %ret=(); + #get monitoring server + my $pair=xCAT_monitoring::monitorctrl->getNodeMonServerPair($node); + my @pair_array=split(',', $pair); + my $monserver=$pair_array[1]; + $ret{MONSERVER}=$monserver; + + #get all the module names from /opt/xcat/lib/perl/XCAT_monitoring directory + my %names=(); + my @plugins=glob("$::XCATROOT/lib/perl/xCAT_monitoring/*.pm"); + foreach (@plugins) { + /.*\/([^\/]*).pm$/; + $names{$1}=1; + } + # remove 2 files that are not plug-ins + delete($names{monitorctrl}); + delete($names{montbhandler}); + + #get node conf data from each plug-in module + foreach my $pname (keys(%names)) { + my $file_name="$::XCATROOT/lib/perl/xCAT_monitoring/$pname.pm"; + my $module_name="xCAT_monitoring::$pname"; + #load the module in memory + eval {require($file_name)}; + if (!$@) { + if (defined(${$module_name."::"}{getNodeConfData})) { + ${$module_name."::"}{getNodeConfData}->($node, \%ret); + } + } + } + + return %ret; +}