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/^(d|c)/i ) { # delete/cancel
26 my $job_id = join('/', @ARGV) || die "expected job_id(s) missing";
27 open(my $curl, '-|', "curl --silent -XPOST -d OPR=CANCEL -d JOBS=$job_id/ http://$ip/JOBCTRL.cmd");
32 print join($sep, $ip, $job_id, 'CANCEL', $_),"\n";
37 die "UNKNOWN op [$op]\n";
40 warn "# $ip/$url" if $debug;
41 open(my $curl, '-|', "curl --silent http://$ip/$url");
44 if ( m/var ${var_re}=(.*);/ ) {
47 my $v = eval $json; # this is not valid JSON, but perl's eval doesn't mind
48 warn "## JSON $name $json -> ",dump($v) if $debug > 1;
53 warn "# info=",dump($info) if $debug;
55 if ( exists $info->{spcs} ) {
56 print join($sep, @{ $info->{lbls} }),"\n";
58 my @s = @{ $info->{spcs} };
59 foreach my $i ( 0 .. $#{ $s[1] } ) {
60 $s[1]->[$i] .= ' ' . $info->{adrslbl}->[$i];
62 $s[1] = join(',', @{ $s[1] });
64 print join($sep, @s),"\n";
69 my @headers = @{ $info->{hdrs} };
70 unshift @headers, 'id' if $op eq 'list';
71 unshift @headers, 'IP';
73 print join($sep, @headers),"\n";
75 foreach my $l ( @{ $info->{info} } ) {
76 warn "## l=",dump($l) if $debug > 1;
78 $l->[3] .= ':' . $info->{stats}->[ $l->[3] ];
79 $l->[4] .= ':' . $info->{types}->[ $l->[4] ];
81 print join($sep, $ip, @$l), "\n";
84 foreach my $l ( @{ $info->{jHst} } ) {
85 warn "## l=",dump($l) if $debug > 1;
87 $l->[2] .= ':' . $info->{stsAry}->[ $l->[2] ];
88 $l->[3] .= ':' . $info->{types}->[ $l->[3] ];
90 print join($sep, $ip, @$l),"\n";