5 use Data::Dump qw(dump);
7 my $ip = shift @ARGV || '10.60.3.35';
8 my $sep = $ENV{SEP} || "\t";
10 my $stat = { _take => 1 };
12 my $cache = "/dev/shm/$ip.snmp";
15 open($snmp, '<', $cache);
16 warn "# cache $cache";
18 my $cmd = "snmpwalk -v1 -cpublic $ip | tee /dev/shm/$ip.snmp";
20 open($snmp, '-|', $cmd);
32 if ( $stat->{_take} && m/::([^\.]+)\.(.+) = (\w+): (.+)/ ) {
33 my ($name,$id,$type,$val) = ( $1,$2,$3,$4 );
34 $stat->{$id}->{$name} = $val;
35 $stat->{_ids}->{$id}++;
37 if ( $stat->{_order}->[-1] ne $name ) {
38 push @{ $stat->{_order} }, $name;
44 warn "# stat = ",dump($stat);
46 my @order = @{ $stat->{_order} };
47 warn "# order = ",dump( \@order );
49 my @ids = keys %{ $stat->{_ids} };
51 warn "# ids = ",dump( \@ids );
53 print join($sep,'IP', 'ID', @order),"\n";
54 foreach my $id ( @ids ) {
55 print join($sep, $ip, $id, map { $stat->{$id}->{$_} } @order),"\n";