store printer data in /tmp if no output directory
[angular-mojolicious.git] / scripts / snmp-printer.pl
index d12504d..035a1ad 100755 (executable)
@@ -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";