added jbhist output with host argument
[safeq] / xq.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
39 print join("\t", @headers),"\n";
40
41 foreach my $l ( @{ $info->{info} } ) {
42         warn "## l=",dump($l) if $debug > 1;
43         
44         $l->[3] = $info->{stats}->[ $l->[3] ];
45         $l->[4] = $info->{types}->[ $l->[4] ];
46
47         print join("\t", @$l), "\n";
48 }
49
50 foreach my $l ( @{ $info->{jHst} } ) {
51         warn "## l=",dump($l) if $debug > 1;
52         
53         $l->[2] = $info->{stsAry}->[ $l->[2] ];
54         $l->[3] = $info->{types}->[ $l->[3] ];
55
56         print join("\t", @$l),"\n";
57 }