Discussion:
[rancid] How to remove fan speed from f5rancid output?
Matt Almgren
2015-07-07 23:14:39 UTC
Permalink
Well, I had thought I had fixed this, but it was just not running for our f5s for a while. Oopps.

Anyway, my perl-fu isn’t very good. Can someone quickly tell me what I need to change in this code to remove the fan speed(rpm) values from the output below:


## $Id: f5rancid.in 2279 2011-01-31 22:41:00Z heas $

sub ShowHardware {
print STDERR " In ShowHardware: $_" if ($debug);

while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);

s/\d+rpm//ig;
s/^\|//;
s/^\ \ ([0-9]+)(\ +).*up.*[0-9]/ $1$2up REMOVED/i;
s/^\ \ ([0-9]+)(\ +).*Air\ Inlet/ $1$2REMOVED Air Inlet/i;
s/^\ \ ([0-9]+)(\ +).*HSBe/ $1$2REMOVED HSBe/i;
s/^\ \ ([0-9]+)(\ +).*TMP421 on die/ $1$2REMOVED TMP421 on die/i;
s/^\ \ ([0-9]+)(\ +)[0-9]+\ +[0-9]+ +[0-9]+/ $1$2REMOVED REMOVED REMOVED/;
/Type: / && ProcessHistory("COMMENTS","keysort","A0",
"#Chassis type: $'");

ProcessHistory("COMMENTS","keysort","B1","#$_") && next;
}
return(0);
}

[***@mt-lb03:Active:In Sync] ~ # tmsh show sys hardware

Sys::Hardware
Chassis Fan Status
Index Status Low Limit(rpm) Fan Speed(rpm)
1 up 3000 10227
2 up 3000 10887
3 up 3000 10546

Chassis Information
Maximum MAC Count 2
Registration Key -

Chassis Power Supply Status
Index Status Current
1 up NA
2 not-present NA

Chassis Temperature Status
Index Lo Limit(C) Temp(degC) Hi Limit(C) Location
1 5 22 55 Air Inlet
<snip>

If there’s a more updated f5rancid that fully supports TMSH on 11.6.0 HF3, I’d love to have a copy.

Thanks, Matt
Alan McKinnon
2015-07-08 07:11:57 UTC
Permalink
Post by Matt Almgren
Well, I had thought I had fixed this, but it was just not running for
our f5s for a while. Oopps.
Anyway, my perl-fu isn’t very good. Can someone quickly tell me what I
need to change in this code to remove the fan speed(rpm) values from the
## $Id: f5rancid.in 2279 2011-01-31 22:41:00Z heas $
sub ShowHardware {
print STDERR " In ShowHardware: $_" if ($debug);
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
s/\d+rpm//ig;
s/^\|//;
s/^\ \ ([0-9]+)(\ +).*up.*[0-9]/ $1$2up REMOVED/i;
^^^^ ^^

This is the code that is intended to do what you want.
But there's no need to escape the spaces in that regex.
Replace with literal spaces, or preferrably \s for any whitespace:

s/^\s+([0-9]+)(\s+).*up.*[0-9]/ $1$2up REMOVED/i;


Tweak and adjust it to your liking depending on what you want the output
line to be transformed into.

You don't need much perl-fu for this, you do however need quite a bit of
regex-fu. The Llama Book (google it) has very good perl regex tutorials
at just the right level to get you going.


Alan
--
Alan McKinnon
***@gmail.com
Matt Almgren
2015-07-08 16:21:09 UTC
Permalink
Thanks Alan for the tip.

I used regexr.com to help with this. Man, I wish this site was around 10 years ago when I was writing regexps on a daily basis. I had forgotten most of it.

This looks like it will work just fine:

s/^\ \ ([0-9]+)(\ +)(.*up.*)\ +([0-9]+) /$1$2$3REMOVEDRPM/i;

Thanks, Matt





From: Alan McKinnon <***@gmail.com<mailto:***@gmail.com>>
Date: Wednesday, July 8, 2015 at 12:11 AM
To: "rancid-***@shrubbery.net<mailto:rancid-***@shrubbery.net>" <rancid-***@shrubbery.net<mailto:rancid-***@shrubbery.net>>
Subject: Re: [rancid] How to remove fan speed from f5rancid output?

On 08/07/2015 01:14, Matt Almgren wrote:
Well, I had thought I had fixed this, but it was just not running for
our f5s for a while. Oopps.
Anyway, my perl-fu isn’t very good. Can someone quickly tell me what I
need to change in this code to remove the fan speed(rpm) values from the
output below:
## $Id: f5rancid.in 2279 2011-01-31 22:41:00Z heas $
sub ShowHardware {
print STDERR " In ShowHardware: $_" if ($debug);
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
s/\d+rpm//ig;
s/^\|//;
s/^\ \ ([0-9]+)(\ +).*up.*[0-9]/ $1$2up REMOVED/i;
^^^^ ^^

This is the code that is intended to do what you want.
But there's no need to escape the spaces in that regex.
Replace with literal spaces, or preferrably \s for any whitespace:

s/^\s+([0-9]+)(\s+).*up.*[0-9]/ $1$2up REMOVED/i;


Tweak and adjust it to your liking depending on what you want the output
line to be transformed into.

You don't need much perl-fu for this, you do however need quite a bit of
regex-fu. The Llama Book (google it) has very good perl regex tutorials
at just the right level to get you going.


Alan




--
Alan McKinnon
***@gmail.com<mailto:***@gmail.com>

Loading...