#!/usr/bin/perl -w

# mailtest check module

# Version: $Revision: 1.3 $
# Author: Eric Garrido, Patrick Radtke, and Matt Selsky
# Date: $Date: 2006/01/18 07:38:05 $
#
# Copyright (c) 2006
# The Trustees of Columbia University in the City of New York
# Columbia University Information Technology
# 
# License restrictions apply, see doc/license.html for details. 

use strict;
use FindBin;
use lib "$FindBin::Bin/../common";
use Survivor::Check;

my %argformat = ();

sub CyrusstuckmailboxValidate {
    return(MODEXEC_OK, 0, "Test OK");  
}

sub CyrusstuckmailboxCheck {

    my $self = shift;
    my $host = shift 
	|| return(MODEXEC_MISCONFIG, 0, "no hostname provided");

    if($host eq ""){
	return(MODEXEC_MISCONFIG, 0, "no hostname provided");
    }

    my @stuck = `/bin/su cyrus -c 'ctl_mboxlist -mw'`;
    
    my $numStuck = scalar(@stuck);
    if($numStuck > 0){
	return(MODEXEC_OK, 1, "No mailboxes seem stuck");
    }
    else {
	return(MODEXEC_PROBLEM, 0, "$numStuck mailboxes appear to be stuck");
    }
}

# begin main block
{

my $sc = new Survivor::Check();

$sc->GetOpt(\%argformat, \&CyrusstuckmailboxValidate);

my $result = $sc->Exec(\&CyrusstuckmailboxCheck);

exit($result);

}
