scripts: Use new key:val parsing logic for port stats too.

This commit is contained in:
Ben Greear
2020-03-16 09:56:13 -07:00
parent 9edeeffed4
commit 7f418038dc
2 changed files with 89 additions and 63 deletions

View File

@@ -726,15 +726,12 @@ our @starting_exceptions = (
"Endpoint [",
"GenericEndp [",
"Latency:",
"Missed Beacons:",
"Pkt-Gaps:",
"Results[",
">>RSLT:",
"Rx Bytes:",
"Rx Bytes (On Wire):",
"Rx Duplicate Pkts:",
"Rx-Invalid-CRYPT:",
"Rx-Invalid-MISC:",
"Rx OOO Pkts:",
"Rx Pkts:",
"Rx Pkts (On Wire):",
@@ -744,13 +741,22 @@ our @starting_exceptions = (
"TCP Retransmits:",
"Tx Bytes:",
"Tx Bytes (On Wire):",
"Tx-Excessive-Retry:",
"Tx Failed Bytes:",
"Tx Failed Pkts:",
"Tx Pkts:",
"Tx Pkts (On Wire):",
"Tx-Retries:",
);
# Generic disassembly of lines created by show
our @port_starting_exceptions = (
# please keep these sorted
"Missed-Beacons:",
"Tx-Excessive-Retry:",
"Rx-Invalid-CRYPT:",
"Rx-Invalid-MISC:",
);
our @one_line_keys = (
"Latency:",
"Pkt-Gaps:",
@@ -765,9 +771,9 @@ our @one_line_keys = (
# $rh = u->show_as_hash(\@lines)
#
sub show_as_hash {
my ($self, $in) = (undef, undef);
my ($self, $in, $isport) = (undef, undef, 0);
if (@_ > 1) {
($self, $in) = @_;
($self, $in, $isport) = @_;
}
else {
$in = pop(@_);
@@ -785,6 +791,8 @@ sub show_as_hash {
@lines = @$in;
}
#print "show_as_hash, isport: $isport\n";
my $rh_pairs = {};
my @special = ();
@@ -792,23 +800,58 @@ sub show_as_hash {
my $key = undef;
my $value = undef;
my @hunks = ();
my $prefix = "";
#print Dumper(\@lines);
chomp(@lines);
my $found_start_x = 0;
foreach my $line (@lines) {
foreach my $start (@LANforge::Utils::starting_exceptions) {
# we purposefully are not wasting time trimming whitespace
my $i = index($line, $start);
if ($i >= 0) {
push(@special, $line);
$found_start_x++;
last;
if ($isport) {
#print "Port line -:$line:-\n";
foreach my $start (@LANforge::Utils::port_starting_exceptions) {
# we purposefully are not wasting time trimming whitespace
my $i = index($line, $start);
if ($i >= 0) {
push(@special, $line);
$found_start_x++;
last;
}
}
}
else {
foreach my $start (@LANforge::Utils::starting_exceptions) {
# we purposefully are not wasting time trimming whitespace
my $i = index($line, $start);
if ($i >= 0) {
push(@special, $line);
$found_start_x++;
last;
}
}
}
if ($found_start_x) {
$found_start_x = 0;
next;
}
if ($isport) {
#print "line -:$line:-\n";
if ($line =~ /^\s+\[Configured\]/) {
#print "Prefix to cfg\n";
$prefix = "Cfg";
next;
}
if ($line =~ /^\s+\[Probed\]/) {
$prefix = "Probed";
next;
}
$line =~ s/ (dbm|[kmg]?bps)/$1/ig;
$line =~ s/DNS Servers/DNS-Servers/ig;
$line =~ s/TX Queue Len/TX-Queue-Len/ig;
$line =~ s/Missed Beacons/Missed-Beacons/ig;
#print "$i: ".$lines[$i]."\n";
}
# at this point, every line should be split using colons and spaces
@hunks = split(/\s+/, $line);
foreach my $hunk (@hunks) {
@@ -818,12 +861,19 @@ sub show_as_hash {
}
$value = $hunk;
if ((defined $key) && ("" ne $key)) {
$rh_pairs->{$key} = (defined $value) ? $value : "";
my $val = (defined $value) ? $value : "";
#print "Adding key -:$key:- val -:$val:-\n";
$rh_pairs->{$key} = $val;
if ($prefix ne "") {
#print "Adding prefixed key -:$prefix-$key:- val -:$val:-\n";
$rh_pairs->{"$prefix-$key"} = $val;
}
$key = undef;
$value = undef;
}
}
}
@hunks = ();
$key = undef;
$value = undef;
@@ -879,15 +929,19 @@ sub show_as_hash {
next if ($found_oneline);
}
# This is parsing bucket counters, maybe more
my $i = index($line, ':');
$key = substr($line, 0, $i);
$key =~ s/^\s*//g;
$value = substr($line, $i+1);
$rh_pairs->{$key} = $value; # Add full line to hash
$value =~ s/^\s*//g;
@hunks = split(/\s+/, $value);
$rh_vals = $self->hunks_to_hashes($key, \@hunks);
foreach my $subkey (keys %$rh_vals) {
$rh_pairs->{$subkey} = $rh_vals->{$subkey}
my $val = $rh_vals->{$subkey};
#print("Adding subkey -:$subkey:- val -:$val:-\n");
$rh_pairs->{$subkey} = $val;
}
$rh_vals = undef;
$key = undef;

View File

@@ -511,61 +511,33 @@ elsif(($show_port ne "NA") && ($show_port ne "")) {
@lines = split("\n", $::utils->doAsyncCmd("nc_show_port 1 $card $port_name"));
}
# trick here is to place a ; before anything that looks like a keyword
for($i=0; $i<@lines; $i++) {
$lines[$i] = " ".$lines[$i]." ;";
$lines[$i] =~ s/ (dbm|[kmg]?bps)/$1/ig;
$lines[$i] =~ s/DNS Servers/DNS-Servers/ig;
$lines[$i] =~ s/TX Queue Len/TX-Queue-Len/ig;
$lines[$i] =~ s/Missed Beacons/Missed-Beacons/ig;
$lines[$i] =~ s/([^ :]+\: +)/;$1/g;
$lines[$i] =~ s/^\s+;?//;
#print "$i: ".$lines[$i]."\n";
}
my $matcher = "(".join('|', keys %option_map).")";
#print "MATCHER: $matcher\n";
my @matches = grep( /$matcher/, @lines);
for my $match (@matches) {
my @parts = split(/\s*;/, $match);
shift(@parts) if (@parts > 1 && $parts[0] =~ /^\s+$/);
for (my $i=0; $i <= $#parts; $i++) {
my $option= "";
my $value = "";
($option) = $parts[$i] =~ /^\s*(.*?):/;
($value) = $parts[$i] =~ /:(.*)$/;
$option =~ s/^\s*(.*?)\s*$/$1/;
if ($value =~ /^\s*$/) {
$value = "";
}
else {
$value =~ s/^\s*(.*?)\s*$/$1/
}
next if (!defined $option || $option eq "");
my $rh_value_map = $::utils->show_as_hash(\@lines, 1);
if ( defined $option && defined $option_map{ $option } ) {
for my $option (keys %option_map) {
my $val = '-';
if ( $option eq "Missed-Beacons"
|| $option eq "Rx-Invalid-CRYPT"
|| $option eq "Rx-Invalid-MISC"
|| $option eq "Tx-Excessive-Retry" )
{
$match =~ s/\s*;/; /g;
$value = $match;
$value =~ s/${option}:\s*;//;
}
$option_map{$option} = $value;
if (defined $rh_value_map->{$option}) {
$val = $rh_value_map->{$option};
$option_map{"$option"} = $val;
if (defined $rh_value_map->{"Cfg-$option"}) {
$val = $rh_value_map->{"Cfg-$option"};
$option_map{"Cfg-$option"} = $val;
}
if (defined $rh_value_map->{"Probed-$option"}) {
$val = $rh_value_map->{"Probed-$option"};
$option_map{"Probed-$option"} = $val;
}
}
}
for $option ( sort keys %option_map ) {
@matches = grep { /$option:/ } @lines;
if (@matches < 1) {
print STDERR "$option $NOT_FOUND\n";
}
else {
print $option.": ".$option_map{ $option }."\n";
}
#print("Checking option: $option\n");
print $option.": ".$option_map{ $option }."\n";
}
exit(0);
}