5 use Data::Dump qw(dump);
10 foreach my $host ( sort keys %$stat ) {
11 foreach my $port ( sort {
12 my $a1 = $a; $a1 =~ s/\D+//g;
13 my $b1 = $b; $b1 =~ s/\D+//g;
16 } keys %{ $stat->{$host} } ) {
17 next if $port =~ m/^_/;
18 printf "%s %s:%s %d\n", $host, $port, $stat->{$host}->{$port}, $stat->{$host}->{_count}->{$port};
27 warn "kill -HUP $$ # to dump stats\n";
29 my $host_re = '[\w-]+';
30 my $port_re = '[\w/]+';
38 if ( m/(\S+)\s%LINK-[IW]-(\w+):\s*(\w+)/ ) {
39 my ($host,$state,$port) = ($1,$2,$3);
40 $stat->{$host}->{$port} .= substr($state,0,1);
41 $stat->{$host}->{_count}->{$port} += $state =~ m/Up/ ? 1 : -1;
42 } elsif ( m/(\S+)\s%STP-W-PORTSTATUS:\s([\w\/]+): STP status (\w+)/ ) {
43 my ($host,$port,$state) = ($1,$2,$3);
44 $stat->{$host}->{$port} .= '-';
45 $stat->{$host}->{_count}->{$port} += $state =~ m/F/ ? 1 : -1;
49 } elsif ( m/LINK - (\w+) - Hostname: <($host_re)>, ($port_re)/ ) {
50 my ($state, $host, $port ) = ($1,$2,$3);
51 $stat->{$host}->{$port} .= substr($state,0,1);
52 $stat->{$host}->{_count}->{$port} += $state =~ m/U/ ? 1 : -1;
53 } elsif ( m/STP - PORTSTATUS - Hostname: <($host_re)>,($port_re): STP status (\w+)/ ) {
54 my ($host,$port,$state) = ($1,$2,$3);
55 $stat->{$host}->{$port} .= '-';
56 $stat->{$host}->{_count}->{$port} += $state =~ m/F/ ? 1 : -1;
59 } elsif ( m'==> /var/log/' ) {
62 warn "IGNORE: [$_]\n";
68 warn "# stat = ", dump($stat);