chiark / gitweb /
3ff6b72140d056b24e11f9b258cc75cd754fca6b
[rrd-graphs.git] / newstailer
1 #!/usr/bin/perl -w
2
3 use strict qw(refs vars);
4 use POSIX;
5
6 use IO::Handle;
7 use IO::File;
8 use File::Tail;
9 use Parse::Syslog;
10
11 die unless @ARGV;
12 die if $ARGV[0] =~ m/^\-/;
13
14 my $totail= pop @ARGV;
15
16 sub run ($) {
17     my ($object) = @_;
18     my $parser= new Parse::Syslog $object, repeat=>0, arrayref=>1;
19     while (my $sl= $parser->next) {
20         print join("|", @$sl), "\n";
21     }
22 }
23
24 foreach my $staticpath (@ARGV) {
25     if ($staticpath =~ m/\.gz$/) {
26         my $fh= new IO::Handle;
27         open $fh, '-|', 'gunzip', '--', $staticpath or die $!;
28         run($fh);
29         !$fh->error or die "$staticpath $!";
30         $!=0;$?=0; close $fh or die "$staticpath $! $?";
31     } else {
32         my $fh= new IO::File '<', $staticpath or die $!;
33         run($staticpath);
34         !$fh->error or die "$staticpath $!";
35         close $fh or die "$staticpath $!";
36     }
37 }
38
39 my $tailer= new File::Tail name=>$totail,
40     interval=>60, adjustafter=>2, ignore_nonexistant=>1, tail=>-1
41     or die "$totail $!";
42
43 run($tailer);
44
45 die "huh?";