fix consumable name
[snmp-json.git] / printer-multi.pl
index 35ad6bc..5d42f15 100755 (executable)
@@ -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;