X-Git-Url: http://git.rot13.org/?p=angular-mojolicious.git;a=blobdiff_plain;f=scripts%2Fsnmp-printer.pl;h=035a1ad3f8e3f9f10ff158689b2499dd405b1e13;hp=d12504d4d4133f288fc21e787abfe3f1917afba7;hb=c1445b894066b55d757ba690d31b88b0f905586e;hpb=4c716811ae1a0413fa2c75b7c9817b507dc6356d diff --git a/scripts/snmp-printer.pl b/scripts/snmp-printer.pl index d12504d..035a1ad 100755 --- a/scripts/snmp-printer.pl +++ b/scripts/snmp-printer.pl @@ -11,7 +11,7 @@ use SNMP::Multi; use Data::Dump qw(dump); my $dir = 'public/json/monitor/printers'; -die "output directory $dir: $!" unless -d $dir; +$dir = "/tmp/printers-" unless -d $dir; use JSON; sub save_json { @@ -28,12 +28,30 @@ sub iso_datetime { return sprintf "%04d-%02d-%02dT%02d:%02d:%02d", $y+1900, $m, $d, $hh, $mm, $ss; } +my $log_path = join('.', $dir, (split(/T/,iso_datetime,2))[0], 'json'); +open(my $log, '>>', $log_path) || die "$log_path: $!"; + my $debug = $ENV{DEBUG} || 0; my $community = 'public'; my @printers = qw( 10.60.0.20 +10.60.0.40 +10.60.0.41 +10.60.0.42 +10.60.0.43 +10.60.0.44 +10.60.0.45 +10.60.0.46 +10.60.0.47 +10.60.0.48 +10.60.0.49 +10.60.0.50 +10.60.0.51 +10.60.0.52 +10.60.0.53 + 10.60.3.15 10.60.3.17 @@ -150,5 +168,9 @@ foreach my $host ( $resp->hosts ) { print "$host = ",dump($status); save_json $host => $status; $collected->{$host} = $status; + + print $log encode_json($status),"\n"; } +close($log); +warn "# log $log_path ", -s $log_path, " bytes\n";