#!/usr/bin/perl -w
#%# family=auto
#%# capabilities=autoconf

$showruntimestats="/opt/open-xchange/sbin/showruntimestats";
$showexec="$showruntimestats --overview";

if ( $ARGV[0] and $ARGV[0] eq "autoconf")
{
	if (-x $showruntimestats) {
		print "yes\n";
		exit 0;
	}
	else {
		print "no\n";
		exit 0;
	}
}

if ($ARGV[0] and $ARGV[0] eq "config") {
    print "graph_title Overview\n";
    print "graph_args --base 1000 -l 0\n";
    print "graph_category Open Xchange\n";
    print "graph_vlabel Number\n";
    print "nbofdbc.label NumberOfDBConnections\n";
    print "nbofdbc.draw LINE1\n";
    print "nboffile.label OpenFileDescriptorCount\n";
    print "nboffile.draw LINE1\n";
    exit 0
}

open(SHOWRUNTIME,"$showexec |") || die "can not read monitoring output";

while (<SHOWRUNTIME>) {
    if ($_ =~ /Overview,NumConnections/) {
        s/.*\=//;
        $val=$_+0;
        print "nbofdbc.value $val\n";
        next;
    }
    if ($_ =~ /OperatingSystem,OpenFileDescriptorCount/) {
        s/.*\=//;
        $val=$_+0;
        print "nboffile.value $val\n";
        next;
    }
}
