#!/usr/bin/perl
# 
# Plugin to monitor the Scalix email system.
#
# $Log$
#
#
# Parameters:
# 	
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
# Magic markers (Used by munin-config and some installation scripts.
# Optional):
#
#%# family=contrib

my $OMRP="/opt/scalix/bin/omrealpath";

my $mode = shift;

if($mode eq "config") {
    print "graph_title Scalix Index Work Queue\n";
    print "graph_args -l 0\n";
    print "graph_vlabel number\n";
    print "graph_category Scalix\n";
    print "graph_title Scalix Index Work Queue\n";
    print "graph_vlabel Items\n";
    print "items.label Items to be indexed\n";
    print "items.min 0\n";
    exit 0;
    }

my $iwdir = `$OMRP "~/indexwork"`;  chomp $iwdir;
#print "$iwdir\n";

my ($f, $fsize, $i);

opendir(DIR, $iwdir);
while ($f = readdir(DIR)) {
    next unless $f =~ /\d+\.\d/;
    $fsize = -s $iwdir . '/' . $f;
#    print "$f $fsize\n";
    $i += ($fsize / 112);
    }
closedir(DIR);

$i = int $i;

print "items.value $i\n";
