mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-06-09 00:32:05 -04:00
more POSIX return value comparison related code fixes
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@55 f882894a-f735-0410-b71e-b25c423dba1c
This commit is contained in:
parent
d36016a7ad
commit
f4c6f7f093
11 changed files with 96 additions and 24 deletions
|
|
@ -98,7 +98,7 @@ main (int argc, char **argv)
|
|||
|
||||
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
|
||||
/* If we get anything on STDERR, at least set warning */
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
printf ("%s", input_buffer);
|
||||
if (!strcmp (output, ""))
|
||||
strcpy (output, 1 + index (input_buffer, ':'));
|
||||
|
|
@ -108,7 +108,7 @@ main (int argc, char **argv)
|
|||
|
||||
/* close the pipe */
|
||||
if (spclose (child_process)) {
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
if (!strcmp (output, ""))
|
||||
strcpy (output, "nslookup returned error status");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ main (int argc, char **argv)
|
|||
/* scan stderr */
|
||||
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
|
||||
if (error_scan (input_buffer) != STATE_OK) {
|
||||
result = max (result, error_scan (input_buffer));
|
||||
result = max_state (result, error_scan (input_buffer));
|
||||
output = strscpy (output, 1 + index (input_buffer, ':'));
|
||||
}
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ main (int argc, char **argv)
|
|||
|
||||
/* close stdout */
|
||||
if (spclose (child_process)) {
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
if (!strcmp (output, ""))
|
||||
output = strscpy (output, "nslookup returned error status");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,21 +93,22 @@ main (int argc, char **argv)
|
|||
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
|
||||
if (verbose)
|
||||
printf ("%s", input_buffer);
|
||||
status = max (status, textscan (input_buffer));
|
||||
status = max_state (status, textscan (input_buffer));
|
||||
}
|
||||
|
||||
/* If we get anything on STDERR, at least set warning */
|
||||
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
|
||||
status = max (status, STATE_WARNING);
|
||||
status = max_state (status, STATE_WARNING);
|
||||
if (verbose)
|
||||
printf ("%s", input_buffer);
|
||||
status = max (status, textscan (input_buffer));
|
||||
status = max_state (status, textscan (input_buffer));
|
||||
}
|
||||
(void) fclose (child_stderr);
|
||||
|
||||
/* close the pipe */
|
||||
if (spclose (child_process))
|
||||
status = max (status, STATE_WARNING);
|
||||
/* need to use max_state not max */
|
||||
status = max_state (status, STATE_WARNING);
|
||||
|
||||
printf ("FPING %s - %s\n", state_text (status), server_name);
|
||||
|
||||
|
|
@ -165,9 +166,28 @@ textscan (char *buf)
|
|||
terminate (status, "FPING %s - %s (loss=%f%%, rta=%f ms)\n",
|
||||
state_text (status), server_name, loss, rta);
|
||||
|
||||
}
|
||||
else if(strstr (buf, "xmt/rcv/%loss") ) {
|
||||
/* no min/max/avg if host was unreachable in fping v2.2.b1 */
|
||||
losstr = strstr (buf, "=");
|
||||
losstr = 1 + strstr (losstr, "/");
|
||||
losstr = 1 + strstr (losstr, "/");
|
||||
loss = strtod (losstr, NULL);
|
||||
if (loss == 100)
|
||||
status = STATE_CRITICAL;
|
||||
else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl)
|
||||
status = STATE_CRITICAL;
|
||||
else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl)
|
||||
status = STATE_WARNING;
|
||||
else
|
||||
status = STATE_OK;
|
||||
|
||||
terminate (status, "FPING %s - %s (loss=%f%% )\n",
|
||||
state_text (status), server_name, loss );
|
||||
|
||||
}
|
||||
else {
|
||||
status = max (status, STATE_WARNING);
|
||||
status = max_state (status, STATE_WARNING);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
|
|
|||
|
|
@ -285,14 +285,14 @@ main (int argc, char **argv)
|
|||
|
||||
/* WARNING if output found on stderr */
|
||||
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
/* close stderr */
|
||||
(void) fclose (child_stderr);
|
||||
|
||||
/* close the pipe */
|
||||
if (spclose (child_process))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
/* if there wasn't any output, display an error */
|
||||
if (line == 0) {
|
||||
|
|
|
|||
|
|
@ -101,14 +101,14 @@ 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_state (result, STATE_WARNING);
|
||||
|
||||
/* close stderr */
|
||||
(void) fclose (child_stderr);
|
||||
|
||||
/* close the pipe */
|
||||
if (spclose (child_process))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
/* reset the alarm handler */
|
||||
alarm (0);
|
||||
|
|
|
|||
|
|
@ -483,7 +483,7 @@ run_ping (char *command_line)
|
|||
|
||||
/* close the pipe - WARNING if status is set */
|
||||
if (spclose (child_process))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ char *community = NULL;
|
|||
char oid[MAX_INPUT_BUFFER] = "";
|
||||
char *label = NULL;
|
||||
char *units = NULL;
|
||||
char *port = NULL;
|
||||
char string_value[MAX_INPUT_BUFFER] = "";
|
||||
char **labels = NULL;
|
||||
char **unitv = NULL;
|
||||
|
|
@ -259,7 +260,7 @@ main (int argc, char **argv)
|
|||
iresult = STATE_WARNING;
|
||||
}
|
||||
|
||||
result = max (result, iresult);
|
||||
result = max_state (result, iresult);
|
||||
|
||||
if (nlabels > 1 && i < nlabels && labels[i] != NULL)
|
||||
outbuff = ssprintf
|
||||
|
|
@ -290,14 +291,14 @@ main (int argc, char **argv)
|
|||
|
||||
/* WARNING if output found on stderr */
|
||||
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
/* close stderr */
|
||||
(void) fclose (child_stderr);
|
||||
|
||||
/* close the pipe */
|
||||
if (spclose (child_process))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
if (nunits > 0)
|
||||
printf ("%s %s -%s\n", label, state_text (result), outbuff);
|
||||
|
|
@ -348,6 +349,12 @@ process_arguments (int argc, char **argv)
|
|||
if (units == NULL)
|
||||
units = strscpy (NULL, "");
|
||||
|
||||
if (port == NULL)
|
||||
port = strscpy(NULL,"161");
|
||||
|
||||
if (port == NULL)
|
||||
port = strscpy(NULL,"161");
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
@ -409,6 +416,7 @@ call_getopt (int argc, char **argv)
|
|||
case 'r':
|
||||
case 'l':
|
||||
case 'u':
|
||||
case 'p':
|
||||
i++;
|
||||
}
|
||||
|
||||
|
|
@ -608,6 +616,8 @@ print_help (char *cmd)
|
|||
" (default is \"public\")\n"
|
||||
" -u, --units=STRING\n"
|
||||
" Units label(s) for output data (e.g., 'sec.').\n"
|
||||
" -p, --port=STRING\n"
|
||||
" TCP port number target is listening on.\n"
|
||||
" -d, --delimiter=STRING\n"
|
||||
" Delimiter to use when parsing returned data. Default is \"%s\"\n"
|
||||
" Any data on the right hand side of the delimiter is considered\n"
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ main (int argc, char **argv)
|
|||
terminate (STATE_UNKNOWN,
|
||||
"check_vsz: could not malloc message (1)");
|
||||
sprintf (message, "%s %s(%d)", message, proc_name, proc_size);
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
}
|
||||
if (proc_size > crit) {
|
||||
result = STATE_CRITICAL;
|
||||
|
|
@ -107,7 +107,7 @@ main (int argc, char **argv)
|
|||
"check_vsz: could not malloc message (2)");
|
||||
sprintf (message, "%s %d", message, proc_size);
|
||||
if (proc_size > warn) {
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
}
|
||||
if (proc_size > crit) {
|
||||
result = STATE_CRITICAL;
|
||||
|
|
@ -118,13 +118,13 @@ 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_state (result, STATE_WARNING);
|
||||
|
||||
(void) fclose (child_stderr);
|
||||
|
||||
/* close the pipe */
|
||||
if (spclose (child_process))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
if (result == STATE_OK)
|
||||
printf ("ok (all VSZ<%d): %s\n", warn, message);
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ main (int argc, char **argv)
|
|||
|
||||
/* WARNING if output found on stderr */
|
||||
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
|
||||
result = max (result, STATE_WARNING);
|
||||
result = max_state (result, STATE_WARNING);
|
||||
|
||||
/* close stderr */
|
||||
(void) fclose (child_stderr);
|
||||
|
|
|
|||
|
|
@ -58,6 +58,44 @@ char *strpcat (char *dest, const char *src, const char *str);
|
|||
|
||||
#define max(a,b) ((a)>(b))?(a):(b)
|
||||
|
||||
/* **************************************************************************
|
||||
* max_state(result, STATE_x)
|
||||
* compares STATE_x to result and returns result if STATE_x is less than a based on the following
|
||||
* STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL
|
||||
*
|
||||
* Note that numerically the above does not hold
|
||||
****************************************************************************/
|
||||
|
||||
int
|
||||
max_state(int a, int b)
|
||||
{
|
||||
if(a == STATE_CRITICAL){
|
||||
return a;
|
||||
}
|
||||
else if (a == STATE_WARNING) {
|
||||
|
||||
if (b == STATE_CRITICAL){
|
||||
return b;
|
||||
}else {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
else if (a == STATE_OK) {
|
||||
|
||||
if ( b== STATE_CRITICAL || b == STATE_WARNING) {
|
||||
return b;
|
||||
}else{
|
||||
return a;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* a == UNKNOWN */
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
char *
|
||||
my_basename (char *path)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* header file for nagios plugins uitls.c */
|
||||
/* header file for nagios plugins utils.c */
|
||||
|
||||
/* this file should be included in all plugins */
|
||||
|
||||
|
|
@ -55,6 +55,9 @@ char *ssprintf (char *str, const char *fmt, ...);
|
|||
char *strpcpy (char *dest, const char *src, const char *str);
|
||||
char *strpcat (char *dest, const char *src, const char *str);
|
||||
|
||||
/* Handle comparisions for STATE_* */
|
||||
int max_state(int, int);
|
||||
|
||||
#define max(a,b) ((a)>(b))?(a):(b)
|
||||
|
||||
#define usage(msg) {\
|
||||
|
|
@ -73,7 +76,8 @@ exit(STATE_UNKNOWN);\
|
|||
(a)==0?"OK":\
|
||||
(a)==1?"WARNING":\
|
||||
(a)==2?"CRITICAL":\
|
||||
(a)==-2?"DEPENDENT":\
|
||||
(a)==3?"UNKNOWN":\
|
||||
(a)==4?"DEPENDENT":\
|
||||
"UNKNOWN"
|
||||
|
||||
/* The idea here is that, although not every plugin will use all of these,
|
||||
|
|
|
|||
Loading…
Reference in a new issue