my $vid ;
my $venum;
my $ret=0 ;
open(PROCVZQUOTA, "</proc/vz/vzquota");
while(<PROCVZQUOTA>){
        my %vid;
        if ( /\D*(\d+):.*/ ){ $vid=$1; }
        if ( /\s*(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*/ ){
                $resource=$1 ;
                $usage=$2 ;
                $softlimit=$3 ;
                $hardlimit=$4 ;
                $time=$5 ;
                $expire=$6 ;
		$venum++;
		if ($resource=="1k-block"){
			$resource="diskspace";
		}
		$usageg=sprintf("%.3f",$usage/1024/1024);
		$softlimitg=sprintf("%.3f",$softlimit/1024/1024);
		$hardlimitg=sprintf("%.3f",$hardlimit/1024/1024);
		
                if ( $usage >= $softlimit ){
			$vname=`vzlist -1 $vid -o name`;
			$vname=~ s/[\r\n ]//g;
                        print "CRITICAL: quota exceeded softlimit for CT $vid ($vname): $resource usage:$usageg","G",", softlimit:$softlimitg","G",", hardlimit:$hardlimitg","G"," <br>" ;
                        $ret=2;
			next;
                }
                if ( $usage >= $softlimit-$softlimit/10 ){
			$vname=`vzlist -1 $vid -o name`;
			$vname=~ s/[\r\n ]//g;
                        print "WARNING: quota exceeded 90% for CT $vid ($vname): $resource usage:$usageg","G",", softlimit:$softlimitg","G",", hardlimit:$hardlimitg","G"," <br>" ;
                        if ($ret<2){  # do not lower exit code
				$ret=1;
			}
                }

        }
}
        if ($ret==0){
                if ($venum==0){
                        print "OK: No containers are running";
                }
                else{
                        print "OK: All ",$venum/2," containers have enough free disk space";
                }
        }

exit($ret);

