Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

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

  1. #11
    labynocle is offline Senior Member
    Join Date
    Jan 2007
    Location
    France - Paris 18
    Posts
    50
    Rep Power
    8

    Post perl version

    Hi there,

    I did my own little script that allow users to be alerted when users are too close to their limit.
    You can set-up thresholds to determine when a user is in a warning, critical or ok state.

    This script is, I think, ideal for a cronjob.

    example :
    ./quota_zimbra.pl -warning 87 -critical 90 -mail yes

    more information
    ./quota_zimbra.pl --help

    I hope it could be usefull for some administrators

    The code :
    Code:
    #!/usr/bin/perl
    
    # quota_zimbra.pl : 	this perl script allows the user to know if his current mail quota is a warning state...
    #									the state is determinated by the thresholds (in percent) you set
    #
    #		v0.1		2007-04-24		: first version by Erwan Ben Souiden : erwan<at>weborama.fr
    
    use strict;
    use Getopt::Long;
    
    ##############################
    # DON T FORGET TO MODIFY LIKE YOU WANT
    
    # mailto value and mailfrom value
    my $mailfrom = "you\@domain.com";
    
    # message_critical value and message_warning value
    my $message_critical = "Your mailbox is in a critical state... please make some space or you will regret it ! mouhahahaaaaa.\nYour dear funky administrator";
    my $message_warning = "Your mailbox is in a warning state...please make some space.\nYour dear funky administrator";
    
    # debug value
    my $debug = 1;
    
    #############################
    
    # the commands you need !
    my $command = '/opt/zimbra/bin/zmprov gqu localhost';
    
    my ($mail_warn, $mail_crit);
    
    my ($mail, $warning, $critical);
    my ($nom, $quota, $used);
    my $c_all = 0;
    my $c_warn = 0;
    my $c_crit = 0;
    my @result;
    
    # help
    if ($ARGV[0] =~ /^-h|^--help|^-H/){
      print " *** quota_zimbra.pl *** \n";
      print_usage();
    }
    
    # options
    GetOptions ('mail=s' => \$mail,
    	    'warning=s' => \$warning,
    	    'critical=s' => \$critical
    	   );
    
    # default values
    $warning =  "85" if ($warning eq "");
    $critical =  "90" if ($critical eq "") ;
    $mail =  "no" if ($mail eq "");
    
    # conditions
    if ( ($mail ne "no") && ($mail ne "yes") ) {
    	print "ERROR : the mail value must be 'yes' or 'no'\n";
    	print_usage();
    }
    if ( ($critical < $warning)  || ($critical < 0) || ($warning < 0) || ($warning > 100) || ($critical > 100) ) {
    	 print "ERROR : the critical threshold must be higher than the warning threshold. And both value must be higher than 0 and smaller than 100\n";
    	 print_usage();
    }
    
    # the script
    @result = `$command`;
    foreach (@result) {
    	($nom, $quota, $used) = split(/ /,$_);
    	$c_all ++;
    	if ($quota eq "0") {
    		print "INFO : $nom has no quota restriction\n" if ($debug);
    		next;
    	}
    	$used = ($used / $quota) *100;
    	if ( ($used >= $warning) && ($used < $critical) ) {
    		$c_warn ++;
    		print "WARNING : $nom is in a warning state\n";
    		$mail_warn  = '/usr/bin/printf "%b" "To:$nom \nSubject: Zimbra Quota \n'.$message_warning.'" | /usr/sbin/sendmail -t -F'.$mailfrom;
    		`$mail_warn` if ($mail eq "yes");
    	}
    	elsif ($used >= $critical) {
    		$c_crit ++;
    		print "CRITICAL : $nom is in a critical state\n";
    		$mail_crit = '/usr/bin/printf "%b" "To:$nom \nSubject: Zimbra Quota \n'.$message_critical.'" | /usr/sbin/sendmail -t -F'.$mailfrom;
    		`$mail_crit` if ($mail eq "yes");
    	}
    	else {
    		print "INFO : $nom is ok !\n" if ($debug);
    	}
    }
    
    if ($debug) {
    	print "\n*******\nINFO : Stats from quota_zimbra.pl\n";
    	print "INFO : $c_crit users in a critical state\n";
    	print "INFO : $c_warn users in a critical state\n";
    	print "INFO : There are $c_all zimbra users\n";
    }
    exit(0);
    
    # function 1 :  display the help 
    sub print_usage()
    {
      print "Utilisation: ./quota_zimbra.pl -mail [yes | no] -warning 85 -critical 90\n";
      print "Options:\n";
      print "\t-mail [yes | no]\n";
      print "\t\tif you want to disable the mail report to the user please. The default value is 'no'\n";
      print "\t-warning INTEGER\n";
      print "\t\tallow you to set up the warning threshold. The default value is 85\n";
      print "\t-critical INTEGER\n";
      print "\t\tallow you to set up the critical threshold. The default value is 90\n";
      exit(0);
    }
    Aleikoum ne mesure pas le web !
    Run, run... ruuuuuuuun !

  2. #12
    phoenix is online now Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,505
    Rep Power
    57

    Default

    Another nice script. Could you add it to the wiki with the other quota script?
    Regards


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  3. #13
    labynocle is offline Senior Member
    Join Date
    Jan 2007
    Location
    France - Paris 18
    Posts
    50
    Rep Power
    8

    Default

    yep ! of course !
    Aleikoum ne mesure pas le web !
    Run, run... ruuuuuuuun !

  4. #14
    labynocle is offline Senior Member
    Join Date
    Jan 2007
    Location
    France - Paris 18
    Posts
    50
    Rep Power
    8

    Post wiki !

    I create my first wiki page : http://wiki.zimbra.com/index.php?title=Quota_Warnings

    I will update the script as soon as possible !
    Aleikoum ne mesure pas le web !
    Run, run... ruuuuuuuun !

  5. #15
    phoenix is online now Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,505
    Rep Power
    57

    Default

    Thanks for doing that.
    Regards


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  6. #16
    labynocle is offline Senior Member
    Join Date
    Jan 2007
    Location
    France - Paris 18
    Posts
    50
    Rep Power
    8

    Default

    Thanks to Rick van der Zwet, we update the quota warning script as you can see here :
    Quota Warnings - ZimbraWiki
    Aleikoum ne mesure pas le web !
    Run, run... ruuuuuuuun !

  7. #17
    Jimerson is offline Intermediate Member
    Join Date
    Aug 2007
    Posts
    16
    Rep Power
    7

    Post

    I am using the quota limit script located here:

    Quota Warnings - ZimbraWiki

    I am running it with the command:

    ./quota_zimbra.pl -warning 75 -critical 90 -mail 1


    When it outputs it properly shows the people that are over the quota, however it does not send them mail.

    Does anyone have any ideas why this would not be working? I have supplied a vaild email in the field on the script.

    Thanks,
    Jim

  8. #18
    mmorse's Avatar
    mmorse is offline Moderator
    Join Date
    May 2006
    Location
    USA
    Posts
    6,242
    Rep Power
    21

    Default

    Quote Originally Posted by Jimerson View Post
    ./quota_zimbra.pl -warning 75 -critical 90 -mail 1
    how about "-mail yes" instead of 1?

  9. #19
    Jimerson is offline Intermediate Member
    Join Date
    Aug 2007
    Posts
    16
    Rep Power
    7

    Default

    ./quota_zimbra.pl -warning 75 -critical 90 -mail yes
    ERROR : the mail value must be '1' or '0' to disable mail notification
    Utilisation: ./quota_zimbra.pl -mail [yes | no] -warning 85 -critical 90
    Options:
    -mail [yes | no]
    if you want to disable the mail report to the user please. The default value is 'no'
    -warning INTEGER
    allow you to set up the warning threshold. The default value is 85
    -critical INTEGER
    allow you to set up the critical threshold. The default value is 90

  10. #20
    mmorse's Avatar
    mmorse is offline Moderator
    Join Date
    May 2006
    Location
    USA
    Posts
    6,242
    Rep Power
    21

    Default

    my $mailinform = 1; ?

    It seems my thought of using 'yes' was stemming from the old version:
    Code:
     # conditions
    if ($mail !~ /^(no|yes)$/) {
      print "ERROR : the mail value must be 'yes' or 'no'\n";
      print_usage();
    }
    Last edited by mmorse; 08-20-2007 at 12:25 PM.

Page 2 of 3 FirstFirst 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
  •