cyrus quota warner

cyrus logoSometimes live can be so easy: running a cyrus IMAP server on a small box normally includes that you set and maintain Quotas for your customers. Normally everything runs fine – until someone is unable to receive any Emails because his Quota reached the limit. I wrote a small script for this which sends me an Email every time it is executed (via cron):

#!/bin/sh
MAILTO='my@example.com'
LOGFILE='/var/log/imap_quota_warnings.log'
TMPFILE=$(mktemp /tmp/quota_warner.XXXXXX)
TMPFILE2=$(mktemp /tmp/quota_warner2.XXXXXX)
HOST=$(hostname)

cleanup_and_exit(){
    rm "$TMPFILE" "$TMPFILE2"
    exit 0
}

trap cleanup_and_exit 0 1 2 3 7 13 15

su - cyrus -s /bin/sh -c /usr/lib/cyrus/bin/quota | tail +2 | sort -k2nr > "$TMPFILE"

echo "Output from $0 on $HOST: " >> "$TMPFILE2"

while read QUOTA PERCENTAGE ACTUSAGE USER ; do
    LOGIN=${USER/user./}
    if [ -z $USER ]; then
        # no USER (and no ACTUSAGE) means: user has no quota at all
        continue
    fi
    if [ $PERCENTAGE -lt 90 ]; then
        continue
    fi
    if [ $PERCENTAGE -gt 98 ]; then
        DATE=$(date)
        echo "$DATE : $LOGIN is using $ACTKB kb ($PERCENTAGE %) of configured maximum: $QUOTAKB (quota)." >> "$LOGFILE"
    fi
    QUOTAKB=$(echo "$QUOTA/1024" | bc)
    ACTKB=$(echo "$ACTUSAGE/1024" | bc)
    echo "$LOGIN is using $ACTKB kb ($PERCENTAGE %) of configured maximum: $QUOTAKB (quota)." >> "$TMPFILE2"
done < "$TMPFILE"

mail -s "IMAP quota report from $HOST" $MAILTO < "$TMPFILE2"

cleanup_and_exit

Now I just need to look into my mailbox to see who is coming next and asking for more quota 🙂 – and in case there starts a discussion when the mailbox started to fill up, I just need to look into the logfile in /var/log/imap_quota_warnings.log.

Advertisements

About Lars Vogdt

This is the private blog space of Lars Vogdt, the topics will be in first place work related.
This entry was posted in openSUSE, SUSE Linux Enterprise and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s