collect vlans configured for ports from show vlan
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 5 Jul 2018 09:34:30 +0000 (11:34 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 5 Jul 2018 09:37:17 +0000 (11:37 +0200)
vlan-ports.pl [new file with mode: 0755]

diff --git a/vlan-ports.pl b/vlan-ports.pl
new file mode 100755 (executable)
index 0000000..96a56f5
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use autodie;
+use Data::Dump qw(dump);
+
+# ./vlan-ports.pl ./log/*sw-{dpc,e300}*vlan* | less
+
+my @logs = @ARGV;
+
+my $stat;
+
+foreach my $log ( @logs ) {
+       open(my $log_fh, '<', $log);
+       my $sw = $log; $sw =~ s/^.*?_//; $sw =~ s/_.*$//;
+       while(<$log_fh>) {
+               chomp;
+               if ( m/\s*(\d+)\s+(\S+)\s+([gc]\S+)\s+(\w+)\s+(\w+)/ ) {
+                       my ($vlan,$name,$ports,$type,$authorization) = ( $1,$2,$3,$4,$5 );
+
+                       warn "$sw $vlan $name $ports $type $authorization\n";
+                       $stat->{$sw}->{_vlan_count}->{$vlan}++;
+
+                       while ( $ports =~ s/(ch\([^\)]+\))// ) {
+                               warn "# removed [$1] from ports\n";
+                       }
+
+                       while ( $ports =~ s/(\d+)-(\d+)// ) {
+                               foreach my $port ( $1 .. $2 ) {
+                                       push @{ $stat->{$sw}->{$port} }, $vlan;
+                               }
+                       }
+                       while ( $ports =~ s/(\d+)// ) {
+                               my $port = $1;
+                               push @{ $stat->{$sw}->{$port} }, $vlan;
+                       }
+                       #warn "# ports left:[$ports] stat = ",dump($stat);
+               } else {
+                       warn "INGORED [$_]";
+               }
+       }
+}
+
+print dump($stat);
+