Hey Chris,

I had another request for such a feature, so I looked at your patch more
closely.  I modified it into the attached patch for the newer
ganglia_ipmi_sensors.pl script.  Will it suit your needs?  The primary
thing I changed in the patch was to not pass a full regex to the script,
only the search/replace expressions within a regex.  We decided having a
user be able to pass an arbitrary string into an eval() was not a good
idea :-)

Yaroslav, will it suit your needs too?

Both patch & script are attached.

Al

P.S.  I haven't committed these anywhere.

On Sat, 2011-01-01 at 20:01 -0800, Christopher Maestas wrote:
> Hi Al,
> 
> 
> I'll try to work on back porting this against that code base sometime
> next week if that's OK.
> 
> 
> Thanks,
> -cdm
> 
> On Mon, Dec 27, 2010 at 10:46 AM, Al Chu <[email protected]> wrote:
>         Hey Chris,
>         
>         Patch for the most part looks fine.  With the FreeIPMI 1.0.0
>         beta
>         already out, why don't we aim this patch for the new Ganglia
>         ipmi
>         sensors perl script that will be released along with it.
>         (ipmimonitoring has been deprecated for a new
>         --output-event-state
>         option in ipmi-sensors).
>         
>         Would you like to do the forward port, or should I?
>         
>         Al
>         
>         
>         On Tue, 2010-12-21 at 21:35 -0800, Christopher Maestas wrote:
>         > Here's a stab at adding a -e flag that lets you run a perl
>         regex
>         > against the hostname.  Then you can run:
>         >
>         >
>         > ./ganglia_ipmimonitoring.pl -e 's/^mp-//g' -h mp-cn[1-4] -D
>         -d
>         >
>         >
>         > I'm sure it could be cleaned up further or restricted to
>         only
>         > doing/checking for search and replace expressions.
>         >
>         >
>         > -cdm
>         >
>         > On Tue, Dec 21, 2010 at 2:20 PM, Al Chu <[email protected]>
>         wrote:
>         >         Hi Chris,
>         >
>         >         Hmmm.  I'm not really sure how we could/should do
>         that.
>         >          Perhaps some
>         >         other option would tell the script to create/remove
>         the prefix
>         >         before
>         >         passing it up to ganglia?
>         >
>         >         Al
>         >
>         >
>         >         On Tue, 2010-12-21 at 10:52 -0800, Christopher
>         Maestas wrote:
>         >         > Any thought given to translating the hostlist from
>         the
>         >         management
>         >         > processor name to a real device name?  For
>         example:
>         >         >       * device name is mp-cn[1-2] and hostname is
>         cn[1-2]
>         >         >
>         >         >
>         >         > ./ganglia_ipmimonitoring.pl -D -d -h mp-cn[1-2] |
>         sed -e
>         >         's/mp-//g'
>         >         >
>         >         >
>         >         > but I don't think that will do what I want ...
>         >
>         >         --
>         >         Albert Chu
>         >         [email protected]
>         >         Computer Scientist
>         >         High Performance Systems Division
>         >         Lawrence Livermore National Laboratory
>         >
>         >
>         >
>         
>         --
>         
>         Albert Chu
>         [email protected]
>         Computer Scientist
>         High Performance Systems Division
>         Lawrence Livermore National Laboratory
>         
>         
> 
> 
-- 
Albert Chu
[email protected]
Computer Scientist
High Performance Systems Division
Lawrence Livermore National Laboratory
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 7633)
+++ ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2011-02-04 Christopher Maestas <[email protected]> and Albert Chu <[email protected]>
+
+	* contrib/ganglia/ganglia_ipmi_sensors.pl: Support new -r option.
+	
 2011-02-01 Albert Chu <[email protected]>
 
 	* bmc-watchdog/src/bmc-watchdog.c (_deamon_cmd_error_exit): Fix
Index: contrib/ganglia/ganglia_ipmi_sensors.pl
===================================================================
--- contrib/ganglia/ganglia_ipmi_sensors.pl	(revision 7619)
+++ contrib/ganglia/ganglia_ipmi_sensors.pl	(working copy)
@@ -37,6 +37,12 @@
 # Options:
 #
 # -h - specify hostname(s) to remotely access (don't specify for inband)
+# -r - specify search and replace substitution expressions (separated by a colon) to
+#      modify a hostname before being passed to gmetric.  This is useful if
+#      the IPMI hostname differs from the desired hostname to input to gmetric.
+#      For example "ipmi:my" would turn "ipmihost4" into "myhost4".  Not specifying
+#      a colon results in a degenerate string removal.  For example,
+#      "-ipmi" would turn "host4-ipmi" into "host4".
 # -S - specify an alternate ipmi-sensors location
 # -s - specify additional ipmi-sensors arguments
 # -G - specify an alternate gmetric location
@@ -48,6 +54,11 @@
 # Environment Variables:
 #
 # IPMI_HOSTS - specify hostname(s) to remotely access (don't specify for inband)
+# IPMI_HOSTS_SUBST - specify search and replace substitution
+#                    expressions (separated by a colon) to modify a
+#                    hostname before being passed to gmetric.  This is
+#                    useful if the IPMI hostname differs from the
+#                    desired hostname to input to gmetric.
 # IPMI_SENSORS_PATH - specify an alternate ipmi-sensors location
 # IPMI_SENSORS_ARGS - specify additional ipmi-sensors arguments
 # GMETRIC_PATH - specify an alternate gmetric location
@@ -112,6 +123,7 @@
 my $no_ganglia = 0;
 
 my $IPMI_HOSTS = undef;
+my $IPMI_HOSTS_SUBST = undef;
 my $IPMI_SENSORS_PATH = "/usr/sbin/ipmi-sensors";
 my $IPMI_SENSORS_ARGS = "";
 my $GMETRIC_PATH = "/usr/bin/gmetric";
@@ -123,12 +135,14 @@
 my $line;
 
 my $cmd;
+my @subst;
 
 sub usage
 {
     my $prog = $0;
-    print "Usage: $prog [-h <hostname(s)>] [-S <path>] [-s <sensors arguments>] [-G <path>] [-g <arguments>] [-T] [-t] [-d] [-H]\n";
+    print "Usage: $prog [-h <hostname(s)>] [-r <string>] [-S <path>] [-s <sensors arguments>] [-G <path>] [-g <arguments>] [-T] [-t] [-d] [-H]\n";
     print "  -h specify hostname(s) to remotely access\n";
+    print "  -r specify search and replace substitution expressions on the hostname (e.g. 'ipmi:host')\n";
     print "  -S specify an alternate ipmi-sensors path\n";
     print "  -s specify additional ipmi-sensors arguments\n";
     print "  -G specify an alternate gmetric path\n";
@@ -141,7 +155,7 @@
     exit 0;
 }
 
-if (!getopts("h:S:s:G:g:TtdDH"))
+if (!getopts("h:r:S:s:G:g:TtdDH"))
 {
     usage();
 }
@@ -156,6 +170,11 @@
     $IPMI_HOSTS = $main::opt_h;
 }
 
+if (defined($main::opt_r))
+{
+    $IPMI_HOSTS_SUBST = $main::opt_r;
+}
+
 if (defined($main::opt_S))
 {
     $IPMI_SENSORS_PATH = $main::opt_S;
@@ -201,6 +220,11 @@
     $IPMI_HOSTS = $ENV{"IPMI_HOSTS"};
 }
 
+if ($ENV{"IPMI_HOSTS_SUBST"})
+{
+    $IPMI_HOSTS_SUBST = $ENV{"IPMI_HOSTS_SUBST"};
+}
+
 if ($ENV{"IPMI_SENSORS_PATH"})
 {
     $IPMI_SENSORS_PATH = $ENV{"IPMI_SENSORS_PATH"};
@@ -224,6 +248,7 @@
 if ($debug)
 {
     print "IPMI_HOSTS=$IPMI_HOSTS\n";
+    print "IPMI_HOSTS_SUBST=$IPMI_HOSTS_SUBST\n";
     print "IPMI_SENSORS_PATH=$IPMI_SENSORS_PATH\n";
     print "IPMI_SENSORS_ARGS=$IPMI_SENSORS_ARGS\n";
     print "GMETRIC_PATH=$GMETRIC_PATH\n";
@@ -325,6 +350,11 @@
     $id_string =~ s/ /_/g;
     $id_string =~ s/\//_/g;
     
+    if ($IPMI_HOSTS_SUBST) {
+	@subst = split(/:/, $IPMI_HOSTS_SUBST);
+	$hostname =~ s/$subst[0]/$subst[1]/;
+    }
+
     if ($hostname ne "localhost" && $hostname ne "127.0.0.1")
     {
         my $packet_ip = gethostbyname($hostname);

Attachment: ganglia_ipmi_sensors.pl
Description: Perl program

_______________________________________________
Freeipmi-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/freeipmi-devel

Reply via email to