5 use Data::Dump qw(dump);
7 my $ip = shift @ARGV || '10.60.3.35';
8 my $debug = $ENV{DEBUG} || 0;
9 my $sep = $ENV{SEP} || "\t";
11 my $op = shift @ARGV || 'list';
16 if ( $op =~ m/^l/i ) { # list
18 $var_re = '(stats|types|info|hdrs)';
19 } elsif ( $op =~ m/^h/i ) { # history
21 $var_re = '(hdrs|stsAry|types|jHst)';
22 } elsif ( $op =~ m/^s/i ) { # status
24 $var_re = '(lbls|spcs|adrslbl)';
25 } elsif ( $op =~ m/^t/i ) { # tray
27 $var_re = '(hdrIn|infoIn|hdrOut|infoOut|stsIn)';
28 } elsif ( $op =~ m/^e/i ) { # error
30 $var_re = '(lHdr|errLog)';
31 } elsif ( $op =~ m/^(d|c)/i ) { # delete/cancel
32 my $job_id = join('/', @ARGV) || die "expected job_id(s) missing";
33 open(my $curl, '-|', "curl --silent -XPOST -d OPR=CANCEL -d JOBS=$job_id/ http://$ip/JOBCTRL.cmd");
38 print join($sep, $ip, $job_id, 'CANCEL', $_),"\n";
43 die "UNKNOWN op [$op]\n";
46 warn "# $ip/$url" if $debug;
47 open(my $curl, '-|', "curl --silent http://$ip/$url");
50 if ( m/var ${var_re}=(.*);/ ) {
53 my $v = eval $json; # this is not valid JSON, but perl's eval doesn't mind
54 warn "## JSON $name $json -> ",dump($v) if $debug > 1;
59 warn "# info=",dump($info) if $debug;
61 if ( exists $info->{spcs} ) {
62 print join($sep, @{ $info->{lbls} }),"\n";
64 my @s = @{ $info->{spcs} };
65 foreach my $i ( 0 .. $#{ $s[1] } ) {
66 $s[1]->[$i] .= ' ' . $info->{adrslbl}->[$i];
68 $s[1] = join(',', @{ $s[1] });
70 print join($sep, @s),"\n";
74 } elsif ( exists $info->{errLog} ) {
75 print join($sep, 'IP', @{ $info->{lHdr} }),"\n";
76 foreach my $error ( @{ $info->{errLog} } ) {
77 print join($sep, $ip, @{ $error }),"\n";
81 } elsif ( exists $info->{infoIn} ) {
82 print join($sep, 'IP', @{ $info->{hdrIn} }),"\n";
83 foreach my $row ( @{ $info->{infoIn} } ) {
84 $row->[1] .= ':' . $info->{stsIn}->[$row->[1]];
85 print join($sep, $ip, @$row),"\n";
88 print join($sep, 'IP', @{ $info->{hdrOut} }),"\n";
89 foreach my $row ( @{ $info->{infoOut} } ) {
90 $row->[1] .= ':' . $info->{stsIn}->[$row->[1]];
91 print join($sep, $ip, @$row),"\n";
96 exit 1 if ! defined $info->{hdrs}; # we didn't get expected output
98 my @headers = @{ $info->{hdrs} };
99 unshift @headers, 'id' if $op eq 'list';
100 unshift @headers, 'IP';
102 print join($sep, @headers),"\n";
104 foreach my $l ( @{ $info->{info} } ) {
105 warn "## l=",dump($l) if $debug > 1;
107 $l->[3] .= ':' . $info->{stats}->[ $l->[3] ];
108 $l->[4] .= ':' . $info->{types}->[ $l->[4] ];
110 print join($sep, $ip, @$l), "\n";
113 foreach my $l ( @{ $info->{jHst} } ) {
114 warn "## l=",dump($l) if $debug > 1;
116 $l->[2] .= ':' . $info->{stsAry}->[ $l->[2] ];
117 $l->[3] .= ':' . $info->{types}->[ $l->[3] ];
119 print join($sep, $ip, @$l),"\n";