summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2009-01-25 01:27:43 +0000
committerivan <ivan>2009-01-25 01:27:43 +0000
commit7d154154ef1f5f2225ebf7802974f6d0bdcddc06 (patch)
tree212b9f139b1c51a5120075bb11ef0fd58c49ee68 /FS
parenta76cf733ec7a6b0175d0394aa0e8ca3765e2abb1 (diff)
add some debugging to RADIUS db calls
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_svc.pm46
1 files changed, 40 insertions, 6 deletions
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index 2d6224c92..30b23908c 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -466,6 +466,8 @@ for records where B<svcdb> is not "svc_acct".
sub seconds_since_sqlradacct {
my($self, $start, $end) = @_;
+ my $mes = "$me seconds_since_sqlradacct:";
+
my $svc_x = $self->svc_x;
my @part_export = $self->part_svc->part_export_usage;
@@ -479,18 +481,26 @@ sub seconds_since_sqlradacct {
next if $part_export->option('ignore_accounting');
+ warn "$mes connecting to sqlradius database\n"
+ if $DEBUG;
+
my $dbh = DBI->connect( map { $part_export->option($_) }
qw(datasrc username password) )
or die "can't connect to sqlradius database: ". $DBI::errstr;
+ warn "$mes connected to sqlradius database\n"
+ if $DEBUG;
+
#select a unix time conversion function based on database type
my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
my $username = $part_export->export_username($svc_x);
my $query;
+
+ warn "$mes finding closed sessions completely within the given range\n"
+ if $DEBUG;
- #find closed sessions completely within the given range
my $sth = $dbh->prepare("SELECT SUM(acctsessiontime)
FROM radacct
WHERE UserName = ?
@@ -502,7 +512,10 @@ sub seconds_since_sqlradacct {
$sth->execute($username, $start, $end) or die $sth->errstr;
my $regular = $sth->fetchrow_arrayref->[0];
- #find open sessions which start in the range, count session start->range end
+ warn "$mes finding open sessions which start in the range\n"
+ if $DEBUG;
+
+ # count session start->range end
$query = "SELECT SUM( ? - $str2time AcctStartTime ) )
FROM radacct
WHERE UserName = ?
@@ -516,7 +529,9 @@ sub seconds_since_sqlradacct {
or die $sth->errstr. " executing query $query";
my $start_during = $sth->fetchrow_arrayref->[0];
- #find closed sessions which start before the range but stop during,
+ warn "$mes finding closed sessions which start before the range but stop during\n"
+ if $DEBUG;
+
#count range start->session end
$sth = $dbh->prepare("SELECT SUM( $str2time AcctStopTime ) - ? )
FROM radacct
@@ -530,9 +545,11 @@ sub seconds_since_sqlradacct {
$sth->execute($start, $username, $start, $start, $end ) or die $sth->errstr;
my $end_during = $sth->fetchrow_arrayref->[0];
- #find closed (not anymore - or open) sessions which start before the range
- # but stop after, or are still open, count range start->range end
- # don't count open sessions (probably missing stop record)
+ warn "$mes finding closed sessions which start before the range but stop after\n"
+ if $DEBUG;
+
+ # count range start->range end
+ # don't count open sessions anymore (probably missing stop record)
$sth = $dbh->prepare("SELECT COUNT(*)
FROM radacct
WHERE UserName = ?
@@ -547,6 +564,9 @@ sub seconds_since_sqlradacct {
$seconds += $regular + $end_during + $start_during + $entire_range;
+ warn "$mes done finding sessions\n"
+ if $DEBUG;
+
}
$seconds;
@@ -566,6 +586,8 @@ for records where B<svcdb> is not "svc_acct".
sub attribute_since_sqlradacct {
my($self, $start, $end, $attrib) = @_;
+ my $mes = "$me attribute_since_sqlradacct:";
+
my $svc_x = $self->svc_x;
my @part_export = $self->part_svc->part_export_usage;
@@ -580,15 +602,24 @@ sub attribute_since_sqlradacct {
next if $part_export->option('ignore_accounting');
+ warn "$mes connecting to sqlradius database\n"
+ if $DEBUG;
+
my $dbh = DBI->connect( map { $part_export->option($_) }
qw(datasrc username password) )
or die "can't connect to sqlradius database: ". $DBI::errstr;
+ warn "$mes connected to sqlradius database\n"
+ if $DEBUG;
+
#select a unix time conversion function based on database type
my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
my $username = $part_export->export_username($svc_x);
+ warn "$mes SUMing $attrib sessions\n"
+ if $DEBUG;
+
my $sth = $dbh->prepare("SELECT SUM($attrib)
FROM radacct
WHERE UserName = ?
@@ -600,6 +631,9 @@ sub attribute_since_sqlradacct {
$sum += $sth->fetchrow_arrayref->[0];
+ warn "$mes done SUMing sessions\n"
+ if $DEBUG;
+
}
$sum;