create directories for new printers
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Nov 2010 20:25:22 +0000 (20:25 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Nov 2010 20:25:22 +0000 (20:25 +0000)
bin/snmp-printer.pl

index 428f334..8311c44 100755 (executable)
@@ -6,14 +6,16 @@ use strict;
 
 use SNMP::Multi;
 use Data::Dump qw(dump);
+use File::Path;
 
-my $dir = 'json/printer';
+my $dir = 'conf/ip';
 
 use JSON;
 sub save_json {
        my ( $path, $json ) = @_;
-       $path = "$dir/$path";
-       open(my $fh, '>', $path);
+       mkpath "$dir/$path" unless -d "$dir/$path";
+       $path = "$dir/$path/snmp-printer.json";
+       open(my $fh, '>', $path) || die "$path: $!";
        print $fh encode_json $json;
        close($fh);
        warn "# $path ", -s $path, " bytes\n";
@@ -22,27 +24,7 @@ sub save_json {
 my $debug = $ENV{DEBUG} || 0; 
 
 my $community = 'public';
-my @printers = qw(
-10.60.0.20
-
-10.60.3.15
-10.60.3.17
-
-10.60.3.19
-10.60.3.21
-
-10.60.3.23
-10.60.3.25
-
-10.60.3.27
-10.60.3.29
-
-10.60.3.31
-10.60.3.33
-
-10.60.3.35
-10.60.3.37
-);
+my @printers = map { s{^conf/ip/([0-9\.]+)/.+$}{$1}; $_ } glob 'conf/ip/*/snmp-printer*';
 
 @printers = @ARGV if @ARGV;