From: Dobrica Pavlinusic Date: Fri, 26 Nov 2010 18:55:03 +0000 (+0100) Subject: save json files X-Git-Url: http://git.rot13.org/?p=snmp-json.git;a=commitdiff_plain;h=4501e42e1692c6a8343baca7ef00e01b701ca86f save json files --- diff --git a/printer-multi.pl b/printer-multi.pl index 0fbb329..5d42f15 100755 --- a/printer-multi.pl +++ b/printer-multi.pl @@ -6,12 +6,21 @@ use SNMP::Multi; use Data::Dump qw(dump); use JSON; -my $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 @@ -124,6 +133,7 @@ foreach my $host ( $resp->hosts ) { } print "$host = ",dump($status); + save_json $host => $status; $collected->{$host} = $status; } @@ -134,5 +144,5 @@ foreach my $ip ( sort keys %$collected ) { $status->{ip} = $ip; push @$json, $status; } -open(my $fh, '>', 'printer.json'); -print $fh encode_json $json; +save_json 'printers' => $json; +