Apache-SearchEngineLog
view release on metacpan or search on metacpan
Configuration
-------------
Apache::SearchEngineLog is configured using environment variables which
you can set in apache's httpd.conf; An configuration could be:
#in httpd.conf
PerlSetEnv DBI_data_source dbi:driver:dsn
PerlSetEnv DBI_username username
PerlSetEnv DBI_password password
PerlSetEnv DBI_table db_table #optional, defaults to "hits"
PerlSetEnv DBI_timeout seconds #optional, defaults to 120
PerlModule Apache::SearchEngineLog
<Location /test>
PerlLogHandler Apache::SearchEngineLog
</Location>
To ensure a database conenction the database is pinged after DBI_timeout
SearchEngineLog.pm view on Meta::CPAN
# 0: Apache::Log object #
# #
# Returns: #
# 0: true if successfully connected, false otherwise #
##########################################################################
{
my $l = shift;
my $db_source = $ENV{'DBI_data_source'} or $l->error ("Apache::SearchEngineLog: DBI_data_source not defined");
my $db_user = $ENV{'DBI_username'} or $l->error ("Apache::SearchEngineLog: DBI_username not defined");
my $db_passwd = $ENV{'DBI_password'} or $l->error ("Apache::SearchEngineLog: DBI_password not defined");
my $db_table = (defined $ENV{'DBI_table'} ? $ENV{'DBI_table'} : 'hits');
if ($DBH = DBI->connect ($db_source, $db_user, $db_passwd))
{
$l->info ("Apache::SearchEngineLog: Database connection established");
}
else
{
$l->error ('Apache::SearchEngineLog: Unable to connect: ' . DBI->errstr ());
return 0;
SearchEngineLog.pm view on Meta::CPAN
=head1 NAME
Apache::SearchEngineLog - Logging of terms used in search engines
=head1 SYNOPSIS
#in httpd.conf
PerlSetEnv DBI_data_source dbi:driver:dsn
PerlSetEnv DBI_username username
PerlSetEnv DBI_password password
PerlSetEnv DBI_table db_table #optional, defaults to "hits"
PerlSetEnv DBI_timeout seconds #optional, defaults to 120
PerlModule Apache::SearchEngineLog
<Location /test>
PerlLogHandler Apache::SearchEngineLog
</Location>
=head1 DESCRIPTION
analyse.cgi view on Meta::CPAN
sub init
{
die "Need to be run under mod_perl!" unless defined $ENV{'MOD_PERL'};
my $s = Apache->server ();
my $l = $s->log ();
$DB_DSN = $ENV{'DBI_data_source'} or $l->error ("Apache::SearchEngineLog: DBI_data_source not defined");
$DB_USER = $ENV{'DBI_username'} or $l->error ("Apache::SearchEngineLog: DBI_username not defined");
$DB_PASSWD = $ENV{'DBI_password'} or $l->error ("Apache::SearchEngineLog: DBI_password not defined");
$DB_TABLE = (defined $ENV{'DBI_table'} ? $ENV{'DBI_table'} : 'hits');
$DBH = DBI->connect ($DB_DSN, $DB_USER, $DB_PASSWD) or $l->error (DBI->errstr ());
$STHS = {};
$STHS->{'uri'}{'prim'} = $DBH->prepare ("SELECT uri, count(*) AS cnt FROM hits WHERE vhost = ? GROUP BY uri ORDER BY uri ASC");
$STHS->{'uri'}{'secd'} = $DBH->prepare ("SELECT term, count(*) AS cnt FROM hits WHERE vhost = ? AND uri = ? GROUP BY term ORDER BY cnt DESC");
$STHS->{'term'}{'prim'} = $DBH->prepare ("SELECT term, count(*) AS cnt FROM hits WHERE vhost = ? GROUP BY term ORDER BY cnt DESC");
my $list = 0;
my $vhost = '';
my $sort = 'uri';
Getopt::Long::config ('pass_through');
my $result = GetOptions
(
'host|h=s' => \$host,
'db|d=s' => \$db,
'user|u=s' => \$user,
'password|p=s' => \$passwd,
'output|o=s' => \$output,
'type|t=s' => \$type,
'list|l' => \$list,
'vhost|v=s' => \$vhost,
'sort|s=s' => \$sort
);
if (!$db or !$user)
{
die <<EOF;
Usage: $0 --db=<database> [options]
-d <name> --db Name of the database to use (required!)
-t <type> --type Type of the DB (default: mysql)
-h <host> --host Host to connect to (default: localhost)
-u <user> --user User to log into the database
-p <passwd> --password Password to log into the database
-l --list Print list of all vhosts and exit
-v <vhosts> --vhost Commaseperated list of vhosts
-s <uri|term> --sort Sort by either uri or searchterm
-o <file> --output File to write output to
EOF
}
my $DBH = DBI->connect ("DBI:$type:database=$db;host=$host", $user, $passwd) or die DBI->errstr ();
( run in 1.094 second using v1.01-cache-2.11-cpan-49f99fa48dc )