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/^e/i ) { # error
27 $var_re = '(lHdr|errLog)';
28 } elsif ( $op =~ m/^(d|c)/i ) { # delete/cancel
29 my $job_id = join('/', @ARGV) || die "expected job_id(s) missing";
30 open(my $curl, '-|', "curl --silent -XPOST -d OPR=CANCEL -d JOBS=$job_id/ http://$ip/JOBCTRL.cmd");
35 print join($sep, $ip, $job_id, 'CANCEL', $_),"\n";
40 die "UNKNOWN op [$op]\n";
43 warn "# $ip/$url" if $debug;
44 open(my $curl, '-|', "curl --silent http://$ip/$url");
47 if ( m/var ${var_re}=(.*);/ ) {
50 my $v = eval $json; # this is not valid JSON, but perl's eval doesn't mind
51 warn "## JSON $name $json -> ",dump($v) if $debug > 1;
56 warn "# info=",dump($info) if $debug;
58 if ( exists $info->{spcs} ) {
59 print join($sep, @{ $info->{lbls} }),"\n";
61 my @s = @{ $info->{spcs} };
62 foreach my $i ( 0 .. $#{ $s[1] } ) {
63 $s[1]->[$i] .= ' ' . $info->{adrslbl}->[$i];
65 $s[1] = join(',', @{ $s[1] });
67 print join($sep, @s),"\n";
71 } elsif ( exists $info->{errLog} ) {
72 print join($sep, @{ $info->{lHdr} }),"\n";
73 foreach my $error ( @{ $info->{errLog} } ) {
74 print join($sep, @{ $error }),"\n";
80 my @headers = @{ $info->{hdrs} };
81 unshift @headers, 'id' if $op eq 'list';
82 unshift @headers, 'IP';
84 print join($sep, @headers),"\n";
86 foreach my $l ( @{ $info->{info} } ) {
87 warn "## l=",dump($l) if $debug > 1;
89 $l->[3] .= ':' . $info->{stats}->[ $l->[3] ];
90 $l->[4] .= ':' . $info->{types}->[ $l->[4] ];
92 print join($sep, $ip, @$l), "\n";
95 foreach my $l ( @{ $info->{jHst} } ) {
96 warn "## l=",dump($l) if $debug > 1;
98 $l->[2] .= ':' . $info->{stsAry}->[ $l->[2] ];
99 $l->[3] .= ':' . $info->{types}->[ $l->[3] ];
101 print join($sep, $ip, @$l),"\n";