[Nagiosplug-checkins] CVS: nagiosplug/plugins check_fping.c,1.1.1.1,1.2 check_ping.c,1.4,1.5 check_dns.c,1.1.1.1,1.2 check_hpjd.c,1.2,1.3 check_dig.c,1.1.1.1,1.2 urlize.c,1.1.1.1,1.2 check_snmp.c,1.1.1.1,1.2 check_nagios.c,1.1.1.1,1.2 check_vsz.c,1.1.1.1,1.2 utils.c,1.1.1.1,1.2 utils.h.in,1.1.1.1,1.2
Subhendu Ghosh
sghosh at users.sourceforge.net
Tue Jun 18 22:12:03 CEST 2002
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv32602
Modified Files:
check_fping.c check_ping.c check_dns.c check_hpjd.c
check_dig.c urlize.c check_snmp.c check_nagios.c check_vsz.c
utils.c utils.h.in
Log Message:
more POSIX return value comparison related code fixes
Index: check_fping.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_fping.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_fping.c 28 Feb 2002 06:42:57 -0000 1.1.1.1
--- check_fping.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 94,106 ****
if (verbose)
printf ("%s", input_buffer);
! status = max (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);
if (verbose)
printf ("%s", input_buffer);
! status = max (status, textscan (input_buffer));
}
(void) fclose (child_stderr);
--- 94,106 ----
if (verbose)
printf ("%s", 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_state (status, STATE_WARNING);
if (verbose)
printf ("%s", input_buffer);
! status = max_state (status, textscan (input_buffer));
}
(void) fclose (child_stderr);
***************
*** 108,112 ****
/* close the pipe */
if (spclose (child_process))
! status = max (status, STATE_WARNING);
printf ("FPING %s - %s\n", state_text (status), server_name);
--- 108,113 ----
/* close the pipe */
if (spclose (child_process))
! /* need to use max_state not max */
! status = max_state (status, STATE_WARNING);
printf ("FPING %s - %s\n", state_text (status), server_name);
***************
*** 167,172 ****
}
else {
! status = max (status, STATE_WARNING);
}
--- 168,192 ----
}
+ 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_state (status, STATE_WARNING);
}
Index: check_ping.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ping.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** check_ping.c 19 Jun 2002 03:09:10 -0000 1.4
--- check_ping.c 19 Jun 2002 05:11:52 -0000 1.5
***************
*** 484,488 ****
/* close the pipe - WARNING if status is set */
if (spclose (child_process))
! result = max (result, STATE_WARNING);
return result;
--- 484,488 ----
/* close the pipe - WARNING if status is set */
if (spclose (child_process))
! result = max_state (result, STATE_WARNING);
return result;
Index: check_dns.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dns.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_dns.c 28 Feb 2002 06:42:57 -0000 1.1.1.1
--- check_dns.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 151,155 ****
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
if (error_scan (input_buffer) != STATE_OK) {
! result = max (result, error_scan (input_buffer));
output = strscpy (output, 1 + index (input_buffer, ':'));
}
--- 151,155 ----
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
if (error_scan (input_buffer) != STATE_OK) {
! result = max_state (result, error_scan (input_buffer));
output = strscpy (output, 1 + index (input_buffer, ':'));
}
***************
*** 161,165 ****
/* close stdout */
if (spclose (child_process)) {
! result = max (result, STATE_WARNING);
if (!strcmp (output, ""))
output = strscpy (output, "nslookup returned error status");
--- 161,165 ----
/* close stdout */
if (spclose (child_process)) {
! result = max_state (result, STATE_WARNING);
if (!strcmp (output, ""))
output = strscpy (output, "nslookup returned error status");
Index: check_hpjd.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_hpjd.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** check_hpjd.c 8 May 2002 05:07:22 -0000 1.2
--- check_hpjd.c 19 Jun 2002 05:11:52 -0000 1.3
***************
*** 286,290 ****
/* WARNING if output found on stderr */
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max (result, STATE_WARNING);
/* close stderr */
--- 286,290 ----
/* WARNING if output found on stderr */
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max_state (result, STATE_WARNING);
/* close stderr */
***************
*** 293,297 ****
/* close the pipe */
if (spclose (child_process))
! result = max (result, STATE_WARNING);
/* if there wasn't any output, display an error */
--- 293,297 ----
/* close the pipe */
if (spclose (child_process))
! result = max_state (result, STATE_WARNING);
/* if there wasn't any output, display an error */
Index: check_dig.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dig.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_dig.c 28 Feb 2002 06:42:57 -0000 1.1.1.1
--- check_dig.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 99,103 ****
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);
printf ("%s", input_buffer);
if (!strcmp (output, ""))
--- 99,103 ----
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
/* If we get anything on STDERR, at least set warning */
! result = max_state (result, STATE_WARNING);
printf ("%s", input_buffer);
if (!strcmp (output, ""))
***************
*** 109,113 ****
/* close the pipe */
if (spclose (child_process)) {
! result = max (result, STATE_WARNING);
if (!strcmp (output, ""))
strcpy (output, "nslookup returned error status");
--- 109,113 ----
/* close the pipe */
if (spclose (child_process)) {
! result = max_state (result, STATE_WARNING);
if (!strcmp (output, ""))
strcpy (output, "nslookup returned error status");
Index: urlize.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/urlize.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** urlize.c 28 Feb 2002 06:42:59 -0000 1.1.1.1
--- urlize.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 111,115 ****
/* WARNING if output found on stderr */
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max (result, STATE_WARNING);
/* close stderr */
--- 111,115 ----
/* WARNING if output found on stderr */
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max_state (result, STATE_WARNING);
/* close stderr */
Index: check_snmp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_snmp.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_snmp.c 28 Feb 2002 06:42:59 -0000 1.1.1.1
--- check_snmp.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 98,101 ****
--- 98,102 ----
char *label = NULL;
char *units = NULL;
+ char *port = NULL;
char string_value[MAX_INPUT_BUFFER] = "";
char **labels = NULL;
***************
*** 260,264 ****
}
! result = max (result, iresult);
if (nlabels > 1 && i < nlabels && labels[i] != NULL)
--- 261,265 ----
}
! result = max_state (result, iresult);
if (nlabels > 1 && i < nlabels && labels[i] != NULL)
***************
*** 291,295 ****
/* WARNING if output found on stderr */
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max (result, STATE_WARNING);
/* close stderr */
--- 292,296 ----
/* WARNING if output found on stderr */
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max_state (result, STATE_WARNING);
/* close stderr */
***************
*** 298,302 ****
/* close the pipe */
if (spclose (child_process))
! result = max (result, STATE_WARNING);
if (nunits > 0)
--- 299,303 ----
/* close the pipe */
if (spclose (child_process))
! result = max_state (result, STATE_WARNING);
if (nunits > 0)
***************
*** 349,352 ****
--- 350,359 ----
units = strscpy (NULL, "");
+ if (port == NULL)
+ port = strscpy(NULL,"161");
+
+ if (port == NULL)
+ port = strscpy(NULL,"161");
+
return c;
}
***************
*** 410,413 ****
--- 417,421 ----
case 'l':
case 'u':
+ case 'p':
i++;
}
***************
*** 609,612 ****
--- 617,622 ----
" -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"
Index: check_nagios.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_nagios.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_nagios.c 28 Feb 2002 06:43:00 -0000 1.1.1.1
--- check_nagios.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 102,106 ****
/* 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);
/* close stderr */
--- 102,106 ----
/* If we get anything on stderr, at least set warning */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max_state (result, STATE_WARNING);
/* close stderr */
***************
*** 109,113 ****
/* close the pipe */
if (spclose (child_process))
! result = max (result, STATE_WARNING);
/* reset the alarm handler */
--- 109,113 ----
/* close the pipe */
if (spclose (child_process))
! result = max_state (result, STATE_WARNING);
/* reset the alarm handler */
Index: check_vsz.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_vsz.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_vsz.c 28 Feb 2002 06:42:59 -0000 1.1.1.1
--- check_vsz.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 94,98 ****
"check_vsz: could not malloc message (1)");
sprintf (message, "%s %s(%d)", message, proc_name, proc_size);
! result = max (result, STATE_WARNING);
}
if (proc_size > crit) {
--- 94,98 ----
"check_vsz: could not malloc message (1)");
sprintf (message, "%s %s(%d)", message, proc_name, proc_size);
! result = max_state (result, STATE_WARNING);
}
if (proc_size > crit) {
***************
*** 108,112 ****
sprintf (message, "%s %d", message, proc_size);
if (proc_size > warn) {
! result = max (result, STATE_WARNING);
}
if (proc_size > crit) {
--- 108,112 ----
sprintf (message, "%s %d", message, proc_size);
if (proc_size > warn) {
! result = max_state (result, STATE_WARNING);
}
if (proc_size > crit) {
***************
*** 119,123 ****
/* 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);
(void) fclose (child_stderr);
--- 119,123 ----
/* If we get anything on STDERR, at least set warning */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
! result = max_state (result, STATE_WARNING);
(void) fclose (child_stderr);
***************
*** 125,129 ****
/* close the pipe */
if (spclose (child_process))
! result = max (result, STATE_WARNING);
if (result == STATE_OK)
--- 125,129 ----
/* close the pipe */
if (spclose (child_process))
! result = max_state (result, STATE_WARNING);
if (result == STATE_OK)
Index: utils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** utils.c 28 Feb 2002 06:43:00 -0000 1.1.1.1
--- utils.c 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 59,62 ****
--- 59,100 ----
#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)
Index: utils.h.in
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** utils.h.in 28 Feb 2002 06:43:00 -0000 1.1.1.1
--- utils.h.in 19 Jun 2002 05:11:52 -0000 1.2
***************
*** 1,3 ****
! /* header file for nagios plugins uitls.c */
/* this file should be included in all plugins */
--- 1,3 ----
! /* header file for nagios plugins utils.c */
/* this file should be included in all plugins */
***************
*** 56,59 ****
--- 56,62 ----
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)
***************
*** 74,78 ****
(a)==1?"WARNING":\
(a)==2?"CRITICAL":\
! (a)==-2?"DEPENDENT":\
"UNKNOWN"
--- 77,82 ----
(a)==1?"WARNING":\
(a)==2?"CRITICAL":\
! (a)==3?"UNKNOWN":\
! (a)==4?"DEPENDENT":\
"UNKNOWN"
More information about the Commits
mailing list