#!/usr/bin/perl =head1 SYNOPSIS expire_client_stats dbi_credentials =head1 DESCRIPTION Script to expire the per client statistics collected by the client_stats plugin. The counts of all rows are reduces by 10 % and rows which have not been changed for 1 month are removed. This script should be run once per week. NOTE: The intervals of 1 week and 1 month and the factor of 9/10 are rather arbitrary. Feel free to modify them. The following parameters can be passed to expire_client_stats: =over 4 =item dbi_credentials Name of the file which contains the datasource, username and password for the database. The file should only be readable for the qpsmtpd user. Default: none. This parameter must be specified! =back =head1 BUGS =head1 COPYRIGHT AND LICENSE Copyright (c) 2004-2006 Peter J. Holzer This plugin is licensed under the same terms as the qpsmtpd package itself. Please see the LICENSE file included with qpsmtpd for details. =cut use strict; use warnings; use DBI; my $dbh; my @cred = read_cred($ARGV[0]); $dbh = DBI->connect($cred[0], $cred[1], $cred[2], {RaiseError => 0, AutoCommit => 0}); my $rc = $dbh->do("update ipstats set success=floor(success*9/10), permfail=floor(permfail*9/10)"); print STDERR "updated $rc rows\n"; $rc = $dbh->do("delete from ipstats where ts < now() - interval 1 month"); print STDERR "deleted $rc rows\n"; $dbh->commit; $dbh->disconnect; sub read_cred { my ($fn) = @_; open(FN, "<$fn") or die "cannot open $fn: $!"; my $line = ; close(FN); my @cred = split(/[\s\n]/, $line); return @cred; }