display xerox job queue by scraping web
[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 open(my $curl, '-|', "curl --silent http://$ip/jblist.htm");
11 my $info;
12 while(<$curl>) {
13         if ( m/var (stats|types|info|hdrs)=(.*);/ ) {
14                 my $json = $2;
15                 my $v = eval $json; # this is not valid JSON, but perl's eval doesn't mind
16                 #warn "# JSON $json -> ",dump($v);
17                 $info->{$1} = $v;
18         }
19 }
20
21 warn "# info=",dump($info) if $debug;
22
23 my $fmt = "%-8s|%-16s|%-16s|%-16s|%-16s|%s\n"; # last should be %d, but this doesn't work for header
24 printf $fmt, 'id', @{ $info->{hdrs} };
25
26 foreach my $l ( @{ $info->{info} } ) {
27         warn "## l=",dump($l) if $debug > 1;
28         
29         printf $fmt,
30                 $l->[0], $l->[1], $l->[2], $info->{stats}->[ $l->[3] ], $info->{types}->[ $l->[4] ], $l->[5];
31 }