X-Git-Url: http://git.rot13.org/?p=snmp-json.git;a=blobdiff_plain;f=printer-multi.pl;h=5d42f155ec9eb1a24f9694364cbecb2fe6a32ac0;hp=35ad6bc9d34382d29f30571055c4e573a0d9c91d;hb=9c6b66d58c7ae5a2061062f96c8e421ac78b14f3;hpb=a7cb26f717dc97ccae13461b07f3b59e27ff0ab6 diff --git a/printer-multi.pl b/printer-multi.pl index 35ad6bc..5d42f15 100755 --- a/printer-multi.pl +++ b/printer-multi.pl @@ -5,10 +5,22 @@ use strict; use SNMP::Multi; use Data::Dump qw(dump); +use JSON; +sub save_json { + my ( $path, $json ) = @_; + $path = "json/$path"; + open(my $fh, '>', $path); + print $fh encode_json $json; + close($fh); + warn "# $path ", -s $path, " bytes\n"; +} + my $debug = $ENV{DEBUG} || 0; my $community = 'public'; my @printers = qw( +10.60.0.20 + 10.60.3.15 10.60.3.17 @@ -40,6 +52,11 @@ pages iso.3.6.1.2.1.43.10.2.1.4.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_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 +@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 ]; my $oid2name; @@ -67,6 +84,8 @@ warn "# working on: ", join(' ', @printers),$/; my $resp = $sm->execute() or die $sm->error(); +my $collected; + foreach my $host ( $resp->hosts ) { my $status; @@ -114,5 +133,16 @@ foreach my $host ( $resp->hosts ) { } print "$host = ",dump($status); + save_json $host => $status; + $collected->{$host} = $status; +} + +# generate json +my $json; +foreach my $ip ( sort keys %$collected ) { + my $status = $collected->{$ip}; + $status->{ip} = $ip; + push @$json, $status; } +save_json 'printers' => $json;