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

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

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 Broken connections\n";
    print "graph_args --base 1000 -l 0\n";
    print "graph_category Open Xchange\n";
    print "graph_vlabel Number Broken Connections\n";
    print "a.label Mail TimeoutConnections\n";
    print "a.draw LINE1\n";
    print "a.type DERIVE\n";
    print "a.min 0\n";
    print "b.label Mail FailedLogins\n";
    print "b.draw LINE1\n";
    print "b.type DERIVE\n";
    print "b.min 0\n";
    print "c.label MailInterface\n";
    print "c.draw LINE1\n";
    print "c.type DERIVE\n";
    print "c.min 0\n";
    print "d.label AJPv13\n";
    print "d.draw LINE1\n";
    print "d.type DERIVE\n";
    print "d.min 0\n";
    print "e.label ConfigDB Read\n";
    print "e.draw LINE1\n";
    print "e.type DERIVE\n";
    print "e.min 0\n";
    print "f.label ConfigDB Write\n";
    print "f.draw LINE1\n";
    print "f.type DERIVE\n";
    print "f.min 0\n";
    print "g.label DB Pool 4\n";
    print "g.draw LINE1\n";
    print "g.type DERIVE\n";
    print "g.min 0\n";
    print "h.label DB Pool 6\n";
    print "h.draw LINE1\n";
    print "h.type DERIVE\n";
    print "h.min 0\n";
    exit 0
}
                                    

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

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /MailInterfaceMonitor,NumTimeoutConnections/) {
        s/.*\=//; 
        $val=$_+0;
        print "a.value $val\n";
        next;
    }
    if ( $_ =~ /MailInterfaceMonitor,NumFailedLogins/) {
         s/.*\=//;
        $val=$_+0;
            print "b.value $val\n";
        next;
    }
    if ( $_ =~ /MailInterfaceMonitor,NumBrokenConnections/) {
        s/.*\=//;
        $val=$_+0;
        print "c.value $val\n";
        next;
    }
    if ( $_ =~ /AJPv13ServerThreadsMonitor,NumBrokenConnections/) {
        s/.*\=//;
        $val=$_+0;
        print "d.value $val\n";
        next;
    }
    if ( $_ =~ /ConfigDB Read,NumBrokenConnections/) {
        s/.*\=//;
        print "e.value $val\n";
        next;
    }
    if ( $_ =~ /ConfigDB Write,NumBrokenConnections/) {
    s/.*\=//;
        print "f.value $val\n";
        next;
    }
    if ( $_ =~ /DB Pool 4,NumBrokenConnections/) {
        s/.*\=//;
        $val=$_+0;
        print "g.value $val\n";
        next;
    }
    if ( $_ =~ /DB Pool 6,NumBrokenConnections/) {
        s/.*\=//;
        $val=$_+0;
        print "h.value $val\n";
        next;
    }
}


