X-Git-Url: http://git.rot13.org/?p=snmp-json.git;a=blobdiff_plain;f=printer-callbacks.pl;h=f17353015dcaebc3dc2d77648016b6fddffa7433;hp=43816dc0e46b4dd53bd731ee99590fa7d196bfc4;hb=cc8da7199ac7b19e9dca9024646033e291b5530c;hpb=1b5651a953a30d912a7ba1552a3e1cefd3d42190 diff --git a/printer-callbacks.pl b/printer-callbacks.pl index 43816dc..f173530 100755 --- a/printer-callbacks.pl +++ b/printer-callbacks.pl @@ -23,14 +23,14 @@ hostname iso.3.6.1.2.1.43.5.1.1.16.1 serial iso.3.6.1.2.1.43.5.1.1.17.1 pages iso.3.6.1.2.1.43.10.2.1.4.1 @message iso.3.6.1.2.1.43.18.1.1.8 -@consumable_name iso.3.6.1.2.1.43.11.1.1.6.1.1 -@consumable_max iso.3.6.1.2.1.43.11.1.1.8.1 -@consumable_curr iso.3.6.1.2.1.43.11.1.1.9.1 -@tray_dim_x iso.3.6.1.2.1.43.8.2.1.4.1 -@tray_dim_y iso.3.6.1.2.1.43.8.2.1.5.1 -@tray_max iso.3.6.1.2.1.43.8.2.1.9.1 -@tray_capacity iso.3.6.1.2.1.43.8.2.1.10.1 -@tray_name iso.3.6.1.2.1.43.8.2.1.13.1 +@consumable.name iso.3.6.1.2.1.43.11.1.1.6.1 +@consumable.max iso.3.6.1.2.1.43.11.1.1.8.1 +@consumable.curr iso.3.6.1.2.1.43.11.1.1.9.1 +@tray.dim_x iso.3.6.1.2.1.43.8.2.1.4.1 +@tray.dim_y iso.3.6.1.2.1.43.8.2.1.5.1 +@tray.max iso.3.6.1.2.1.43.8.2.1.9.1 +@tray.capacity iso.3.6.1.2.1.43.8.2.1.10.1 +@tray.name iso.3.6.1.2.1.43.8.2.1.13.1 ]; our $response; @@ -47,12 +47,19 @@ sub columns_cb { warn "# $oid $name var_bind_list ", dump( $session->var_bind_list ); my $results = $session->var_bind_list; - while ( my ($r_oid,$val) = each %$results ) { + foreach my $r_oid ( sort { + my ($af,$bf) = ($a,$b); + $af =~ s{\.(\d+)$}{sprintf("%03d",$1)}eg; + $bf =~ s{\.(\d+)$}{sprintf("%03d",$1)}eg; + $af cmp $bf + } keys %$results ) { + my $var = $results->{$r_oid}; if ( $name =~ m{^\@} ) { - my $offset = $1 - 1 if $r_oid =~ m{^\Q$oid\E\.?(\d+)}; - $response->{ $session->hostname }->{ $name }->[ $offset ] = $results->{$r_oid}; + my $no_prefix = $name; + $no_prefix =~ s{^\@}{}; + push @{ $response->{ $session->hostname }->{ $no_prefix } }, $var; } else { - $response->{ $session->hostname }->{ $name } = $results->{$r_oid}; + $response->{ $session->hostname }->{ $name } = $var; } } } @@ -88,4 +95,16 @@ foreach my $host ( @printers ) { warn "# dispatch requests for ",dump(@printers); snmp_dispatcher; -print dump($response); +foreach my $ip ( keys %$response ) { + + my $status = $response->{$ip}; + foreach my $group ( grep { /\w+\.\w+/ } keys %$status ) { + my ( $prefix,$name ) = split(/\./,$group,2); + foreach my $i ( 0 .. $#{ $status->{$group} } ) { + $status->{$prefix}->[$i]->{$name} = $status->{$group}->[$i]; + } + delete $status->{$group}; + } + + print "$ip ",dump($status); +}