Additional Info in email?

Andrew Davis nccomp at gmail.com
Tue Mar 31 19:52:23 CEST 2009


I'm using the "check_multiprocs" add on available from NagiosExchange. 
With it configured for a host, if I drill in on the test in the web 
interface, I see:

    Current Status:      OK   (for 0d 8h 51m 46s)

    Status Information:    PROCS OK
    cron ok: 1
    syslogd ok: 1
    xntpd ok: 1
    sshd ok: 7
    sendmail ok: 2
    rpcbind ok: 1
    inetd ok: 1
    lockd ok: 1
    statd ok: 1
    nfsd ok: 1
    rpc.metad ok: 1
    mountd ok: 2

However, last night one of the services was restarted (probably syslogd) 
due to cron. I received an alert via email about it, but all I saw was:

    ***** Nagios *****

    Notification Type: PROBLEM

    Service: PROCS
    Host: <server> [truncated by me]
    Address: <IP address> [truncated by me]
    State: WARNING

    Date/Time: Tue Mar 31 06:04:47 EDT 2009

    Additional Info:

    PROCS WARNING


What I need is to see which processes are down in the "Additional Info:" 
field when its emailed. Anyone know how I would go about this? 
Unfortunately, I'm not a perl guy... I've included the script below...

# libexec> cat check_multiprocs

#!/usr/bin/perl -w
# Check Multiprocs

use Getopt::Long;

sub fail($);

my ($opt_c,$opt_h);
my $PROGNAME = "PROCS";
my $STATE = "OK";                                    # Initially, we're fine
my $RETSTRING = "";

# SYSTEM COMMANDS
#my $PS = "/bin/ps ax";
my $PS = "/bin/ps -aef";
my $GREP = "/bin/egrep";

my %RETVALUE = (
    'OK'       => 0,
    'WARNING'  => 1,
    'CRITICAL' => 2
    );
   


GetOptions
    ("c=s"    => \$opt_c, "config=s"    => \$opt_c,
     "h"    => \$opt_h, "help"    => \$opt_h);


if ($opt_h) { print_help(); exit 3; }

($opt_c) || fail("No config file specified");
my $inFile = $1 if ($opt_c =~ /([-.\/a-zA-Z0-9]+)/);

open (INFILE,"<$inFile") || fail("Could not open file: $inFile");

while (<INFILE>) {
    my ($wmin, $wmax, $cmin, $cmax);
    next if (/^#|^$/);                                # No comments

    my @line = split(/;/);
    ($#line == 5) || fail("Error parsing $inFile:\n at line");            # 
We need 6 arguments per line

    my $host = $line[0];
    my $proc = $line[1];

    $wmin = ($line[2] =~ /[0-9]+/ ? $line[2] : 1);            # Get an 
actual number for the mins/maxes
    $wmax = ($line[3] =~ /[0-9]+/ ? $line[3] : 1000);           
    $cmin = ($line[4] =~ /[0-9]+/ ? $line[4] : 1);           
    $cmax = ($line[5] =~ /[0-9]+/ ? $line[5] : 1000);           

    if ($host eq "localhost" || $host eq $ENV{'HOSTNAME'}) {        # 
Now, check each process
        my $procStr;
        if ($proc =~ /^".*"$/) {                        # How does our 
process string look?
            $procStr = $proc;                    # For some reason this 
works, but the other way doesn't
        }
        else {
            $procStr = "'$proc( |\$)+'";
        }

        my @OUT = `$PS | $GREP -e $procStr | $GREP -v grep`;
        my $count = $#OUT + 1;

        if ($count < $cmin) {                        # Be more specific 
for crit procs
            $STATE = "CRITICAL";
            $RETSTRING .= "\n$proc, too few processes: $count";
        }
        elsif ($count > $cmax ) {
            $STATE = "CRITICAL";
            $RETSTRING .= "\n$proc, too many processes: $count";
        }
         elsif ($count < $wmin || $count > $wmax) {
            if ( $STATE ne "CRITICAL" ) {   
                $STATE = "WARNING";
            }
            $RETSTRING .= "\n$proc exceeded warn threhold: $count";
        }
        else {
            $RETSTRING .= "\n$proc ok: $count";
        }
    }
}

if ( $RETSTRING eq "" ) {
    $RETSTRING = "\nAll monitored processes OK" . $RETSTRING;
}

print "$PROGNAME $STATE $RETSTRING\n";
exit $RETVALUE{$STATE};



############################################################
#
# SUBROUTINE DEFINITIONS
#
############################################################

sub fail($) {
        print "Error: @_\n";
    print_usage();

    exit 3;
}

sub print_usage {
    print "Usage: $PROGNAME -c <config>\n";
    return;
}

sub print_help {
    print "$PROGNAME, Revision: 1.0\n";

    print "\n";
    print_usage();

    print "

-c, --config=config file
    Configuration file. Processes should be in the format:
    <process>;<min>;<max>
";

    print "\n";


    return;
}

-- 


  A. Davis
  Email:     nccomp at gmail.com

  "There is no limit to what a man can accomplish
   if he doesn't care who gets the credit." - Ronald Reagan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20090331/dfa31795/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null


More information about the Users mailing list