mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-02 19:58:03 +00:00
scripts: Use new key:val parsing logic for port stats too.
This commit is contained in:
@@ -726,15 +726,12 @@ our @starting_exceptions = (
|
|||||||
"Endpoint [",
|
"Endpoint [",
|
||||||
"GenericEndp [",
|
"GenericEndp [",
|
||||||
"Latency:",
|
"Latency:",
|
||||||
"Missed Beacons:",
|
|
||||||
"Pkt-Gaps:",
|
"Pkt-Gaps:",
|
||||||
"Results[",
|
"Results[",
|
||||||
">>RSLT:",
|
">>RSLT:",
|
||||||
"Rx Bytes:",
|
"Rx Bytes:",
|
||||||
"Rx Bytes (On Wire):",
|
"Rx Bytes (On Wire):",
|
||||||
"Rx Duplicate Pkts:",
|
"Rx Duplicate Pkts:",
|
||||||
"Rx-Invalid-CRYPT:",
|
|
||||||
"Rx-Invalid-MISC:",
|
|
||||||
"Rx OOO Pkts:",
|
"Rx OOO Pkts:",
|
||||||
"Rx Pkts:",
|
"Rx Pkts:",
|
||||||
"Rx Pkts (On Wire):",
|
"Rx Pkts (On Wire):",
|
||||||
@@ -744,13 +741,22 @@ our @starting_exceptions = (
|
|||||||
"TCP Retransmits:",
|
"TCP Retransmits:",
|
||||||
"Tx Bytes:",
|
"Tx Bytes:",
|
||||||
"Tx Bytes (On Wire):",
|
"Tx Bytes (On Wire):",
|
||||||
"Tx-Excessive-Retry:",
|
|
||||||
"Tx Failed Bytes:",
|
"Tx Failed Bytes:",
|
||||||
"Tx Failed Pkts:",
|
"Tx Failed Pkts:",
|
||||||
"Tx Pkts:",
|
"Tx Pkts:",
|
||||||
"Tx Pkts (On Wire):",
|
"Tx Pkts (On Wire):",
|
||||||
"Tx-Retries:",
|
"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 = (
|
our @one_line_keys = (
|
||||||
"Latency:",
|
"Latency:",
|
||||||
"Pkt-Gaps:",
|
"Pkt-Gaps:",
|
||||||
@@ -765,9 +771,9 @@ our @one_line_keys = (
|
|||||||
# $rh = u->show_as_hash(\@lines)
|
# $rh = u->show_as_hash(\@lines)
|
||||||
#
|
#
|
||||||
sub show_as_hash {
|
sub show_as_hash {
|
||||||
my ($self, $in) = (undef, undef);
|
my ($self, $in, $isport) = (undef, undef, 0);
|
||||||
if (@_ > 1) {
|
if (@_ > 1) {
|
||||||
($self, $in) = @_;
|
($self, $in, $isport) = @_;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$in = pop(@_);
|
$in = pop(@_);
|
||||||
@@ -785,6 +791,8 @@ sub show_as_hash {
|
|||||||
@lines = @$in;
|
@lines = @$in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#print "show_as_hash, isport: $isport\n";
|
||||||
|
|
||||||
my $rh_pairs = {};
|
my $rh_pairs = {};
|
||||||
my @special = ();
|
my @special = ();
|
||||||
|
|
||||||
@@ -792,23 +800,58 @@ sub show_as_hash {
|
|||||||
my $key = undef;
|
my $key = undef;
|
||||||
my $value = undef;
|
my $value = undef;
|
||||||
my @hunks = ();
|
my @hunks = ();
|
||||||
|
my $prefix = "";
|
||||||
#print Dumper(\@lines);
|
#print Dumper(\@lines);
|
||||||
chomp(@lines);
|
chomp(@lines);
|
||||||
my $found_start_x = 0;
|
my $found_start_x = 0;
|
||||||
foreach my $line (@lines) {
|
foreach my $line (@lines) {
|
||||||
foreach my $start (@LANforge::Utils::starting_exceptions) {
|
if ($isport) {
|
||||||
# we purposefully are not wasting time trimming whitespace
|
#print "Port line -:$line:-\n";
|
||||||
my $i = index($line, $start);
|
foreach my $start (@LANforge::Utils::port_starting_exceptions) {
|
||||||
if ($i >= 0) {
|
# we purposefully are not wasting time trimming whitespace
|
||||||
push(@special, $line);
|
my $i = index($line, $start);
|
||||||
$found_start_x++;
|
if ($i >= 0) {
|
||||||
last;
|
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) {
|
if ($found_start_x) {
|
||||||
$found_start_x = 0;
|
$found_start_x = 0;
|
||||||
next;
|
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
|
# at this point, every line should be split using colons and spaces
|
||||||
@hunks = split(/\s+/, $line);
|
@hunks = split(/\s+/, $line);
|
||||||
foreach my $hunk (@hunks) {
|
foreach my $hunk (@hunks) {
|
||||||
@@ -818,12 +861,19 @@ sub show_as_hash {
|
|||||||
}
|
}
|
||||||
$value = $hunk;
|
$value = $hunk;
|
||||||
if ((defined $key) && ("" ne $key)) {
|
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;
|
$key = undef;
|
||||||
$value = undef;
|
$value = undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@hunks = ();
|
@hunks = ();
|
||||||
$key = undef;
|
$key = undef;
|
||||||
$value = undef;
|
$value = undef;
|
||||||
@@ -879,15 +929,19 @@ sub show_as_hash {
|
|||||||
next if ($found_oneline);
|
next if ($found_oneline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This is parsing bucket counters, maybe more
|
||||||
my $i = index($line, ':');
|
my $i = index($line, ':');
|
||||||
$key = substr($line, 0, $i);
|
$key = substr($line, 0, $i);
|
||||||
$key =~ s/^\s*//g;
|
$key =~ s/^\s*//g;
|
||||||
$value = substr($line, $i+1);
|
$value = substr($line, $i+1);
|
||||||
|
$rh_pairs->{$key} = $value; # Add full line to hash
|
||||||
$value =~ s/^\s*//g;
|
$value =~ s/^\s*//g;
|
||||||
@hunks = split(/\s+/, $value);
|
@hunks = split(/\s+/, $value);
|
||||||
$rh_vals = $self->hunks_to_hashes($key, \@hunks);
|
$rh_vals = $self->hunks_to_hashes($key, \@hunks);
|
||||||
foreach my $subkey (keys %$rh_vals) {
|
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;
|
$rh_vals = undef;
|
||||||
$key = undef;
|
$key = undef;
|
||||||
|
|||||||
@@ -511,61 +511,33 @@ elsif(($show_port ne "NA") && ($show_port ne "")) {
|
|||||||
@lines = split("\n", $::utils->doAsyncCmd("nc_show_port 1 $card $port_name"));
|
@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
|
my $rh_value_map = $::utils->show_as_hash(\@lines, 1);
|
||||||
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 "");
|
|
||||||
|
|
||||||
if ( defined $option && defined $option_map{ $option } ) {
|
for my $option (keys %option_map) {
|
||||||
|
my $val = '-';
|
||||||
|
|
||||||
if ( $option eq "Missed-Beacons"
|
if (defined $rh_value_map->{$option}) {
|
||||||
|| $option eq "Rx-Invalid-CRYPT"
|
$val = $rh_value_map->{$option};
|
||||||
|| $option eq "Rx-Invalid-MISC"
|
|
||||||
|| $option eq "Tx-Excessive-Retry" )
|
$option_map{"$option"} = $val;
|
||||||
{
|
|
||||||
$match =~ s/\s*;/; /g;
|
if (defined $rh_value_map->{"Cfg-$option"}) {
|
||||||
$value = $match;
|
$val = $rh_value_map->{"Cfg-$option"};
|
||||||
$value =~ s/${option}:\s*;//;
|
$option_map{"Cfg-$option"} = $val;
|
||||||
}
|
}
|
||||||
$option_map{$option} = $value;
|
if (defined $rh_value_map->{"Probed-$option"}) {
|
||||||
|
$val = $rh_value_map->{"Probed-$option"};
|
||||||
|
$option_map{"Probed-$option"} = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for $option ( sort keys %option_map ) {
|
for $option ( sort keys %option_map ) {
|
||||||
@matches = grep { /$option:/ } @lines;
|
#print("Checking option: $option\n");
|
||||||
if (@matches < 1) {
|
print $option.": ".$option_map{ $option }."\n";
|
||||||
print STDERR "$option $NOT_FOUND\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print $option.": ".$option_map{ $option }."\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user