View Full Version : Daily Quota report empty
Moten
7th November 2008, 09:39
Setup using the http://howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu8.04 setup guide.
Getting blank quota reports when running /usr/local/sbin/quota_notify
----------------------------------------------------------------
DAILY QUOTA REPORT:
----------------------------------------------
| % USAGE | ACCOUNT NAME |
----------------------------------------------
--
Company Name
----------------------------------------------------------------
I have one user that is over the limit for sure. They also are getting no alerts.
Where should I look into why this may be happening?
Moten
7th November 2008, 09:46
Here is the file /usr/local/sbin/quota_notify
#!/usr/bin/perl -w
# Author <jps@tntmax.com>
#
# This script assumes that virtual_mailbox_base in defined
# in postfix's main.cf file. This directory is assumed to contain
# directories which themselves contain your virtual user's maildirs.
# For example:
#
# -----------/
# |
# |
# home/vmail/domains/
# | |
# | |
# example.com/ foo.com/
# |
# |
# -----------------
# | | |
# | | |
# user1/ user2/ user3/
# |
# |
# maildirsize
#
use strict;
my $POSTFIX_CF = "/etc/postfix/main.cf";
my $MAILPROG = "/usr/sbin/sendmail -t";
my $WARNPERCENT = 70;
my @POSTMASTERS = ('postmaster@companyname.net');
my $CONAME = 'companyname';
my $COADDR = 'postmaster@companyname.net';
my $SUADDR = 'postmaster@companyname.net';
my $MAIL_REPORT = 1;
my $MAIL_WARNING = 1;
#get virtual mailbox base from postfix config
open(PCF, "< $POSTFIX_CF") or die $!;
my $mboxBase;
while (<PCF>) {
next unless /virtual_mailbox_base\s*=\s*(.*)\s*/;
$mboxBase = $1;
}
close(PCF);
#assume one level of subdirectories for domain names
my @domains;
opendir(DIR, $mboxBase) or die $!;
while (defined(my $name = readdir(DIR))) {
next if $name =~ /^\.\.?$/; #skip '.' and '..'
next unless (-d "$mboxBase/$name");
push(@domains, $name);
}
closedir(DIR);
#iterate through domains for username/maildirsize files
my @users;
chdir($mboxBase);
foreach my $domain (@domains) {
opendir(DIR, $domain) or die $!;
while (defined(my $name = readdir(DIR))) {
next if $name =~ /^\.\.?$/; #skip '.' and '..'
next unless (-d "$domain/$name");
push(@users, {"$name\@$domain" => "$mboxBase/$domain/$name"});
}
}
closedir(DIR);
#get user quotas and percent used
my (%lusers, $report);
foreach my $href (@users) {
foreach my $user (keys %$href) {
my $quotafile = "$href->{$user}/maildirsize";
next unless (-f $quotafile);
open(QF, "< $quotafile") or die $!;
my ($firstln, $quota, $used);
while (<QF>) {
my $line = $_;
if (! $firstln) {
$firstln = 1;
die "Error: corrupt quotafile $quotafile"
unless ($line =~ /^(\d+)S/);
$quota = $1;
last if (! $quota);
next;
}
die "Error: corrupt quotafile $quotafile"
unless ($line =~ /\s*(-?\d+)/);
$used += $1;
}
close(QF);
next if (! $used);
my $percent = int($used / $quota * 100);
$lusers{$user} = $percent unless not $percent;
}
}
#send a report to the postmasters
if ($MAIL_REPORT) {
open(MAIL, "| $MAILPROG");
select(MAIL);
map {print "To: $_\n"} @POSTMASTERS;
print "From: $COADDR\n";
print "Subject: Daily Quota Report.\n";
print "DAILY QUOTA REPORT:\n\n";
print "----------------------------------------------\n";
print "| % USAGE | ACCOUNT NAME |\n";
print "----------------------------------------------\n";
foreach my $luser ( sort { $lusers{$b} <=> $lusers{$a} } keys %lusers ) {
printf("| %3d | %32s |\n", $lusers{$luser}, $luser);
print "---------------------------------------------\n";
}
print "\n--\n";
print "$CONAME\n";
close(MAIL);
}
#email a warning to people over quota
if ($MAIL_WARNING) {
foreach my $luser (keys (%lusers)) {
next unless $lusers{$luser} >= $WARNPERCENT; # skip those under quota
open(MAIL, "| $MAILPROG");
select(MAIL);
print "To: $luser\n";
map {print "BCC: $_\n"} @POSTMASTERS;
print "From: $SUADDR\n";
print "Subject: WARNING: Your mailbox is $lusers{$luser}% full.\n";
print "Reply-to: $SUADDR\n";
print "Your mailbox: $luser is $lusers{$luser}% full.\n\n";
print "Once your e-mail box has exceeded your monthly storage quota\n";
print "your monthly billing will be automatically adjusted.\n";
print "Please consider deleting e-mail from the server or readjusting your download options.\n\n";
print "Contact for further assistance.\n\n";
print "Thank You.\n\n";
print "--\n";
print "$CONAME\n";
close(MAIL);
}
}
And here is the postconfig -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
broken_sasl_auth_clients = yes
config_directory = /etc/postfix
content_filter = amavis:[127.0.0.1]:10024
html_directory = /usr/share/doc/postfix/html
inet_interfaces = all
mailbox_size_limit = 0
mydestination = Albpostfix02.companyname.com, localhost, localhost.localdomain
myhostname = Albpostfix02.companyname.com
mynetworks = 127.0.0.0/8
myorigin = /etc/mailname
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
readme_directory = /usr/share/doc/postfix
receive_override_options = no_address_mappings
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf
virtual_alias_domains =
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf
thecaoticone
7th November 2008, 10:00
I have posted a fix for Gusty that also works for Hardy
http://www.howtoforge.com/forums/showthread.php?t=19765
Moten
7th November 2008, 15:38
I replaced that line and then reloaded and restarted postfix, but still I am getting a blank alert.
User also still not getting the alert.
thecaoticone
7th November 2008, 18:47
Each user should have a maildirsize in their directory that keeps track of the quota info. The problem I found was this file was not there.
As root do the following commands:
updatedblocate maildirsizeYou see somthing like this in the output:
/home/vmail/domain.com/user1/maildirsize
If you open the file in an editor you should see something like this:
26214400S
7309923 766
The 26214400S is the quota limit
The 7309923 is current amount of space used
The 766 is number of emails (sent & received) in the user directory.
If this file or info does not exist, you will continue to receive blank emails.
Moten
10th November 2008, 18:35
The command locate maildirsize returns nothing. I am guessing that would be an issue. Tried searching quickly to find how to resolve, but no luck.
I will keep looking, but if you have an idea for this. Also, I am using virtual users with MySQL. I didn't know if locate maildirsize was trying to look at my user account.
Thanks again.
thecaoticone
11th November 2008, 07:51
After aplying the QuotaPatch to Postfix, Postfix should create this file when the next email arrives. Then every time an email is received (or removed via an imap client), Postfix should update this file.
So the problem should be in Postfix or the QuotaPatch.
The line I change is per the Patch instructions, from their website.
The only thing I can think of, if you did an upgrade, then the original, or newer, version of Postfix may have been installed.
That means the patched version was uninstalled.
Moten
11th November 2008, 19:00
I tried to follow the process to patch the current version 2.5.1
mail_version = 2.5.1
milter_macro_v = $mail_name $mail_version
doesn't appear to hav changed anything, but I got errors at the end of building the package:
mailbox.c: In function āchange_mailbox_limitā:
mailbox.c:90: error: āvirtual_mailbox_limit_mapsā undeclared (first use in this function)
mailbox.c:90: error: (Each undeclared identifier is reported only once
mailbox.c:90: error: for each function it appears in.)
mailbox.c: At top level:
mailbox.c:140: error: redefinition of āchange_mailbox_limitā
mailbox.c:75: error: previous definition of āchange_mailbox_limitā was here
mailbox.c: In function āchange_mailbox_limitā:
mailbox.c:150: error: āvirtual_mailbox_limit_mapsā undeclared (first use in this function)
mailbox.c: At top level:
mailbox.c:174: error: redefinition of āchange_mailbox_limitā
mailbox.c:140: error: previous definition of āchange_mailbox_limitā was here
mailbox.c: In function āchange_mailbox_limitā:
mailbox.c:189: error: āvirtual_mailbox_limit_mapsā undeclared (first use in this function)
make: *** [mailbox.o] Error 1
make: Leaving directory `/usr/src/postfix-2.5.1/src/virtual'
make[1]: *** [update] Error 1
make[1]: Leaving directory `/usr/src/postfix-2.5.1'
make: *** [build] Error 2
It has not been updated and I was fairly sure it was already patched. Where else could I look to find out why this isn't creating the file?
thecaoticone
12th November 2008, 08:05
I tried rebuilding Postfix with the patch per falko's guide. It worked twice without any errors.
If you are sure that the quota patch is in place, then you can try to use my main.cf file. It is straight from the guide with a few spam settings added.
The file is from a working mail server using Ubuntu 8.04 and has delivered quota reports daily since being placed into service June 1, 2008.
Copy your main.cf file to main.cf.old so you can copy it back if needed.
Remove the main.cf file and replace it with the one below.
You will have to change the parts in bold to fit your server name. (I think there are only 2 instances.)
Then reload postfix and send an email to your account on the server.
Then do:
updatedblocate maildirsize If the quota patch is installed and working, you should see something like this:
/home/vmail/your_domain.com/your_user/maildirsize
If you see this then do:
/usr/local/sbin/quota_notify Also remember, if a user has not used 1% of the quota or more, they will not show in the report.
My /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
# myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = /usr/share/doc/postfix
# TLS parameters
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
myhostname = mail.domain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mail.domain.com, localhost, localhost.localdomain
relayhost =
mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
html_directory = /usr/share/doc/postfix/html
virtual_alias_domains =
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf
virtual_create_maildirsize = yes
virtual_maildir_extended = yes
virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = "The user you are trying to reach is over quota."
virtual_overquota_bounce = yes
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
content_filter = amavis:[127.0.0.1]:10024
receive_override_options = no_address_mappings
##SPAM SETTINGS
smtpd_recipient_restrictions =
reject_unauth_pipelining,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_rbl_client bl.spamcop.net
reject_rbl_client zen.spamhaus.org,
reject_rbl_client dnsbl-1.uceprotect.net
reject_rbl_client cbl.abuseat.org
smtpd_sender_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
permit
disable_vrfy_command = yes
smtpd_delay_reject = yes
smtpd_helo_required = yes
smtpd_helo_restrictions =
permit_mynetworks,
permit
smtpd_recipient_limit = 5
smtpd_error_sleep_time = 0s
smtpd_soft_error_limit = 3
smtpd_hard_error_limit = 6
klonos
16th November 2008, 03:13
...
If you open the file in an editor you should see something like this:
26214400S
7309923 766
The 26214400S is the quota limit
The 7309923 is current amount of space used
The 766 is number of emails (sent & received) in the user directory.
If this file or info does not exist, you will continue to receive blank emails.
I was trying to troubleshoot this issue of mine where I'd get negative % for some users in my report.
1. I changed my /etc/postfix/main.cf from:
virtual_mailbox_extended = yesto:
virtual_maildir_extended = yesas suggested in some other thread and run:
/etc/init.d/postfix reload2. I renamed each 'maildirsize' file for each user to 'old.maildirsize'
3. I sent an email to all users.
4. Checked after a while and some of them had the 'maildirsize' file created while others not.
5. Run:
/usr/local/sbin/quota_notifyand got a report that seemed ok.
4. Created a blank 'maildirsize' file for the users that didn't have one.
5. Sent a new mail to all users and run the report script.
6. Got a report that seemed ok again.
7. Checked some of the 'maildirsize' files and some of them had 2 lines for space used and nr of emails. The second line had negative values!?!:
104857600S
135416 62
-1728 -1Any ideas???
falko
16th November 2008, 14:32
http://www.usenet-forums.com/courier-imap/248678-courier-users-enormous-large-mailboxes-quotas-3gb-more-maildirsize.html
That could be because of files > 2GB.
Moten
18th November 2008, 03:39
Must have been something wrong with the files i had downloaded.
I used a different directory, downloaded the source and patch following the guide, installed and all is working perfectly now.
Thanks for the help.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.