spong-client Module Template



This template assumes that you are creating  a new client check called 'mailq'. The name of the file created should be 'check_mailq'. The file name should always be 'check_' and the registry name (e.g. for the foo check, the registry name is 'foo' and the file name is 'check_foo'.

The line that has the assignment to $CHECKFUNC{'registry-name'} is the key to the registry mechanism. It's what track the registry name to the your check function.

The registry name does not always have to match up to the service name as in this case of 'mailq'. If you where creating a new and improved function to check mail queues, you could create a module called 'my_mailq'. You would use the regiestry name 'my_mailq', but you would use the service name 'mailq' in the &status() function when reporting you info back to the server.

check_mailq:

# Register my routine with plugin registry
$CHECKFUNCS{'mailq'} = \&check_mailq;

# Sendmail mail queue check for mail servers. It checks the number of mail
# message queued against the $MAILQWARN AND $MAILQCRIT variables.
# It runs the command in the config variable $MAILQ to do it's check.

sub check_mailq {
    my($mqcnt, $message, $color, $summary );

    open (FOO,"$MAILQ |");
    $mqcnt = 0;
    while (<FOO>) {
        if (/Mail Queue\s+\((\d+)/) { $mqcnt = $1; }

        # Grab enough to get the first 10 entries.
        if (++$lines <= 35) { $message .= $_ };
    }
    close FOO;

    $color = "green";
    if ($mqcnt > $MAILQWARN) { $color = "yellow"; }
    if ($mqcnt > $MAILQCRIT) { $color = "red"; }

    $summary = "Mail Queue count = $mqcnt";

    &debug("mailq - $color, $summary");
    &status( $SPONGSERVER, $HOST, "mailq", $color, $summary, $message );
}

# I'm include perl code, I need this line.
1;

Please note the final line. It is always required for a module file.