rename jobs script
[safeq] / xwc-jobs.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6
7 my $ip = shift @ARGV || '10.60.3.35';
8 my $debug = $ENV{DEBUG} || 0;
9
10
11 my $op = shift @ARGV || 'list';
12
13 my $url = 'jblist.htm';
14 if ( $op eq 'list' ) {
15         $url = 'jblist.htm';
16 } elsif ( $op eq 'hist' ) {
17         $url = 'jbhist.htm';
18 } else {
19         die "UNKNOWN op [$op]\n";
20 }
21
22 warn "# $ip/$url" if $debug;
23 open(my $curl, '-|', "curl --silent http://$ip/$url");
24 my $info;
25 while(<$curl>) {
26         if ( m/var (stats|types|info|hdrs|stsAry|jHst)=(.*);/ ) {
27                 my $json = $2;
28                 my $v = eval $json; # this is not valid JSON, but perl's eval doesn't mind
29                 #warn "# JSON $json -> ",dump($v);
30                 $info->{$1} = $v;
31         }
32 }
33
34 warn "# info=",dump($info) if $debug;
35
36 my @headers = @{ $info->{hdrs} };
37 unshift @headers, 'id' if $op eq 'list';
38 unshift @headers, 'IP';
39
40 print join("\t", @headers),"\n";
41
42 foreach my $l ( @{ $info->{info} } ) {
43         warn "## l=",dump($l) if $debug > 1;
44         
45         $l->[3] .= ':' . $info->{stats}->[ $l->[3] ];
46         $l->[4] .= ':' . $info->{types}->[ $l->[4] ];
47
48         print join("\t", $ip, @$l), "\n";
49 }
50
51 foreach my $l ( @{ $info->{jHst} } ) {
52         warn "## l=",dump($l) if $debug > 1;
53         
54         $l->[2] .= ':' . $info->{stsAry}->[ $l->[2] ];
55         $l->[3] .= ':' . $info->{types}->[ $l->[3] ];
56
57         print join("\t", $ip, @$l),"\n";
58 }