Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: Get mailbox size (for create quota warning SMTP script)

  1. #1
    inigoml's Avatar
    inigoml is offline Project Contributor
    Join Date
    Aug 2006
    Location
    Madrid, Spain
    Posts
    124
    Rep Power
    8

    Question Get mailbox size (for create quota warning SMTP script)

    Hi Everybody.

    In order to create a home-made script for warning users before quota limit is reached, I would need a method to query mailbox size in server.

    I've evaluated IMAP approach, but it's is very slow cause all code I've found scans full mailbox to get mailbox size.

    Is there any other way to get mailbox size without having to scan folders? Perhaps with a direct mysql query... but I don't have datamodel here.

    Thanks in advance.

  2. #2
    Klug's Avatar
    Klug is offline Moderator
    Join Date
    Mar 2006
    Location
    Beaucaire, France
    Posts
    2,316
    Rep Power
    13

    Default

    Doesn't Zimbra IMAP implementation support "GETQUOTA" ?

  3. #3
    inigoml's Avatar
    inigoml is offline Project Contributor
    Join Date
    Aug 2006
    Location
    Madrid, Spain
    Posts
    124
    Rep Power
    8

    Default Yes, it's...

    Quote Originally Posted by Klug
    Doesn't Zimbra IMAP implementation support "GETQUOTA" ?
    Yes, it's... I'm embarrased

    I will post php script as soon as possible, since I think it's very useful.

  4. #4
    inigoml's Avatar
    inigoml is offline Project Contributor
    Join Date
    Aug 2006
    Location
    Madrid, Spain
    Posts
    124
    Rep Power
    8

    Default IMAP login with admin account

    I've almost finished a PHP script for getting users account.
    However, I cannot login with admin user to other mailboxes but admin one.
    One approach would be resetting user passwords before login, and then restore, but I think it could be a bit dangerous.

    Any suggestion? (zimbra imap server doesn't support adminuser flag).

    ----
    $user=$users[$i];
    $mbox = imap_open("{localhost:993/imap/ssl/novalidate-cert/user=$user/adminuser=admin}", admin, "mypassword", OP_HALFOPEN);

    $quota_values = imap_get_quotaroot($mbox, "INBOX");
    if (is_array($quota_values)) {
    $storage = $quota_values['STORAGE'];
    //echo "Usage:".$storage['usage']."\n";
    //echo "Storage:".$storage['limit']."\n";
    if ($storage['usage'] > $storage['limit']*0.9)
    echo "Storage for user $user over 90%\n";
    else
    echo "Storage for user $user under 90%\n";
    ---

  5. #5
    dkarp is offline Zimbra Employee
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    11

    Default SOAP is *by far* the easiest way

    Easiest way to do this: Get an admin auth token, then issue the GetInfo SOAP request for each user and look for <used> in the response.

    Second-easiest way to do this: Authenticate as the user to IMAP using the admin user/password and AUTH=PLAIN, then issue GETQUOTA.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  6. #6
    schemers is offline Zimbra Employee
    Join Date
    Aug 2005
    Posts
    228
    Rep Power
    9

    Default

    The easieset approach is to simply use zmprov:
    Code:
    $ /opt/zimbra/bin/zmprov gqu localhost
    user1@macpro.local 62914560 7703249
    spam-sink@macpro.local 0 15168
    wiki@macpro.local 0 4996
    admin@macpro.local 0 0
    ham-sink@macpro.local 0 0
    user2@macpro.local 0 0
    user3@macpro.local 0 0
    user4@macpro.local 0 0
    Second column is maximum quote in bytes (0 means unlimited), third column is used quota, in bytes.

    This uses the admin GetQuotaUsageRequest soap call.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  7. #7
    dkarp is offline Zimbra Employee
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    11

    Default Busted!

    Yeah, what Roland said.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  8. #8
    inigoml's Avatar
    inigoml is offline Project Contributor
    Join Date
    Aug 2006
    Location
    Madrid, Spain
    Posts
    124
    Rep Power
    8

    Red face Quota warning script.

    Hi everybody.

    I've created a script for quota checking.
    This script should be launched by zimbra user and it's "crontable".

    It warns everyday when a user reach 90% quota usage, and weekly (on Sunday) when reaching 75%. Please, modify at your own.

    <?php

    $users=array();
    $user=array();
    $return = exec ("zmprov gqu localhost",$users_quota, $status);

    for ($i = 1; $i < count($users_quota); $i++)
    {
    $user['email']=strtok ($users_quota[$i]," ");
    $user['max']= strtok (" ");
    $user['act']= strtok (" ");

    switch ($user['email']) {
    case "kuns1kesoy@vectorsf.com":
    break;
    case "ud2qtlgeld@vectorsf.com":
    break;
    case "beveg2wn@vectorsf.com":
    break;
    case "wiki@vectorsf.com":
    break;
    default:
    if ($user['act'] > $user['max']*0.9) {
    echo "Storage for user ".$user['email']." over 90%\n";
    sendwarning ($user['email'],$user['act'],$user['max'],2);
    }
    else if ($user['act'] > $user['max']*0.75 && $user['act'] < $user['max']*0.90 ) {
    echo "Storage for user ".$user['email']." over 75%\n";
    sendwarning ($user['email'],$user['act'],$user['max'],1);
    }

    }

    }

    function sendwarning ($email,$usage,$maxquota,$warntype)
    {
    $dow = date ("D");
    $to = $email;
    $subject = 'Aviso de utilizacion de cuota de mail';
    $headers = 'From: postmaster@vectorsf.com' . "\r\n" .
    'Reply-To: postmaster@vectorsf.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    if ($warntype == 1 && $dow == "Sun")
    $message = "Tu cuota de correo ha superado el 75% de su asignacion.\nTe recomendamos vayas eliminando o archivando los mensajes mas antiguos para evitar problemas de almacenamiento futuros.\nEn estos momentos estas utilizando ".round($usage/1024/1024)." MB de un total de ".round($maxquota/1024/1024)." MB.\n";
    else if ($warntype == 2)
    $message = "Tu cuota de correo ha superado el 90% de su asignacion.\nTe recomendamos vayas eliminando o archivando los mensajes mas antiguos para evitar problemas de almacenamiento futuros.\nEn estos momentos estas utilizando ".round($usage/1024/1024)." MB de un total de ".round($maxquota/1024/1024)." MB.\n";
    else return;

    mail($to, $subject, $message, $headers);
    }
    ?>

  9. #9
    phoenix is online now Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,483
    Rep Power
    56

    Default

    Nice one, I'll give it a run later. Does it also give the users current quota as well as warnings or is it just a warning at the 75% & 90%? Does it email the user or admin or both - sorry about the questions, I'm not much of a coder.

    Could you stick this in the wiki if you have time?
    Regards


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  10. #10
    zaf
    zaf is offline Partner (VAR/HSP)
    Join Date
    Jan 2006
    Location
    Lafayette, LA
    Posts
    81
    Rep Power
    9

    Default

    I wrote another ugly script in bash to do the same thing. I'll also post it on the wiki

    Code:
    #!/bin/sh
    
    warn_percentage=85
    
    tmpFile=`mktemp`
    
    zmprov gqu localhost > $tmpFile
    
    while read line ; do
        userReport=$line
    
        user=`echo $userReport | cut -f1 -d\ `
        max_quota=`echo $userReport | cut -f2 -d\ `
        used_quota=`echo $userReport | cut -f3 -d\ `
    
        if [ $max_quota -ne 0 ] ; then
    
            quota_percentage=`echo "scale=1; (($used_quota * 100)/ $max_quota)" | bc`
    
            if [ `echo "$quota_percentage >= $warn_percentage" | bc` -eq 1 ] ; then
                max_quota_megs=`echo "scale=1; ($max_quota / 1048576)" | bc`
                echo "You are currently using $quota_percentage% of your mailbox quota of $max_quota_megs megabytes" | mail -s \"Quota Warning - $quota_percentage%\" $user
    
            fi
           
        fi
    
    done < $tmpFile
    
    rm -f tmpFile
    Last edited by zaf; 11-21-2006 at 10:20 AM.

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 210
    Last Post: 01-17-2012, 01:19 AM
  2. need advice on configuring zimbra to work with fax server
    By pheonix1t in forum Administrators
    Replies: 0
    Last Post: 07-11-2007, 07:46 PM
  3. Warning: Unresponsive script
    By yetdog in forum Administrators
    Replies: 5
    Last Post: 04-03-2006, 12:15 PM
  4. Is it started or not
    By kwelipatton in forum Installation
    Replies: 10
    Last Post: 03-28-2006, 11:11 PM
  5. Monitoring : Data not yet avalaible
    By s3nz3x in forum Installation
    Replies: 7
    Last Post: 11-30-2005, 07:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •