Quota Warnings

Quota Limit

Hi there !

I did my own little script that allow users to be alerted when users are too close to their quota 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.


examples :

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

more information :

./quota_zimbra.pl --help

I hope it could be usefull for some administrators :-D

Please excuse my english level and my wiki presentation ;-)

I will update this script as soon as possible (with exclude option...)


#!/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" unless $warning;
$critical =  "90" unless $critical;
$mail =  "no" unless $mail;
# conditions
if ($mail !~ /^(no|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);
}
Jump to: navigation, search