<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000099">
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:<br>
<blockquote>Current Status: OK (for 0d 8h 51m 46s)<br>
<br>
Status Information: PROCS OK<br>
cron ok: 1<br>
syslogd ok: 1<br>
xntpd ok: 1<br>
sshd ok: 7<br>
sendmail ok: 2<br>
rpcbind ok: 1<br>
inetd ok: 1<br>
lockd ok: 1<br>
statd ok: 1<br>
nfsd ok: 1<br>
rpc.metad ok: 1<br>
mountd ok: 2<br>
</blockquote>
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:<br>
<br>
<blockquote>***** Nagios *****<br>
<br>
Notification Type: PROBLEM<br>
<br>
Service: PROCS<br>
Host: <server> [truncated by me]<br>
Address: <IP address> [truncated by me]<br>
State: WARNING<br>
<br>
Date/Time: Tue Mar 31 06:04:47 EDT 2009<br>
<br>
Additional Info:<br>
<br>
PROCS WARNING<br>
</blockquote>
<br>
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...<br>
<br>
# libexec> cat check_multiprocs<br>
<br>
#!/usr/bin/perl -w <br>
# Check Multiprocs<br>
<br>
use Getopt::Long;<br>
<br>
sub fail($);<br>
<br>
my ($opt_c,$opt_h);<br>
my $PROGNAME = "PROCS";<br>
my $STATE = "OK"; # Initially, we're
fine<br>
my $RETSTRING = "";<br>
<br>
# SYSTEM COMMANDS<br>
#my $PS = "/bin/ps ax";<br>
my $PS = "/bin/ps -aef";<br>
my $GREP = "/bin/egrep";<br>
<br>
my %RETVALUE = (<br>
'OK' => 0,<br>
'WARNING' => 1,<br>
'CRITICAL' => 2<br>
);<br>
<br>
<br>
<br>
GetOptions <br>
("c=s" => \$opt_c, "config=s" => \$opt_c,<br>
"h" => \$opt_h, "help" => \$opt_h);<br>
<br>
<br>
if ($opt_h) { print_help(); exit 3; }<br>
<br>
($opt_c) || fail("No config file specified");<br>
my $inFile = $1 if ($opt_c =~ /([-.\/a-zA-Z0-9]+)/);<br>
<br>
open (INFILE,"<$inFile") || fail("Could not open file: $inFile");<br>
<br>
while (<INFILE>) {<br>
my ($wmin, $wmax, $cmin, $cmax);<br>
next if (/^#|^$/); # No comments<br>
<br>
my @line = split(/;/);<br>
($#line == 5) || fail("Error parsing $inFile:\n@line");
# We need 6 arguments per line<br>
<br>
my $host = $line[0];<br>
my $proc = $line[1];<br>
<br>
$wmin = ($line[2] =~ /[0-9]+/ ? $line[2] : 1); # Get an
actual number for the mins/maxes<br>
$wmax = ($line[3] =~ /[0-9]+/ ? $line[3] : 1000); <br>
$cmin = ($line[4] =~ /[0-9]+/ ? $line[4] : 1); <br>
$cmax = ($line[5] =~ /[0-9]+/ ? $line[5] : 1000); <br>
<br>
if ($host eq "localhost" || $host eq $ENV{'HOSTNAME'}) { #
Now, check each process <br>
my $procStr;<br>
if ($proc =~ /^".*"$/) { # How does our
process string look?<br>
$procStr = $proc; # For some reason this
works, but the other way doesn't<br>
}<br>
else {<br>
$procStr = "'$proc( |\$)+'";<br>
}<br>
<br>
my @OUT = `$PS | $GREP -e $procStr | $GREP -v grep`;<br>
my $count = $#OUT + 1;<br>
<br>
if ($count < $cmin) { # Be more
specific for crit procs<br>
$STATE = "CRITICAL";<br>
$RETSTRING .= "\n$proc, too few processes: $count";<br>
}<br>
elsif ($count > $cmax ) {<br>
$STATE = "CRITICAL";<br>
$RETSTRING .= "\n$proc, too many processes: $count";<br>
}<br>
elsif ($count < $wmin || $count > $wmax) { <br>
if ( $STATE ne "CRITICAL" ) { <br>
$STATE = "WARNING";<br>
}<br>
$RETSTRING .= "\n$proc exceeded warn threhold: $count";<br>
}<br>
else {<br>
$RETSTRING .= "\n$proc ok: $count";<br>
}<br>
}<br>
}<br>
<br>
if ( $RETSTRING eq "" ) {<br>
$RETSTRING = "\nAll monitored processes OK" . $RETSTRING;<br>
}<br>
<br>
print "$PROGNAME $STATE $RETSTRING\n";<br>
exit $RETVALUE{$STATE};<br>
<br>
<br>
<br>
############################################################<br>
#<br>
# SUBROUTINE DEFINITIONS<br>
#<br>
############################################################<br>
<br>
sub fail($) {<br>
print "Error: @_\n";<br>
print_usage();<br>
<br>
exit 3;<br>
}<br>
<br>
sub print_usage {<br>
print "Usage: $PROGNAME -c <config>\n";<br>
return;<br>
}<br>
<br>
sub print_help {<br>
print "$PROGNAME, Revision: 1.0\n";<br>
<br>
print "\n";<br>
print_usage();<br>
<br>
print "<br>
<br>
-c, --config=config file<br>
Configuration file. Processes should be in the format:<br>
<process>;<min>;<max><br>
";<br>
<br>
print "\n";<br>
<br>
<br>
return;<br>
}<br>
<br>
<pre class="moz-signature" cols="72">--
A. Davis
Email: <a class="moz-txt-link-abbreviated" href="mailto:nccomp@gmail.com">nccomp@gmail.com</a>
"There is no limit to what a man can accomplish
if he doesn't care who gets the credit." - Ronald Reagan
</pre>
</body>
</html>