Discussion:
[rancid] [PATCH] nxrancid ShowEnvPower oscillating
Zenon Mousmoulas
2012-06-06 09:42:15 UTC
Permalink
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.
John Jetmore
2012-06-14 16:37:15 UTC
Permalink
Post by Zenon Mousmoulas
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
--- 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
heasley
2012-06-15 00:29:58 UTC
Permalink
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.
John Jetmore
2012-06-15 13:52:20 UTC
Permalink
Post by heasley
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
Zenon Mousmoulas
2012-06-15 14:57:46 UTC
Permalink
Post by John Jetmore
[...]
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.
heasley
2012-06-15 16:00:21 UTC
Permalink
Post by 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
Post by John Jetmore
+ if (/(.*) +(\d+ W)( +\d+ W.*)/) {
becomes
+ if (/(.* +)(\d+ W)( +\d+ W.*)/) {
Post by John Jetmore
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
#######################
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
############################
!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
############################
!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
################################
!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
##################################
!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
John Jetmore
2012-06-15 18:39:26 UTC
Permalink
Post by heasley
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

Loading...