From d36016a7adf28424d7f4adaa50612c41f1937c3b Mon Sep 17 00:00:00 2001 From: Subhendu Ghosh Date: Wed, 19 Jun 2002 03:09:10 +0000 Subject: fixes for using POSIX return codes git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@54 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 7429424..9ce4a32 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -62,6 +62,7 @@ main (int argc, char **argv) int used_disk = -1; int free_disk = -1; int result = STATE_UNKNOWN; + int temp_result = STATE_UNKNOWN; char *command_line = NULL; char input_buffer[MAX_INPUT_BUFFER] = ""; char file_system[MAX_INPUT_BUFFER] = ""; @@ -99,7 +100,36 @@ main (int argc, char **argv) || sscanf (input_buffer, "%s %*s %d %d %d %d%% %s", file_system, &total_disk, &used_disk, &free_disk, &usp, &mntp) == 6) { - result = max (result, check_disk (usp, free_disk)); + /* cannot use max now that STATE_UNKNOWN is greater than STATE_CRITICAL + result = max (result, check_disk (usp, free_disk)); */ + temp_result = check_disk (usp, free_disk) ; + + + if ( temp_result == STATE_CRITICAL ) { + result = STATE_CRITICAL; + } + else if (temp_result == STATE_WARNING) { + if ( !( result == STATE_CRITICAL) ) { + result = STATE_WARNING; + } + } + else if (temp_result == STATE_OK) { + if ( ! ( result == STATE_CRITICAL || result == STATE_WARNING) ){ + result = STATE_OK; + } + } + else if (temp_result == STATE_UNKNOWN) { + if ( ! ( result == STATE_CRITICAL || result == STATE_WARNING || result == STATE_OK) ){ + result = STATE_UNKNOWN; + } + } + else { + /* don't have a match with the return value from check_disk() */ + result = STATE_UNKNOWN; + } + + + len = snprintf (outbuf, MAX_INPUT_BUFFER - 1, " [%d kB (%d%%) free on %s]", free_disk, 100 - usp, @@ -115,15 +145,20 @@ main (int argc, char **argv) /* If we get anything on stderr, at least set warning */ while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) - result = max (result, STATE_WARNING); + /*result = max (result, STATE_WARNING); */ + if( !( result == STATE_CRITICAL) ) { + result = STATE_WARNING; + } /* close stderr */ (void) fclose (child_stderr); /* close the pipe */ if (spclose (child_process)) - result = max (result, STATE_WARNING); - + /*result = max (result, STATE_WARNING); */ + if( !( result == STATE_CRITICAL) ) { + result = STATE_WARNING; + } if (usp < 0) printf ("Disk \"%s\" not mounted or nonexistant\n", path); else if (result == STATE_UNKNOWN) diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 5eada4f..420f148 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -121,8 +121,12 @@ main (int argc, char **argv) else if (pl >= wpl || rta >= wrta) result = STATE_WARNING; else if (pl < wpl && rta < wrta && pl >= 0 && rta >= 0) - result = max (result, STATE_OK); - + /* cannot use the max function because STATE_UNKNOWN is now 3 gt STATE_OK + result = max (result, STATE_OK); */ + if( !( (result == STATE_WARNING) || (result == STATE_CRITICAL) ) ) { + result = STATE_OK; + } + if (display_html == TRUE) printf ("", CGIURL, server_address); if (pl == 100) @@ -381,7 +385,12 @@ run_ping (char *command_line) while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { if (strstr (input_buffer, "(DUP!)")) { - result = max (result, STATE_WARNING); + /* cannot use the max function since STATE_UNKNOWN is max + result = max (result, STATE_WARNING); */ + if( !(result == STATE_CRITICAL) ){ + result = STATE_WARNING; + } + warn_text = realloc (warn_text, strlen (WARN_DUPLICATES) + 1); if (warn_text == NULL) terminate (STATE_UNKNOWN, "unable to realloc warn_text"); @@ -445,6 +454,9 @@ run_ping (char *command_line) else if (strstr (input_buffer, "Destination Host Unreachable")) terminate (STATE_CRITICAL, "PING CRITICAL - Host Unreachable (%s)", server_address); + else if (strstr (input_buffer, "unknown host" ) ) + terminate (STATE_CRITICAL, "PING CRITICAL - Host not found (%s)", + server_address); warn_text = realloc (warn_text, strlen (warn_text) + strlen (input_buffer) + 2); @@ -456,9 +468,15 @@ run_ping (char *command_line) sprintf (warn_text, "%s %s", warn_text, input_buffer); if (strstr (input_buffer, "DUPLICATES FOUND")) - result = max (result, STATE_WARNING); + /* cannot use the max function since STATE_UNKNOWN is max + result = max (result, STATE_WARNING); */ + if( !(result == STATE_CRITICAL) ){ + result = STATE_WARNING; + } else - result = max (result, STATE_CRITICAL); + /* cannot use the max function since STATE_UNKNOWN is max + result = max (result, STATE_CRITICAL); */ + result = STATE_CRITICAL ; } (void) fclose (child_stderr); @@ -469,7 +487,7 @@ run_ping (char *command_line) return result; } - + void print_usage (void) diff --git a/plugins/check_procs.c b/plugins/check_procs.c index c66d33d..9a3dc01 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -145,18 +145,29 @@ main (int argc, char **argv) /* If we get anything on STDERR, at least set warning */ while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { if (verbose) - printf ("%s", input_buffer); - result = max (result, STATE_WARNING); + printf ("STDERR: %s", input_buffer); + /*Cannot use max() any more as STATE_UNKNOWN is gt STATE_CRITICAL + result = max (result, STATE_WARNING); */ + if ( !(result == STATE_CRITICAL) ) { + result = STATE_WARNING; + } + printf ("System call sent warnings to stderr\n"); } - if (result > STATE_OK) + +/* if (result == STATE_UNKNOWN || result == STATE_WARNING) printf ("System call sent warnings to stderr\n"); - +*/ (void) fclose (child_stderr); /* close the pipe */ if (spclose (child_process)) { printf ("System call returned nonzero status\n"); - return max (result, STATE_WARNING); + if ( !(result == STATE_CRITICAL) ) { + return STATE_WARNING; + } + else { + return result ; + } } if (options == ALL) @@ -164,7 +175,8 @@ main (int argc, char **argv) if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ printf ("Unable to read output\n"); - return max (result, STATE_UNKNOWN); + + return result; } if (verbose && (options & STAT)) @@ -199,15 +211,30 @@ main (int argc, char **argv) } else if (wmax >= 0 && procs > wmax) { printf (format, "WARNING", procs); - return max (result, STATE_WARNING); + if ( !(result == STATE_CRITICAL) ) { + return STATE_WARNING; + } + else { + return result ; + } + /*return max (result, STATE_WARNING); */ } else if (wmin >= 0 && procs < wmin) { printf (format, "WARNING", procs); - return max (result, STATE_WARNING); + if ( !(result == STATE_CRITICAL) ) { + return STATE_WARNING; + } + else { + return result ; + } + /*return max (result, STATE_WARNING); */ } printf (format, "OK", procs); - return max (result, STATE_OK); + if ( result == STATE_UNKNOWN ) { + result = STATE_OK; + } + return result; } /* process command-line arguments */ -- cgit v0.10-9-g596f