qmail log parsing with tai64 string support

Developers
vitaly
2005-06-27
2012-10-11
  • vitaly
    vitaly
    2005-06-27

    Hello Everybody,

    Our qmail keep date in the tai64 log format. Unfortunatelly I have not found how awstats processes this and added following code to maillogconvert.pl:

    use POSIX qw(strftime);

    sub _h2i($) {
    my $c = shift;
    my $oc = ord($c);
    my $rv;

    return ($oc - ord('0')) if $c =~ m/\d/;
    return ($oc - ord('A') + 10) if $c =~ m/[A-F]/;
    return ($oc - ord('a') + 10) if $c =~ m/[a-f]/;
    return -1;
    

    }

    sub _t4d($) {
    my $s = shift;
    return 0 unless length($s) == 8;
    my $l = 4;
    my $d = 0;
    for my $ix (0 .. $l2-1) {
    my $pw = 4 * ($l
    2 - $ix - 1);
    my $b = &_h2i(substr($s,$ix,1));
    return 0 if ($b < 0);
    $d |= $b << $pw;
    }
    return $d;
    }

    sub tai64nlocal($) {
    my $tok = shift;
    my $ls;
    if ($tok =~ m/^\@40000000\w+?(\s.+)/) {
    $ls = $1;
    }else {
    return (0,0);
    }
    my $secs = _t4d(substr($tok,9,8));
    my $nano = _t4d(substr($tok,17,8));
    return ($secs == 0) ? '' : strftime("%Y-%m-%d %H:%M:%S",localtime($secs)).$ls;
    }

    and added
    $ = tai64nlocal($);
    before qmail date parsing, inside of "elsif (/starting delivery/)"

    Best
    Vitaly