Results 1 to 2 of 2
Hy guys,
I am using squidalyser for analysing my squid logfiles. I have got it running, finally, but there is one problem. When i select the ' A graph of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-13-2004 #1Just Joined!
- Join Date
- Dec 2003
- Posts
- 70
squid logfile analysis problem
Hy guys,
I am using squidalyser for analysing my squid logfiles. I have got it running, finally, but there is one problem. When i select the ' A graph of activity (per byte)' or the ' A graph of activity (per item accessed)' option, it does not give me any graphs, but when i select the other options that give me text results, it displays them correctly. I have all the required modules installed, along with GD library, with png file support. I checked the httpd logs, and it showed me the error:
This is how the squidparse.pl file looks[Mon Sep 13 21:22:18 2004] [error] [client 127.0.0.1] Can't call method "png" on an undefined value at /var/www/cgi-bin/squidimg.pl line 49., referer: http://localhost/cgi-bin/squidalyser.pl
Any help is welcome... Thank you,#!/usr/bin/perl
use strict;
use DBI;
use Time::ParseDate;
my $t0 = time;
my (%conf, $dbh);
open (CONF, "< /usr/local/squidparse/squidalyser.conf") or die $!;
while (my $line = <CONF>) {
chomp($line);
$line =~ /^\#/ and next;
$line =~ /^$/ and next;
my ($varname, $varvalue) = split(/\s+/, $line);
$conf{$varname} = $varvalue;
}
close CONF;
my $now = localtime();
print qq|
Running $0 at $now
DB Name: $conf{dbname}
DB Host: $conf{dbhost}
DB User: $conf{dbuser}
Squidlog: $conf{squidlog}
|;
dbconnect($conf{dbhost}, $conf{dbname}, $conf{dbuser}, $conf{dbpass});
my $query = 'SELECT MAX(time) FROM logfile';
my $sth = $dbh->prepare($query);
$sth->execute;
my $lastrun = $sth->fetchrow;
$sth->finish;
$query = qq|
INSERT INTO logfile (remotehost,rfc931,authuser,request,status,bytes,t ime)
VALUES ( ? , ? , ? , ? , ?, ? , ? )
|;
$sth = $dbh->prepare($query);
my $count;
open (LOG, "< $conf{squidlog}") or die $!;
while (my $line = <LOG>) {
my $seconds;
if ($line =~ /\s+\[(\d{2,2}.*?)\]\s+/) {
$seconds = parsedate($1);
} else {
$line =~ /^(\d{10,10})\.\d{3,3}/;
$seconds = $1;
}
if ($seconds >= $lastrun) {
my ($remhost, $rfc931, $date, $request, $status, $bytes) = parseline($line);
insertinlog($remhost, $rfc931, $date, $request, $status, $bytes, $line);
$lastrun = $seconds;
$count++;
}
}
&expire_db;
&dbdisconnect;
my $t1 = time;
my $elapsed = $t1 - $t0;
print qq|Took $elapsed seconds to process $count records.\n|;
exit 0;
sub insertinlog {
my ($remhost, $rfc931, $date, $request, $status, $bytes, $line) = @_;
$bytes = 0 unless ($bytes =~ /\d+/);
$status = 0 unless ($status =~ /\d+/);
$sth->execute($remhost,$rfc931,'-',$request,$status,$bytes, $date) or do {
print $line;
print $query;
die $!;
};
$sth->finish;
return;
}
sub parseline {
my $line = shift or return;
my @f = split(/\s+/, $line);
if ($line =~ /^(\d{10,}\.\d{3,3})/) {
# squid logfile format
my $sec = $1;
my $sta = $1 if ($line =~ /TCP.*?\/(\d{3,3})/);
# If we're using NTLM authentication, we have username in DOMAIN\User format,
# so split domain and user (authuser) at \ and store username back in $f[7].
# Patch submitted by Neil M. and hacked a bit by me
I don't use NTLM so if
# you spot an error with this one let me know.
if ($f[7] =~ /\\/) {
my ($domain, $user) = split(/\\/,$f[7]);
if ($conf{include_domain} eq 'y') {
$f[7] = qq|$domain:$user|;
} else {
$f[7] = $user;
}
}
return ($f[2], $f[7], $sec, $f[6], $sta, $f[4]);
} else {
# http logfile format
my $date = "$f[3] $f[4]";
$date =~ s/\[|\]//g;
my $sec = parsedate($date);
$f[6] =~ s/"//g;
print $f[0];
print $f[1];
return ($f[0], $f[1], $sec, $f[6], $f[8], $f[9]);
}
}
sub expire_db {
my ($exp_val, $exp_unit) = split(/\_/, $conf{expire});
unless ($exp_val > 0) {
print qq|Error in config file: `expire $conf{expire}'.\nNo records expired from database.|;
return;
}
if ($exp_unit eq 'h') {
$conf{factor} = 3600;
} elsif ($exp_unit eq 'd') {
$conf{factor} = 86400
} elsif ($exp_unit eq 'w') {
$conf{factor} = 604800;
}
my $nowsec = parsedate($now);
my $expire_before = $nowsec - ($conf{factor} * $exp_val);
my $query = qq|DELETE FROM logfile WHERE time < $expire_before|;
my $sth = $dbh->prepare($query);
$sth->execute or do {
print $query;
die $!;
};
my $rows = $sth->rows;
print qq|\nExpired $rows records from the database.\n|;
}
sub dbconnect {
my ($dbhost, $dbname, $dbuser, $dbpass) = @_;
$dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpa ss) or die (DBI::errstr);
}
sub dbdisconnect {
$sth and $sth->finish;
($dbh and $dbh->disconnect) or die (DBI::errstr);
}
- 09-13-2004 #2Just Joined!
- Join Date
- Dec 2003
- Posts
- 70
next problem
Hello,
I installed the GD.pm module, and it stopped giving me the above error message, but now httpd is giving me the foll error messages:
I checked the path for the existence of the file GD.so, it was there.[Mon Sep 13 22:26:07 2004] [error] [client 127.0.0.1] /usr/bin/perl: error while loading shared libraries: /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi/auto/GD/GD.so: undefined symbol: gdImageGifPtr, referer: http://localhost/cgi-bin/squidalyser.pl
[Mon Sep 13 22:26:07 2004] [error] [client 127.0.0.1] Premature end of script headers: squidimg.pl, referer: http://localhost/cgi-bin/squidalyser.pl
Any suggestions?
Thank You


Reply With Quote
