Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: RANCID: Users

[PATCH] nxrancid ShowEnvPower oscillating

 

 

RANCID users RSS feed   Index | Next | Previous | View Threaded


zmousm at noc

Jun 6, 2012, 2:42 AM

Post #1 of 7 (706 views)
Permalink
[PATCH] nxrancid ShowEnvPower oscillating

Hi,

ShowEnvPower in nxrancid tries to filter actual power/draw from the
output, but (as noted in a comment) it does not always chop enough for the
text to line up. Therefore nxrancid output oscillates when the power draw
of some module(s), as reported by "show environment power", switches
between 3-digit and 4-digit wattage. For example:

--- group/configs/n7k-device 2012/06/04 23:18:42 7973
+++ group/configs/n7k-device 2012/06/05 02:18:43 7974
@@ -192,7 +192,7 @@
!Env: 4 N7K-M148GS-11L 400 W Powered-Up
!Env: 5 N7K-SUP1 210 W Powered-Up
!Env: 6 N7K-SUP1 210 W Powered-Up
-!Env: 7 N7K-M132XP-12L 750 W Powered-Up
+!Env: 7 N7K-M132XP-12L 750 W Powered-Up
!Env: Xb1 N7K-C7010-FAB-1 80 W Powered-Up
!Env: Xb2 N7K-C7010-FAB-1 80 W Powered-Up
!Env: Xb3 N7K-C7010-FAB-1 80 W Powered-Up

The following patch tries to stop this. Fixed width parsing works with
NX-OS 6.0, I could not run this against other (previous) versions but it
should be the same -- I hope someone on the list can test it.

Best regards,
Zenon Mousmoulas
---

diff -ru rancid-2.3.8/bin/nxrancid.in rancid-2.3.8-zmousm/bin/nxrancid.in
--- rancid-2.3.8/bin/nxrancid.in 2011-07-29 23:40:40.000000000 +0300
+++ rancid-2.3.8-zmousm/bin/nxrancid.in 2012-06-06 11:56:59.000000000
+0300
@@ -374,13 +374,16 @@
#------- ------------------- ----------- ----------- --------------
#2 NURBURGRING N/A 573 W Powered-Up
#fan1 N/A 720 W Powered-Up
- s/ Actual / /;
- s/ Output / /;
- s/ \(Watts \) / /;
- s/ Draw / /;
- s/ ----------- / /;
- s/ N\/A / / ||
- s/ \d+ W / /; # Does not chop enough to line up.
+
+ if (/Actual +Total/ ||
+ /Actual +Power/ ||
+ /Draw +Allocated/ ||
+ /Output +Capacity/ ||
+ /(\(Watts \)) +\g{-1}/ ||
+ /(-----------) +\g{-1}/ ||
+ /(\d+ W|N\/A) +\d+ W/) {
+ substr $_, 30, 13, "";
+ }

/actual draw/ && next; # Drop changing total power output.


_______________________________________________
Rancid-discuss mailing list
Rancid-discuss [at] shrubbery
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss


jj33 at pobox

Jun 14, 2012, 9:37 AM

Post #2 of 7 (657 views)
Permalink
Re: [PATCH] nxrancid ShowEnvPower oscillating [In reply to]

On Wed, Jun 6, 2012 at 5:42 AM, Zenon Mousmoulas <zmousm [at] noc> wrote:
> Hi,
>
> ShowEnvPower in nxrancid tries to filter actual power/draw from the
> output, but (as noted in a comment) it does not always chop enough for the
> text to line up. Therefore nxrancid output oscillates when the power draw
> of some module(s), as reported by "show environment power", switches
> between 3-digit and 4-digit wattage. For example:
>
> --- group/configs/n7k-device    2012/06/04 23:18:42     7973
> +++ group/configs/n7k-device    2012/06/05 02:18:43     7974
> @@ -192,7 +192,7 @@
>  !Env: 4        N7K-M148GS-11L                     400 W    Powered-Up
>  !Env: 5        N7K-SUP1                     210 W    Powered-Up
>  !Env: 6        N7K-SUP1                     210 W    Powered-Up
> -!Env: 7        N7K-M132XP-12L                   750 W    Powered-Up
> +!Env: 7        N7K-M132XP-12L                     750 W    Powered-Up
>  !Env: Xb1      N7K-C7010-FAB-1               80 W    Powered-Up
>  !Env: Xb2      N7K-C7010-FAB-1               80 W    Powered-Up
>  !Env: Xb3      N7K-C7010-FAB-1               80 W    Powered-Up
>
> The following patch tries to stop this. Fixed width parsing works with
> NX-OS 6.0, I could not run this against other (previous) versions but it
> should be the same -- I hope someone on the list can test it.
>
> Best regards,
> Zenon Mousmoulas
> ---
>
> diff -ru rancid-2.3.8/bin/nxrancid.in rancid-2.3.8-zmousm/bin/nxrancid.in
> --- rancid-2.3.8/bin/nxrancid.in        2011-07-29 23:40:40.000000000 +0300
> +++ rancid-2.3.8-zmousm/bin/nxrancid.in 2012-06-06 11:56:59.000000000
> +0300
> @@ -374,13 +374,16 @@
>  #-------  -------------------  -----------  -----------  --------------
>  #2        NURBURGRING                N/A          573 W    Powered-Up
>  #fan1                                N/A          720 W    Powered-Up
> -       s/      Actual /  /;
> -       s/      Output /  /;
> -       s/    \(Watts \) /  /;
> -       s/        Draw /  /;
> -       s/ ----------- /  /;
> -       s/        N\/A  /  / ||
> -       s/ \d+ W /  /;          # Does not chop enough to line up.
> +
> +       if (/Actual +Total/ ||
> +           /Actual +Power/ ||
> +           /Draw +Allocated/ ||
> +           /Output +Capacity/ ||
> +           /(\(Watts \)) +\g{-1}/ ||
> +           /(-----------) +\g{-1}/ ||
> +           /(\d+ W|N\/A) +\d+ W/) {
> +           substr $_, 30, 13, "";
> +       }
>
>        /actual draw/ && next;  # Drop changing total power output.

Zenon, thanks for reporting this. I just started looking at a similar
issue on an NX-OS 5 machine, it was great to find your problem report
and patch. I ended up using a slightly smaller fix which is working
well for me:

#########################
--- nxrancid-238-dist 2012-06-14 10:58:55.000000000 -0500
+++ nxrancid-238-local 2012-06-14 11:00:00.000000000 -0500
@@ -380,7 +380,7 @@
s/ Draw / /;
s/ ----------- / /;
s/ N\/A / / ||
- s/ \d+ W / /; # Does not chop enough to line up.
+ s/ [ \d]{9} W / /; # Does not chop enough to line
up. (does now)

/actual draw/ && next; # Drop changing total power output.

###########################

I didn't feel comfortable that the substr() solution wouldn't cause
other problems (for instance, unexpectedly long module or model names
making the column 30 starting point incorrect). My solution isn't
perfect, but it feels slightly safer to me.

Thanks
--John
_______________________________________________
Rancid-discuss mailing list
Rancid-discuss [at] shrubbery
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss


heas at shrubbery

Jun 14, 2012, 5:29 PM

Post #3 of 7 (650 views)
Permalink
Re: [PATCH] nxrancid ShowEnvPower oscillating [In reply to]

How about the following instead:

Index: nxrancid.in
===================================================================
--- nxrancid.in (revision 2494)
+++ nxrancid.in (working copy)
@@ -375,14 +375,8 @@
#------- ------------------- ----------- ----------- --------------
#2 NURBURGRING N/A 573 W Powered-Up
#fan1 N/A 720 W Powered-Up
- if (/Actual +Total/ ||
- /Actual +Power/ ||
- /Draw +Allocated/ ||
- /Output +Capacity/ ||
- /(\(Watts \)) +\g{-1}/ ||
- /(-----------) +\g{-1}/ ||
- /(\d+ W|N\/A) +\d+ W/) {
- substr($_, 30, 13, "");
+ if ( /(.*) +(\d+ W)( +\d+ W.*)/) {
+ $_ = sprintf("%s%-". length($2)."s%s\n", $1, "", $3);
}

/actual draw/ && next; # Drop changing total power output.

_______________________________________________
Rancid-discuss mailing list
Rancid-discuss [at] shrubbery
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss


jj33 at pobox

Jun 15, 2012, 6:52 AM

Post #4 of 7 (649 views)
Permalink
Re: [PATCH] nxrancid ShowEnvPower oscillating [In reply to]

On Thu, Jun 14, 2012 at 8:29 PM, heasley <heas [at] shrubbery> wrote:
> How about the following instead:
>
> Index: nxrancid.in
> ===================================================================
> --- nxrancid.in (revision 2494)
> +++ nxrancid.in (working copy)
> @@ -375,14 +375,8 @@
>  #-------  -------------------  -----------  -----------  --------------
>  #2        NURBURGRING                N/A          573 W    Powered-Up
>  #fan1                                N/A          720 W    Powered-Up
> -       if (/Actual +Total/ ||
> -           /Actual +Power/ ||
> -           /Draw +Allocated/ ||
> -           /Output +Capacity/ ||
> -           /(\(Watts \)) +\g{-1}/ ||
> -           /(-----------) +\g{-1}/ ||
> -           /(\d+ W|N\/A) +\d+ W/) {
> -           substr($_, 30, 13, "");
> +       if ( /(.*) +(\d+ W)( +\d+ W.*)/) {
> +           $_ = sprintf("%s%-". length($2)."s%s\n", $1, "", $3);
>        }
>
>        /actual draw/ && next;  # Drop changing total power output.
>

Here's a version of your patch that applies against 238 (it looks like
the version above was applied against a copy already patched with
Zenon's solution):

################

--- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500
+++ nxrancid-238-heasley 2012-06-15 08:22:37.000000000 -0500
@@ -379,8 +379,10 @@
s/ \(Watts \) / /;
s/ Draw / /;
s/ ----------- / /;
- s/ N\/A / / ||
- s/ \d+ W / /; # Does not chop enough to line up.
+ s/ N\/A / /;
+ if (/(.*) +(\d+ W)( +\d+ W.*)/) {
+ $_ = sprintf("%s%-". length($2)."s%s\n", $1, "", $3);
+ }

/actual draw/ && next; # Drop changing total power output.
#################

Second, I like what you are doing here, your solution solves my major
concern with my patch, which was that I was matching [\s\d]{9}, but
not strictly requiring that it be all spaces and then all digits.
This left a small hole where, if there was somehow another number
added immediately in front of the actual wattage, we would swallow it.

My only problem with this solution is that it still leaves the \d+\sW
lines out of alignment with the lines around it. I'm attaching a .txt
of the different patch outputs so they can be easily viewed in a
monospace font.

Here is my version of your patch which solves all of the issues:
1) prevents line oscillation when the number of figits in the actual
draw changes
2) stricter regexp, should only parse the line as we expect.
3) fixes alignment so all "show env power" output columns match

######################
--- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500
+++ nxrancid-238-jetmore-2 2012-06-15 08:40:29.000000000 -0500
@@ -379,8 +379,10 @@
s/ \(Watts \) / /;
s/ Draw / /;
s/ ----------- / /;
- s/ N\/A / / ||
- s/ \d+ W / /; # Does not chop enough to line up.
+ s/ N\/A / /;
+ if (/(.*?)(\s+\d+ W)( +\d+ W.*)/) {
+ $_ = sprintf("%s%-".(length($2)-11)."s%s\n", $1, "", $3);
+ }

/actual draw/ && next; # Drop changing total power output.
##########################

Thanks for your consideration,
--John
Attachments: nxrancid-example-output.txt (3.36 KB)


zmousm at noc

Jun 15, 2012, 7:57 AM

Post #5 of 7 (653 views)
Permalink
Re: [PATCH] nxrancid ShowEnvPower oscillating [In reply to]

On Fri, 15 Jun 2012 09:52:20 -0400, John Jetmore <jj33 [at] pobox> wrote:
> [...]
> Here is my version of your patch which solves all of the issues:
> 1) prevents line oscillation when the number of figits in the actual
> draw changes
> 2) stricter regexp, should only parse the line as we expect.
> 3) fixes alignment so all "show env power" output columns match
>
> ######################
> --- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500
> +++ nxrancid-238-jetmore-2 2012-06-15 08:40:29.000000000 -0500
> @@ -379,8 +379,10 @@
> s/ \(Watts \) / /;
> s/ Draw / /;
> s/ ----------- / /;
> - s/ N\/A / / ||
> - s/ \d+ W / /; # Does not chop enough to line up.
> + s/ N\/A / /;
> + if (/(.*?)(\s+\d+ W)( +\d+ W.*)/) {
> + $_ = sprintf("%s%-".(length($2)-11)."s%s\n", $1, "",
$3);
> + }
>
> /actual draw/ && next; # Drop changing total power output.
> ##########################

In my approach I also trimmed the whitespace after this column (11+2=13
chars). Other than that, LGTM.

That is, until Cisco changes the width of this column ;)

Thanks,
Z.
_______________________________________________
Rancid-discuss mailing list
Rancid-discuss [at] shrubbery
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss


heas at shrubbery

Jun 15, 2012, 9:00 AM

Post #6 of 7 (651 views)
Permalink
Re: [PATCH] nxrancid ShowEnvPower oscillating [In reply to]

Fri, Jun 15, 2012 at 09:52:20AM -0400, John Jetmore:
> --- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500
> +++ nxrancid-238-heasley 2012-06-15 08:22:37.000000000 -0500
> @@ -379,8 +379,10 @@
> s/ \(Watts \) / /;
> s/ Draw / /;
> s/ ----------- / /;
> - s/ N\/A / / ||
> - s/ \d+ W / /; # Does not chop enough to line up.
> + s/ N\/A / /;
> + if (/(.*) +(\d+ W)( +\d+ W.*)/) {
> + $_ = sprintf("%s%-". length($2)."s%s\n", $1, "", $3);
> + }
>
> /actual draw/ && next; # Drop changing total power output.
> #################
>
> Second, I like what you are doing here, your solution solves my major
> concern with my patch, which was that I was matching [\s\d]{9}, but
> not strictly requiring that it be all spaces and then all digits.
> This left a small hole where, if there was somehow another number
> added immediately in front of the actual wattage, we would swallow it.
>
> My only problem with this solution is that it still leaves the \d+\sW
> lines out of alignment with the lines around it. I'm attaching a .txt
> of the different patch outputs so they can be easily viewed in a
> monospace font.

your patch isnt complete; mine removed all the filters to remove the
column and just blanked the data. so the column remains and there is
no issue with alignment. but, your regex is correct including that
WS, so in my method

> + if (/(.*) +(\d+ W)( +\d+ W.*)/) {
becomes
+ if (/(.* +)(\d+ W)( +\d+ W.*)/) {

> Here is my version of your patch which solves all of the issues:
> 1) prevents line oscillation when the number of figits in the actual
> draw changes
> 2) stricter regexp, should only parse the line as we expect.
> 3) fixes alignment so all "show env power" output columns match
>
> ######################
> --- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500
> +++ nxrancid-238-jetmore-2 2012-06-15 08:40:29.000000000 -0500
> @@ -379,8 +379,10 @@
> s/ \(Watts \) / /;
> s/ Draw / /;
> s/ ----------- / /;
> - s/ N\/A / / ||
> - s/ \d+ W / /; # Does not chop enough to line up.
> + s/ N\/A / /;
> + if (/(.*?)(\s+\d+ W)( +\d+ W.*)/) {
> + $_ = sprintf("%s%-".(length($2)-11)."s%s\n", $1, "", $3);
> + }
>
> /actual draw/ && next; # Drop changing total power output.
> ##########################
>
> Thanks for your consideration,
> --John

> #######################
> un-modified output:
> Actual Power
> Module Model Draw Allocated Status
> (Watts ) (Watts )
> ------- ------------------- ----------- ----------- --------------
> Xb4 xbar N/A 60 W Absent
> Xb5 xbar N/A 60 W Absent
> fan1 N7K-C7010-FAN-S 116 W 720 W Powered-Up
> fan2 N7K-C7010-FAN-S 116 W 720 W Powered-Up
> fan3 N7K-C7010-FAN-F 11 W 120 W Powered-Up
> fan4 N7K-C7010-FAN-F 11 W 120 W Powered-Up
>
> ############################
> original code:
> !Env: Power
> !Env: Module Model Allocated Status
> !Env: (Watts )
> !Env: ------- ------------------- ----------- --------------
> !Env: Xb4 xbar 60 W Absent
> !Env: Xb5 xbar 60 W Absent
> !Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
> !Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
>
>
> ############################
> jetmore's original patch:
> !Env: Power
> !Env: Module Model Allocated Status
> !Env: (Watts )
> !Env: ------- ------------------- ----------- --------------
> !Env: Xb4 xbar 60 W Absent
> !Env: Xb5 xbar 60 W Absent
> !Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
> !Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
>
> ################################
> heasley's patch:
> !Env: Power
> !Env: Module Model Allocated Status
> !Env: (Watts )
> !Env: ------- ------------------- ----------- --------------
> !Env: Xb4 xbar 60 W Absent
> !Env: Xb5 xbar 60 W Absent
> !Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
> !Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
>
> ##################################
> jetmore's new patch:
> !Env: Power
> !Env: Module Model Allocated Status
> !Env: (Watts )
> !Env: ------- ------------------- ----------- --------------
> !Env: Xb4 xbar 60 W Absent
> !Env: Xb5 xbar 60 W Absent
> !Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up
> !Env: fan3 N7K-C7010-FAN-F 120 W Powered-Up
> !Env: fan4 N7K-C7010-FAN-F 120 W Powered-Up
>

_______________________________________________
Rancid-discuss mailing list
Rancid-discuss [at] shrubbery
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss


jj33 at pobox

Jun 15, 2012, 11:39 AM

Post #7 of 7 (654 views)
Permalink
Re: [PATCH] nxrancid ShowEnvPower oscillating [In reply to]

On Fri, Jun 15, 2012 at 12:00 PM, heasley <heas [at] shrubbery> wrote:
> your patch isnt complete; mine removed all the filters to remove the
> column and just blanked the data.  so the column remains and there is
> no issue with alignment.  but, your regex is correct including that
> WS, so in my method
>
>> +       if (/(.*) +(\d+ W)( +\d+ W.*)/) {
> becomes
> +       if (/(.* +)(\d+ W)( +\d+ W.*)/) {

It wasn't clear to me what you were doing because your diff wasn't
against the 2.3.8 code, but I now understand what you are saying.
Sounds like a fine solution to me, and I'm glad my response helped a
little. Looking forward to seeing it in the next release.

For the record, here's what I actually tested locally:

#############################
--- nxrancid-238-dist 2012-06-14 09:10:26.000000000 -0500
+++ nxrancid-238-heasley-2 2012-06-15 13:37:27.000000000 -0500
@@ -374,13 +374,9 @@
#------- ------------------- ----------- ----------- --------------
#2 NURBURGRING N/A 573 W Powered-Up
#fan1 N/A 720 W Powered-Up
- s/ Actual / /;
- s/ Output / /;
- s/ \(Watts \) / /;
- s/ Draw / /;
- s/ ----------- / /;
- s/ N\/A / / ||
- s/ \d+ W / /; # Does not chop enough to line up.
+ if (/(.* +)(\d+ W)( +\d+ W.*)/) {
+ $_ = sprintf("%s%-".length($2)."s%s\n", $1, "", $3);
+ }

/actual draw/ && next; # Drop changing total power output.
########################

And example output (which lines up properly in monospace font):

!Env: Xb4 xbar N/A 60 W Absent
!Env: Xb5 xbar N/A 60 W Absent
!Env: fan1 N7K-C7010-FAN-S 720 W Powered-Up
!Env: fan2 N7K-C7010-FAN-S 720 W Powered-Up


Thanks
--John
_______________________________________________
Rancid-discuss mailing list
Rancid-discuss [at] shrubbery
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss

RANCID users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.