Apache-DBILogger
view release on metacpan or search on metacpan
DBILogger.pm view on Meta::CPAN
$Apache::DBILogger::revision = sprintf("%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/o);
$Apache::DBILogger::VERSION = "0.93";
sub reconnect($$) {
my ($dbhref, $r) = @_;
$$dbhref->disconnect;
$r->log_error("Reconnecting to DBI server");
$$dbhref = DBI->connect($r->dir_config("DBILogger_data_source"), $r->dir_config("DBILogger_username"), $r->dir_config("DBILogger_password"));
unless ($$dbhref) {
$r->log_error("Apache::DBILogger could not connect to ".$r->dir_config("DBILogger_data_source")." - ".$DBI::errstr);
return DECLINED;
}
}
sub logger {
my $r = shift->last;
DBILogger.pm view on Meta::CPAN
'timeserved'=> time2str("%Y-%m-%d %X", time),
'contenttype' => $r->content_type || ''
);
if (my $user = $c->user) {
$data{user} = $user;
}
$data{usertrack} = $r->notes('cookie') || '';
my $dbh = DBI->connect($r->dir_config("DBILogger_data_source"), $r->dir_config("DBILogger_username"), $r->dir_config("DBILogger_password"));
unless ($dbh) {
$r->log_error("Apache::DBILogger could not connect to ".$r->dir_config("DBILogger_data_source")." - ".$DBI::errstr);
return DECLINED;
}
my @valueslist;
foreach (keys %data) {
$data{$_} = $dbh->quote($data{$_});
DBILogger.pm view on Meta::CPAN
Apache::DBILogger - Tracks what's being transferred in a DBI database
=head1 SYNOPSIS
# Place this in your Apache's httpd.conf file
PerlLogHandler Apache::DBILogger
PerlSetVar DBILogger_data_source DBI:mysql:httpdlog
PerlSetVar DBILogger_username httpduser
PerlSetVar DBILogger_password secret
PerlSetvar DBILogger_table requests
Create a database with a table named B<requests> like this:
CREATE TABLE requests (
server varchar(127) DEFAULT '' NOT NULL,
bytes mediumint(9) DEFAULT '0' NOT NULL,
user varchar(15) DEFAULT '' NOT NULL,
filename varchar(200) DEFAULT '' NOT NULL,
remotehost varchar(150) DEFAULT '' NOT NULL,
NAME
Apache::DBILogger - Tracks what's being transferred in a DBI
database
SYNOPSIS
# Place this in your Apache's httpd.conf file
PerlLogHandler Apache::DBILogger
PerlSetVar DBILogger_data_source DBI:mysql:httpdlog
PerlSetVar DBILogger_username httpduser
PerlSetVar DBILogger_password secret
Create a database with a table named B<requests> like this:
CREATE TABLE requests ( id mediumint(9) DEFAULT '0' NOT NULL
auto_increment, server varchar(127) DEFAULT '' NOT NULL, bytes
mediumint(9) DEFAULT '0' NOT NULL, user varchar(15), filename
varchar(200), remotehost varchar(150), remoteip varchar(15)
DEFAULT '' NOT NULL, status smallint(6) DEFAULT '0' NOT NULL,
timeserved datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
urlpath varchar(200) DEFAULT '' NOT NULL, referer varchar(250),
bin/moverows.pl view on Meta::CPAN
sub sqldo {
my $sqlcommand = shift;
my $sth = $dbh->prepare($sqlcommand);
die "Could not prepare [$DBI::errstr] ($sqlcommand)" unless $sth;
my $rv = $sth->execute;
die "Could not execute [$DBI::errstr] ($sqlcommand)" unless $rv;
$sth->finish;
}
$dbh = DBI->connect("DBI:$WebStat::Config::database{driver}:$WebStat::Config::database{database}:$WebStat::Config::database{host}", "$WebStat::Config::database{user}", "$WebStat::Config::database{password}" );
die "Cannot connect to database: $DBI::errstr ($!)" unless $dbh;
sqldo("LOCK TABLES requests WRITE, requests_insert WRITE");
sqldo("insert into requests select * from requests_insert");
sqldo("delete from requests_insert");
sqldo("UNLOCK TABLES");
$dbh->disconnect;
bin/webstat.conf view on Meta::CPAN
# Only 'default' mail rcpt's will get mail in test (-T) mode
#
package WebStat::Config;
use vars qw(%server %database);
%database = (
driver => 'mysql',
host => 'ratatosk',
user => 'stats',
password => 'seeekrit',
database => 'httpdlog',
table => 'requests'
);
$server{default} = {
mail => {
frequency => "daily",
rcpt => [qw(ask@netcetera.dk)],
from => 'netpasser@netcetera.dk'
}
bin/webstat_mail.pl view on Meta::CPAN
use vars qw(%opts %conf);
use Getopt::Std;
use Data::Dumper;
use Date::Format;
use Net::SMTP;
getopts("dtc:MTh", \%opts);
&usage if ($opts{h});
&readconfigfile;
my $dbh = DBI->connect("DBI:$WebStat::Config::database{driver}:$WebStat::Config::database{database}:$WebStat::Config::database{host}", "$WebStat::Config::database{user}", "$WebStat::Config::database{password}" );
die "Cannot connect to database: $DBI::errstr ($!)" unless $dbh;
$dbh->do("set SQL_BIG_TABLES=1");
# for each server: do something..
while( my ($server, $serverconfig) = each %WebStat::Config::server) {
next if ($server eq "default");
print "$server\n" if $opts{d};
#print Data::Dumper->Dump([\$serverconfig], [qw($serverconfig)]) if $opts{d};
bin/webstat_resolver.pl view on Meta::CPAN
my $sqlcommand = shift;
# print "$sqlcommand\n";
# return;
my $sth = $dbh->prepare($sqlcommand);
die "Could not prepare [$DBI::errstr] ($sqlcommand)" unless $sth;
my $rv = $sth->execute;
die "Could not execute [$DBI::errstr] ($sqlcommand)" unless $rv;
$sth->finish;
}
$dbh = DBI->connect("DBI:$WebStat::Config::database{driver}:$WebStat::Config::database{database}:$WebStat::Config::database{host}", "$WebStat::Config::database{user}", "$WebStat::Config::database{password}" );
die "Cannot connect to database: $DBI::errstr ($!)" unless $dbh;
my $table = "requests_insert";
my $sth = $dbh->prepare(qq[select remoteip from $table \
where remotehost = '' group by remoteip]);
die "Could not prepare [$DBI::errstr]" unless $sth;
my $rv = $sth->execute;
die "Could not execute [$DBI::errstr]" unless $rv;
( run in 0.691 second using v1.01-cache-2.11-cpan-49f99fa48dc )