[freeside-commits] freeside/FS/FS cust_svc.pm,1.66.2.9,1.66.2.10
Ivan,,,
ivan at wavetail.420.am
Sat Jan 24 17:27:47 PST 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv19135
Modified Files:
Tag: FREESIDE_1_7_BRANCH
cust_svc.pm
Log Message:
add some debugging to RADIUS db calls
Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.66.2.9
retrieving revision 1.66.2.10
diff -u -d -r1.66.2.9 -r1.66.2.10
--- cust_svc.pm 5 Jun 2008 19:44:30 -0000 1.66.2.9
+++ cust_svc.pm 25 Jan 2009 01:27:44 -0000 1.66.2.10
@@ -460,6 +460,8 @@
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;
@@ -473,18 +475,26 @@
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 = ?
@@ -496,7 +506,10 @@
$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 = ?
@@ -510,7 +523,9 @@
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
@@ -524,9 +539,11 @@
$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 = ?
@@ -541,6 +558,9 @@
$seconds += $regular + $end_during + $start_during + $entire_range;
+ warn "$mes done finding sessions\n"
+ if $DEBUG;
+
}
$seconds;
@@ -560,6 +580,8 @@
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;
@@ -574,15 +596,24 @@
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 = ?
@@ -594,6 +625,9 @@
$sum += $sth->fetchrow_arrayref->[0];
+ warn "$mes done SUMing sessions\n"
+ if $DEBUG;
+
}
$sum;
More information about the freeside-commits
mailing list