Commit 121b1658 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Fixed issues in logs regarding to the quota usage

* Fixed issue with quota usage increasing sporadically
- Robert Anderson <randerson@lbsd.net>
parent 8c5abb99
......@@ -167,30 +167,32 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
# Check if we have a queue tracking item
if (defined($qtrack)) {
my $elapsedTime = defined($qtrack->{'LastUpdate'}) ? ( $now - $qtrack->{'LastUpdate'} ) : $quota->{'Period'};
# If elapsed time is less than zero, its time diff between servers, meaning no time has elapsed
$elapsedTime = 0 if ($elapsedTime < 0);
# Check if elapsedTime is longer than period, or negative (time diff between servers?)
my $currentCounter;
if ($elapsedTime > $quota->{'Period'} || $elapsedTime < 0) {
$qtrack->{'Counter'} = 0;
if ($elapsedTime > $quota->{'Period'}) {
$currentCounter = 0;
# Calculate the % of the period we have, and multiply it with the counter ... this should give us a reasonably
# accurate counting
} else {
$currentCounter = ( 1 - ($elapsedTime / $quota->{'Period'}) ) * $qtrack->{'Counter'};
}
# Make sure increment is at least 0
$newCounters{$qtrack->{'QuotasLimitsID'}} = defined($currentCounter) ?
$qtrack->{'Counter'} - $currentCounter : $qtrack->{'Counter'}
if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}}));
# Work out the difference to the DB value, we ONLY DO THIS ONCE!!! so if its defined, leave it alone!
if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}})) {
$newCounters{$qtrack->{'QuotasLimitsID'}} = $currentCounter - $qtrack->{'Counter'};
}
# Limit type
my $limitType = lc($limit->{'Type'});
# Make sure its the MessageCount counter
if ($limitType eq "messagecount") {
# Check for violation
if ($qtrack->{'Counter'} > $limit->{'CounterLimit'}) {
if ($currentCounter > $limit->{'CounterLimit'}) {
$hasExceeded = "Policy rejection; Message count quota exceeded";
}
# Bump up limit
......@@ -199,7 +201,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
# Check for cumulative size violation
} elsif ($limitType eq "messagecumulativesize") {
# Check for violation
if ($qtrack->{'Counter'} > $limit->{'CounterLimit'}) {
if ($currentCounter > $limit->{'CounterLimit'}) {
$hasExceeded = "Policy rejection; Cumulative message size quota exceeded";
}
}
......@@ -210,9 +212,10 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
$qtrack->{'Counter'} = 0;
$qtrack->{'LastUpdate'} = $now;
# Make sure increment is at least 0
$newCounters{$qtrack->{'QuotasLimitsID'}} = $qtrack->{'Counter'}
if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}}));
# Work out the difference to the DB value, we ONLY DO THIS ONCE!!! so if its defined, leave it alone!
if (!defined($newCounters{$qtrack->{'QuotasLimitsID'}})) {
$newCounters{$qtrack->{'QuotasLimitsID'}} = $qtrack->{'Counter'};
}
# Check if this is a message counter
if (lc($limit->{'Type'}) eq "messagecount") {
......@@ -256,7 +259,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
foreach my $qtrack (@trackingList) {
# Percent used
my $pused = sprintf('%.1f', ( ($newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}) / $qtrack->{'CounterLimit'} ) * 100);
my $pused = sprintf('%.1f', ( ($newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}) / $qtrack->{'CounterLimit'} ) * 100);
# Update database
my $sth = DBDo('
......@@ -304,7 +307,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
$qtrack->{'LimitID'},
$qtrack->{'DBKey'},
$qtrack->{'LimitType'},
sprintf('%.0f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}),
sprintf('%.2f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}),
$qtrack->{'CounterLimit'},
$pused);
......@@ -323,7 +326,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
$qtrack->{'LimitID'},
$qtrack->{'DBKey'},
$qtrack->{'LimitType'},
sprintf('%.0f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}),
sprintf('%.2f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}),
$qtrack->{'CounterLimit'},
$pused);
......@@ -337,7 +340,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
# If we have exceeded, set verdict
} else {
# Percent used
my $pused = sprintf('%.1f', ( ($newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'QuotasLimitsID'}) / $exceededQtrack->{'CounterLimit'} ) * 100);
my $pused = sprintf('%.1f', ( ($newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'Counter'}) / $exceededQtrack->{'CounterLimit'} ) * 100);
# Log rejection to mail log
$server->maillog("module=Quotas, action=%s, host=%s, helo=%s, from=%s, to=%s, reason=quota_match, policy=%s, quota=%s, limit=%s, track=%s, "
......@@ -352,7 +355,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'Policy'}}
$exceededQtrack->{'LimitID'},
$exceededQtrack->{'DBKey'},
$exceededQtrack->{'LimitType'},
sprintf('%.0f',$newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'QuotasLimitsID'}),
sprintf('%.2f',$newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'Counter'}),
$exceededQtrack->{'CounterLimit'},
$pused);
......@@ -419,20 +422,20 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'_Recipie
# Check if we're working with cumulative sizes
if (lc($limit->{'Type'}) eq "messagecumulativesize") {
# Bump up counter
$qtrack->{'Counter'} += $sessionData->{'Size'};
my $currentCounter = $qtrack->{'Counter'} + $sessionData->{'Size'};
# Update database
my $sth = DBDo('
UPDATE
@TP@quotas_tracking
SET
Counter = ?,
Counter = Counter + ?,
LastUpdate = ?
WHERE
QuotasLimitsID = ?
AND TrackKey = ?
',
$qtrack->{'Counter'},$now,$qtrack->{'QuotasLimitsID'},$qtrack->{'TrackKey'}
$sessionData->{'Size'},$now,$qtrack->{'QuotasLimitsID'},$qtrack->{'TrackKey'}
);
if (!$sth) {
$server->log(LOG_ERR,"[QUOTAS] Failed to update quota_tracking item: ".awitpt::db::dblayer::Error());
......@@ -440,7 +443,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'_Recipie
}
# Percent used
my $pused = sprintf('%.1f', ( $qtrack->{'Counter'} / $limit->{'CounterLimit'} ) * 100);
my $pused = sprintf('%.1f', ( $currentCounter / $limit->{'CounterLimit'} ) * 100);
# Log update to mail log
$server->maillog("module=Quotas, mode=update, host=%s, helo=%s, from=%s, to=%s, reason=quota_update, policy=%s, "
......@@ -454,7 +457,7 @@ POLICY: foreach my $priority (sort {$a <=> $b} keys %{$sessionData->{'_Recipie
$limit->{'ID'},
$key,
$limit->{'Type'},
sprintf('%.0f',$qtrack->{'Counter'}),
sprintf('%.2f',$currentCounter),
$limit->{'CounterLimit'},
$pused);
} # if (lc($limit->{'Type'}) eq "messagecumulativesize")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment