5 use Data::Dump qw(dump);
9 my $host_re = '[\w-]+';
10 my $port_re = '[\w/]+';
16 if ( m/(\S+)\s%LINK-[IW]-(\w+):\s*(\w+)/ ) {
17 my ($host,$state,$port) = ($1,$2,$3);
18 $stat->{$host}->{$port} .= substr($state,0,1);
19 $stat->{$host}->{_count}->{$port} += $state =~ m/Up/ ? 1 : -1;
20 } elsif ( m/(\S+)\s%STP-W-PORTSTATUS:\s([\w\/]+): STP status (\w+)/ ) {
21 my ($host,$port,$state) = ($1,$2,$3);
22 $stat->{$host}->{$port} .= '-';
23 $stat->{$host}->{_count}->{$port} += $state =~ m/F/ ? 1 : -1;
27 } elsif ( m/LINK - (\w+) - Hostname: <($host_re)>, ($port_re)/ ) {
28 my ($state, $host, $port ) = ($1,$2,$3);
29 $stat->{$host}->{$port} .= substr($state,0,1);
30 $stat->{$host}->{_count}->{$port} += $state =~ m/U/ ? 1 : -1;
31 } elsif ( m/STP - PORTSTATUS - Hostname: <($host_re)>,($port_re): STP status (\w+)/ ) {
32 my ($host,$port,$state) = ($1,$2,$3);
33 $stat->{$host}->{$port} .= '-';
34 $stat->{$host}->{_count}->{$port} += $state =~ m/F/ ? 1 : -1;
38 warn "IGNORE: [$_]\n";
42 warn "# stat = ", dump($stat);
44 foreach my $host ( sort keys %$stat ) {
45 foreach my $port ( sort {
46 my $a1 = $a; $a1 =~ s/\D+//g;
47 my $b1 = $b; $b1 =~ s/\D+//g;
49 } keys %{ $stat->{$host} } ) {
50 next if $port =~ m/^_/;
51 printf "%s %s:%s %d\n", $host, $port, $stat->{$host}->{$port}, $stat->{$host}->{_count}->{$port};