Hi Ian,

Policyd v2 / Cluebringer - v2.0.11RC1

Does this percentage get cached anywhere in the db? I’ve cleared out
my session_tracking table and quotas_tracking table and the
percentages are still wildly out:

[2011/03/09-16:18:46 - 9046] [CORE] INFO: module=Quotas, mode=update,
host=83.148.189.2, helo=, [email protected],
[email protected], reason=quota_update, policy=2, quota=258,
limit=258, track=SenderIP:83.148.189.2/32, counter=MessageCount,
quota=259/15 (1726.7%)


I'll get Robert to spin you a patch up to HEAD tomorrow for that branch,
as far as I know he tracked down the issue you having and fixed it.

Please try the attached patches, 0002-Fixed-issues-in-logs-regarding-to-the-quota-usage.patch contains the fix for the issue you're experiencing.

- Robert Anderson
>From e59694fc4c2e092fcb541ea0f952ead682f691dd Mon Sep 17 00:00:00 2001
From: Nigel Kukard <[email protected]>
Date: Sun, 19 Sep 2010 10:23:37 +0000
Subject: [PATCH 1/2] * Allow matching of wildcards in email address specifications
 - Robert Anderson <[email protected]>

---
 cbp/policies.pm |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/cbp/policies.pm b/cbp/policies.pm
index abd9ff2..7b258a4 100644
--- a/cbp/policies.pm
+++ b/cbp/policies.pm
@@ -473,8 +473,23 @@ sub emailAddressMatches
 	my ($email_user,$email_domain) = ($email =~ /^(\S+)@(\S+)$/);
 	my ($template_user,$template_domain) = ($template =~ /^(\S*)@(\S+)$/);
 
-	if (lc($email_domain) eq lc($template_domain) && (lc($email_user) eq lc($template_user) || $template_user eq "")) {
-		$match = 1;
+	# Make sure its all lowercase
+	$template_user = lc($template_user);
+	$template_domain = lc($template_domain);
+
+	# Replace all .'s with \.'s
+	$template_user =~ s/\./\\./g;
+	$template_domain =~ s/\./\\./g;
+
+	# Change *'s into a proper regex expression
+	$template_user =~ s/\*/\\S*/g;
+	$template_domain =~ s/\*/\\S*/g;
+
+	# Check if we have a match
+	if ($email_domain =~ /^$template_domain$/) {
+		if (($email_user =~ $template_user) || $template_user =~ /^$/) {
+			$match = 1;
+		}
 	}
 
 	return $match;
-- 
1.7.3.4

>From 640456aa00ff397abf26e117c0805fa6a4825ffc Mon Sep 17 00:00:00 2001
From: Nigel Kukard <[email protected]>
Date: Tue, 21 Dec 2010 08:05:01 +0000
Subject: [PATCH 2/2] * Fixed issues in logs regarding to the quota usage
 * Fixed issue with quota usage increasing sporadically
 - Robert Anderson <[email protected]>

---
 cbp/modules/Quotas.pm |   48 +++++++++++++++++++++++++-----------------------
 1 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/cbp/modules/Quotas.pm b/cbp/modules/Quotas.pm
index 25e7aac..63333c3 100644
--- a/cbp/modules/Quotas.pm
+++ b/cbp/modules/Quotas.pm
@@ -163,30 +163,32 @@ sub check {
 						# 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($qtrack->{'Counter'}) ?
-									$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
@@ -195,7 +197,7 @@ sub check {
 							# 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";
 								}
 							}
@@ -206,9 +208,10 @@ sub check {
 							$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") {
@@ -247,7 +250,7 @@ sub check {
 			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("
@@ -296,7 +299,7 @@ sub check {
 							$qtrack->{'LimitID'},
 							$qtrack->{'DBKey'},
 							$qtrack->{'LimitType'},
-							sprintf('%.0f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}),
+							sprintf('%.2f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}),
 							$qtrack->{'CounterLimit'},
 							$pused);
 
@@ -315,7 +318,7 @@ sub check {
 							$qtrack->{'LimitID'},
 							$qtrack->{'DBKey'},
 							$qtrack->{'LimitType'},
-							sprintf('%.0f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'QuotasLimitsID'}),
+							sprintf('%.2f',$newCounters{$qtrack->{'QuotasLimitsID'}} + $qtrack->{'Counter'}),
 							$qtrack->{'CounterLimit'},
 							$pused);
 
@@ -329,7 +332,7 @@ sub check {
 		# 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, "
@@ -344,10 +347,9 @@ sub check {
 					$exceededQtrack->{'LimitID'},
 					$exceededQtrack->{'DBKey'},
 					$exceededQtrack->{'LimitType'},
-					sprintf('%.0f',$newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'QuotasLimitsID'}),
+					sprintf('%.2f',$newCounters{$exceededQtrack->{'QuotasLimitsID'}} + $exceededQtrack->{'Counter'}),
 					$exceededQtrack->{'CounterLimit'},
 					$pused);
-
 			$verdict = $exceededQtrack->{'Verdict'};
 			$verdict_data = (defined($exceededQtrack->{'VerdictData'}) && $exceededQtrack->{'VerdictData'} ne "") 
 					? $exceededQtrack->{'VerdictData'} : $hasExceeded;
@@ -411,14 +413,14 @@ sub check {
 							# 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 
 										quotas_tracking
 									SET
-										Counter = ".DBQuote($qtrack->{'Counter'}).",
+										Counter = Counter + ".DBQuote($sessionData->{'Size'}).",
 										LastUpdate = ".DBQuote($now)."
 									WHERE
 										QuotasLimitsID = ".DBQuote($qtrack->{'QuotasLimitsID'})."
@@ -430,7 +432,7 @@ sub check {
 								}
 
 								# 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, "
@@ -444,7 +446,7 @@ sub check {
 										$limit->{'ID'},
 										$key,
 										$limit->{'Type'},
-										sprintf('%.0f',$qtrack->{'Counter'}),
+										sprintf('%.2f',$currentCounter),
 										$limit->{'CounterLimit'},
 										$pused);
 							} # if (lc($limit->{'Type'}) eq "messagecumulativesize")
-- 
1.7.3.4

_______________________________________________
Users mailing list
[email protected]
http://lists.policyd.org/mailman/listinfo/users

Reply via email to