some work on logging format
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 13 Aug 2009 12:00:51 +0000 (12:00 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 13 Aug 2009 12:00:51 +0000 (12:00 +0000)
lib/PXElator/dnsd.pm

index b82664f..c6780c0 100644 (file)
@@ -46,13 +46,15 @@ sub reply_handler {
 
        my $ttl = 3600;
 
+       my $audit = { source => 'unknown' };
+
        if ( $local ) {
                warn "local[$local] $qname $qtype";
                $rcode = "NOERROR";
                my $rdata;
                if ( $qtype eq "A" && $local eq "server" ) {
                        $rdata = name_ip( $local, $server::ip );
-                       CouchDB::audit('local', $rdata);
+                       $audit->{source} = 'local';
                } else {
                        $rcode = "NXDOMAIN";
                }
@@ -63,14 +65,14 @@ sub reply_handler {
                        if ( my $rdata = $ptr_cache->{$1} ) {
                                $rdata .= '.' . $server::domain_name;
                                push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
-                               CouchDB::audit('ptr', $rdata );
+                               $audit->{source} = 'PTR';
                        } else {
 warn "## ",dump( $ptr_cache );
                                $rcode = "NXDOMAIN";
                        }
        } elsif ( my $packet = $res->query( $qname, $qtype ) ) {
 
-               CouchDB::audit( 'upstream', $packet );
+               $audit->{source} = 'upstream';
                $packet->print;
                push @ans, $_ foreach $packet->answer;
                $rcode = "NOERROR";
@@ -82,7 +84,10 @@ warn "## ",dump( $ptr_cache );
 
        warn "rcode: $rcode ",dump( @ans );
 
-       CouchDB::audit('response', { rcode => $rcode, ans => [ @ans ], auth => [ @auth ], add => [ @add ] });
+       $audit->{rcode} = $rcode;
+       $audit->{ans} = [ @ans ];
+
+       CouchDB::audit( 'response', $audit );
 
        # mark the answer as authoritive (by setting the 'aa' flag
        return ($rcode, \@ans, \@auth, \@add, { aa => 1 });