Apache-DBILogger

 view release on metacpan or  search on metacpan

bin/webstat_mail.pl  view on Meta::CPAN


}

sub DoSql {
	my $sqlcommand = shift;
	print "sqlcommand: $sqlcommand\n" if $opts{d};
	my $sth = $dbh->prepare($sqlcommand) 
	  or die "Could not prepare [$DBI::errstr] ($sqlcommand)";
	$sth->execute 
	  or die "Could not execute [$DBI::errstr] ($sqlcommand)";
	
    return $sth;
}

sub readconfigfile {
	my $conffile = $opts{c} || "./webstat.conf";	
	require $conffile;
 	if ($opts{d}) {
	 	#print Data::Dumper->Dump([\%WebStat::Config::server], [qw(server)]);
	 	#print Data::Dumper->Dump([\%WebStat::Config::database], [qw(database)]);
 	}
}


# count hits and traffic
#	 select count(bytes) as hits,sum(bytes) as trafik,server from requests group by server order by hits limit 20 ;


$dbh->disconnect;

undef %WebStat::Config::server;

exit;


sub usage {
    print STDERR <<EOT;
Usage: $0 [options]

Options:
    -d               Debug: print debug information.
	-c /config/file  Select configurationfile
	-t               Show hits for today (only)
	-M               Mail reports (default: print to stdout)
	-T               Test mode, only send mails to the default mail rcpt
    -h               This help
EOT
    exit(1);
}


__END__

# tests with referer stuff
#if ($conf{referer}) {
#	my $host = $conf{host} ? "and host=".$dbh->quote($conf{host}) : "";
#	my $sth = $dbh->prepare("select count(server),urlpath,referer from requests where referer not like ")

 # select count(server) as hits ,urlpath,referer from requests where referer not like CONCAT('http://', server, '%')  order by hits desc limit 10 ;

# THIS worked, I guess...
#my $sqlcommand = qq[select count(server) as hits ,urlpath,referer,server from requests where \
#                  (referer like 'http://%' or referer = '') and not (referer like CONCAT('http://', server, '%') \

# or referer like CONCAT('http://www.hip.dk/%') or referer like CONCAT('http://www.hilleroed-posten.dk/%') ) \
# and server='www.hillerod-posten.dk' group by referer,server order by hits desc limit 10];

while (my $r = $sth->fetchrow_hashref) {
	print qq($r->{hits}, $r->{urlpath}, $r->{referer}\n);		
}









( run in 2.072 seconds using v1.01-cache-2.11-cpan-e1769b4cff6 )