Add new directive DNSLookupTimeout to change the default timeout for DNS lookup. Add one second timeout when SquidAnalyzer look for an DNS name. Thanks to alex for the patch.

This commit is contained in:
Darold Gilles 2013-11-26 19:42:21 +01:00
parent c81c111cc4
commit 39051280a8
4 changed files with 49 additions and 2 deletions

6
README
View File

@ -189,6 +189,12 @@ CONFIGURATION
DNS name instead. Note that you must have a working DNS resolution DNS name instead. Note that you must have a working DNS resolution
and that it can really slow down the generation of reports. and that it can really slow down the generation of reports.
DNSLookupTimeout 1
If you have enabled UseClientDNSName and have lot of ip addresses
that do not resolve you may want to increase the DNS lookup timeout.
By default SquidAnalyzer will stop to lookup a DNS name after one
second.
NetworkAlias network-aliases_file NetworkAlias network-aliases_file
Set path to the file containing network alias name. Network are show Set path to the file containing network alias name. Network are show
as Ip addresses so if you want to display name instead create a file as Ip addresses so if you want to display name instead create a file

View File

@ -36,6 +36,9 @@ $ZCAT_PROG = "/bin/zcat";
$BZCAT_PROG = "/bin/bzcat"; $BZCAT_PROG = "/bin/bzcat";
$RM_PROG = "/bin/rm"; $RM_PROG = "/bin/rm";
# DNS Cache
my %CACHE = {};
# Default translation srings # Default translation srings
my %Translate = ( my %Translate = (
'CharSet' => 'utf-8', 'CharSet' => 'utf-8',
@ -451,6 +454,7 @@ sub _init
$self->{TopUrlUser} = $options{TopUrlUser} || 0; $self->{TopUrlUser} = $options{TopUrlUser} || 0;
$self->{no_year_stat} = 0; $self->{no_year_stat} = 0;
$self->{UseClientDNSName} = $options{UseClientDNSName} || 0; $self->{UseClientDNSName} = $options{UseClientDNSName} || 0;
$self->{DNSLookupTimeout} = $options{DNSLookupTimeout} || 1;
if ($self->{Lang}) { if ($self->{Lang}) {
open(IN, "$self->{Lang}") or die "ERROR: can't open translation file $self->{Lang}, $!\n"; open(IN, "$self->{Lang}") or die "ERROR: can't open translation file $self->{Lang}, $!\n";
@ -601,6 +605,32 @@ sub _init
} }
sub _gethostbyaddr
{
my ($self, $ip) = @_;
return $ip unless $ip=~/\d+\.\d+\.\d+\.\d+/;
my $host = undef;
unless(exists $CACHE{$ip}) {
eval {
local $SIG{ALRM} = sub { die "timeout\n" };
alarm $self->{DNSLookupTimeout};
$host = gethostbyaddr(inet_aton($ip), AF_INET);
alarm 0;
};
if ($@) {
$CACHE{$ip} = undef;
#printf "_gethostbyaddr timeout : %s\n", $ip;
}
else {
$CACHE{$ip} = $host;
#printf "_gethostbyaddr success : %s (%s)\n", $ip, $host;
}
}
return $CACHE{$ip} || $ip;
}
sub _parseData sub _parseData
{ {
my ($self, $time, $elapsed, $client, $code, $bytes, $url, $id, $type) = @_; my ($self, $time, $elapsed, $client, $code, $bytes, $url, $id, $type) = @_;
@ -636,7 +666,7 @@ sub _parseData
# (login is equal to ip) and if client is an ip address # (login is equal to ip) and if client is an ip address
if ( ($id eq $client) && $self->{UseClientDNSName}) { if ( ($id eq $client) && $self->{UseClientDNSName}) {
if ($client =~ /^\d+\.\d+\.\d+\.\d+$/) { if ($client =~ /^\d+\.\d+\.\d+\.\d+$/) {
my $dnsname = gethostbyaddr(inet_aton($client), AF_INET); my $dnsname = $self->_gethostbyaddr($client);
if ($dnsname) { if ($dnsname) {
$id = $dnsname; $id = $dnsname;
} }

View File

@ -199,6 +199,12 @@ the client ip address, this allow you to use the DNS name instead.
Note that you must have a working DNS resolution and that it can really slow Note that you must have a working DNS resolution and that it can really slow
down the generation of reports. down the generation of reports.
=item DNSLookupTimeout 1
If you have enabled UseClientDNSName and have lot of ip addresses that do not
resolve you may want to increase the DNS lookup timeout. By default SquidAnalyzer
will stop to lookup a DNS name after one second.
=item NetworkAlias network-aliases_file =item NetworkAlias network-aliases_file
Set path to the file containing network alias name. Network are Set path to the file containing network alias name. Network are

View File

@ -124,7 +124,7 @@
.\" ======================================================================== .\" ========================================================================
.\" .\"
.IX Title "SQUIDANALYZER 1" .IX Title "SQUIDANALYZER 1"
.TH SQUIDANALYZER 1 "2013-09-04" "perl v5.14.2" "User Contributed Perl Documentation" .TH SQUIDANALYZER 1 "2013-11-26" "perl v5.14.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents. .\" way too many mistakes in technical documents.
.if n .ad l .if n .ad l
@ -330,6 +330,11 @@ thisA\*^\ directive. When you don't have authentication, the username is set to
the client ip address, this allow you to use the \s-1DNS\s0 name instead. the client ip address, this allow you to use the \s-1DNS\s0 name instead.
Note that you must have a working \s-1DNS\s0 resolution and that it can really slow Note that you must have a working \s-1DNS\s0 resolution and that it can really slow
down the generation of reports. down the generation of reports.
.IP "DNSLookupTimeout 1" 4
.IX Item "DNSLookupTimeout 1"
If you have enabled UseClientDNSName and have lot of ip addresses that do not
resolve you may want to increase the \s-1DNS\s0 lookup timeout. By default SquidAnalyzer
will stop to lookup a \s-1DNS\s0 name after one second.
.IP "NetworkAlias network\-aliases_file" 4 .IP "NetworkAlias network\-aliases_file" 4
.IX Item "NetworkAlias network-aliases_file" .IX Item "NetworkAlias network-aliases_file"
Set path to the file containing network alias name. Network are Set path to the file containing network alias name. Network are