From 716e90449f39becd6cee7f3485c90425f71b8b79 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Sun, 16 Sep 2001 18:08:39 +0000 Subject: [PATCH] update to use SafeExec::safe_exec() to run external programs --- src/lib/Spong/Client/plugins/check_cpu | 11 +++++++---- src/lib/Spong/Client/plugins/check_disk | 10 +++++++--- src/lib/Spong/Client/plugins/check_mailq | 11 ++++++----- src/lib/Spong/Client/plugins/check_processes | 10 +++++----- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/lib/Spong/Client/plugins/check_cpu b/src/lib/Spong/Client/plugins/check_cpu index 0a13463..d7b5c11 100755 --- a/src/lib/Spong/Client/plugins/check_cpu +++ b/src/lib/Spong/Client/plugins/check_cpu @@ -4,18 +4,21 @@ $CHECKFUNCS{'cpu'} = \&check_cpu; # 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( ) { 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 diff --git a/src/lib/Spong/Client/plugins/check_disk b/src/lib/Spong/Client/plugins/check_disk index 70f1ede..ecffec7 100755 --- a/src/lib/Spong/Client/plugins/check_disk +++ b/src/lib/Spong/Client/plugins/check_disk @@ -4,16 +4,20 @@ $CHECKFUNCS{'disk'} = \&check_disk; # 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 = ; # Header + $message = shift(@msg); # Header DFPIPE: - while( ) { + while( shift(@msg) ) { if( m!^(\S+)\s.*?\s(\d+)\%\s+[^/]*(/.*)$! ) { my( $rawfs, $percent, $name ) = ( $1, $2, $3 ); my $skip; diff --git a/src/lib/Spong/Client/plugins/check_mailq b/src/lib/Spong/Client/plugins/check_mailq index c1a527e..2876f48 100755 --- a/src/lib/Spong/Client/plugins/check_mailq +++ b/src/lib/Spong/Client/plugins/check_mailq @@ -1,11 +1,13 @@ # 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 { @@ -13,9 +15,9 @@ sub check_mailq { my(%qcnt,$singleq,@problems); $singlq = 0; - open (FOO,"$MAILQ |"); + my @msg = safe_exec($MAILQ); $mqcnt = 0; - while () { + 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; } @@ -27,7 +29,6 @@ sub check_mailq { if (++$lines <= 35) { $message .= $_; } else {last;}; } } - close FOO; $color = "green"; if ($mqcnt > $MAILQWARN) { $color = "yellow"; } diff --git a/src/lib/Spong/Client/plugins/check_processes b/src/lib/Spong/Client/plugins/check_processes index 9cbf9a2..5cafdba 100755 --- a/src/lib/Spong/Client/plugins/check_processes +++ b/src/lib/Spong/Client/plugins/check_processes @@ -1,5 +1,3 @@ -# $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; @@ -8,14 +6,16 @@ $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 =

; - close P; + @plist = safe_exec($PS,30); foreach $check ( @JOBSWARN, @PROCSWARN ) { $cnt = 1; -- 2.30.2