X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=syslog-count-link.pl;h=c78ee402c2fe6a0dde14778b0714c8a74bff81cb;hb=d0b195c03803264353181ca8c59a3c10ae52a212;hp=26963cf4ba52ef990186e119a00086141cb4542a;hpb=2d042c326cb42e4e99f9ed9a6aec729c5da2f74c;p=dell-switch diff --git a/syslog-count-link.pl b/syslog-count-link.pl index 26963cf..c78ee40 100755 --- a/syslog-count-link.pl +++ b/syslog-count-link.pl @@ -14,6 +14,8 @@ use Data::Dump qw(dump); use POSIX qw(strftime); my $timeout = $ENV{TIMEOUT} || 60; # forget switch after sec +# timeout should be smaller than stp refresh inverval or +# stp messages will accumulate forever my $name = $0; $name =~ s/.*\/([^\/]+)$/$1/; @@ -39,7 +41,7 @@ sub print_stats { delete $stat->{$host}->{$port}; next; } - my $out = sprintf "%-12s %-4s %-2d %s\n", $host, $port, $dt, $stat->{$host}->{$port}->[1]; + my $out = sprintf "%-12s %-8s %-2d %s\n", $host, $port, $dt, $stat->{$host}->{$port}->[1]; print $out; print $fh $out; } @@ -96,9 +98,9 @@ while(<>) { if ( m/(\S+)\s%LINK-[IW]-(\w+):\s*(\w+)/ ) { my ($host,$state,$port) = ($1,$2,$3); stat_host_port( $host, $port, substr($state,0,1) ); - } elsif ( m/(\S+)\s%STP-W-PORTSTATUS:\s([\w\/]+): STP status (\w+)/ ) { - my ($host,$port,$state) = ($1,$2,$3); - stat_host_port( $host, $port, '-' ); + } elsif ( m/(\S+)\s%STP-W-PORTSTATUS:\s([\w\/]+)(?: of instance \d+)?: STP status (\w+)/ ) { + my ($host,$port,$state) = ($1,$2,substr($3,0,1) ); + stat_host_port( $host, $port, $state =~ m/f/i ? '-' : $state ); ## Dell new @@ -116,6 +118,11 @@ while(<>) { stat_host_port( $host, $port, substr($state,0,1) ); + } elsif ( m/($host_re) TRAPMGR.* %% Spanning Tree Topology Change: (\d+)/ ) { + my ( $host, $state ) = ( $1, $2 ); + stat_host_port( $host, 'STP', $2 ); + + } elsif ( m'==> /var/log/' ) { # ignore tail output next; @@ -124,7 +131,7 @@ while(<>) { next; } - if ( -e "$dir/dump" ) { + if ( -e "$dir/dump" || $ENV{DUMP} ) { print "### ",strftime("%Y-%m-%d %H:%M:%S",localtime(time)), "\n"; print_stats; }