# This routine checks the 5min CPU load avg from the uptime comand. This
# check also return a status of warning if the uptime is less then 1 hour.
+# $Id: check_cpu,v 1.2 2001/09/16 18:08:39 sljohnson Exp $
+
+use Spong::SafeExec qw(safe_exec);
+
sub check_cpu {
my $color = "green";
- my $uptime = `$UPTIME`;
+ my $uptime = safe_exec($UPTIME,30);
my( $message, $jobs );
my $s = 'up\s+([^\,]+)\,.*\s(\d+) user.+?' .
'[0-9\.]+\,\s*([0-9\.]+)\,\s*([0-9\.]+)\s*$';
my( $up, $users, $load ) = ( $uptime =~ /$s/ );
- open( PIPE, "$PS |" );
- while( <PIPE> ) { if( $jobs++ < 11 ) { $message .= $_; } }
- close( PIPE );
+ my @msg = safe_exec($PS,30);
+ for ( 0..10 ) { $message .= $msg[$_] };
# Check to see if the system has only been up a short time, and if it has
# only been less then an hour, send a page
# This check check the amount of free diskspace for all of the mounted disk
# partitions and the the amount of free swapspace.
+# $Id: check_disk,v 1.3 2001/09/16 18:08:39 sljohnson Exp $
+
+use Spong::SafeExec qw(safe_exec);
+
sub check_disk {
my $color = "green";
my( $summary, $message, $check, @problems, $large, $lpercent, $page );
- open( PIPE, "$DF |" );
+ my @msg = safe_exec($DF);
- $message = <PIPE>; # Header
+ $message = shift(@msg); # Header
DFPIPE:
- while( <PIPE> ) {
+ while( shift(@msg) ) {
if( m!^(\S+)\s.*?\s(\d+)\%\s+[^/]*(/.*)$! ) {
my( $rawfs, $percent, $name ) = ( $1, $2, $3 );
my $skip;
# Register routine with plugin registery
$CHECKFUNCS{'mailq'} = \&check_mailq;
-# $Id: check_mailq,v 1.3 2000/08/22 19:39:58 sljohnson Exp $
-
# Sendmail mailq check for mail servers. If checks the numeber of mail
# message queue against the $MAILQWARN AND $MAILQCRIT variables
+# $Id: check_mailq,v 1.4 2001/09/16 18:08:39 sljohnson Exp $
+
+use Spong::SafeExec qw(safe_exec);
+
use File::Basename;
sub check_mailq {
my(%qcnt,$singleq,@problems);
$singlq = 0;
- open (FOO,"$MAILQ |");
+ my @msg = safe_exec($MAILQ);
$mqcnt = 0;
- while (<FOO>) {
+ while (shift @msg) {
if (/Mail Queue\s+\((\d+)/) { $mqcnt = $1; $singleq=1; }
elsif (/Total Requests:\s+(\d+)/) { $mqcnt = $1; }
elsif (/\s+(\S+)\s+\((\d+)\s+requests\)/) { $qcnt{$1} = $2; }
if (++$lines <= 35) { $message .= $_; } else {last;};
}
}
- close FOO;
$color = "green";
if ($mqcnt > $MAILQWARN) { $color = "yellow"; }
-# $Id: check_processes,v 1.4 2000/11/07 06:20:54 sljohnson Exp $
-
# Register this routine with the plugin registery
$CHECKFUNCS{'processes'} = \&check_processes;
# This routine checks processes running on the host and makes sure that
# the important ones are running
+# $Id: check_processes,v 1.5 2001/09/16 18:08:39 sljohnson Exp $
+
+use Spong::SafeExec qw(safe_exec);
+
sub check_processes {
my $color = "green";
my( $message, $summary, $check, @ret, $down, @down, $time, $critical );
my (@plist);
- open (P, "$PS |");
- @plist = <P>;
- close P;
+ @plist = safe_exec($PS,30);
foreach $check ( @JOBSWARN, @PROCSWARN ) {
$cnt = 1;