aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/check_dig.c4
-rw-r--r--plugins/check_dns.c4
-rw-r--r--plugins/check_fping.c30
-rw-r--r--plugins/check_hpjd.c4
-rw-r--r--plugins/check_nagios.c4
-rw-r--r--plugins/check_ping.c2
-rw-r--r--plugins/check_snmp.c16
-rw-r--r--plugins/check_vsz.c8
-rw-r--r--plugins/urlize.c2
-rw-r--r--plugins/utils.c38
-rw-r--r--plugins/utils.h.in8
11 files changed, 96 insertions, 24 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 57609acd..384b380b 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -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");
}
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index eaff4372..a0d6e85e 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -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");
}
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index f6531a54..9a2dd557 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -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);
@@ -166,8 +167,27 @@ textscan (char *buf)
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;
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 9d1878a4..b45dfcc7 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -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) {
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index 04258354..ea79d247 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -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);
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 420f148c..835d9c1b 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -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;
}
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 2f970b3d..8e977e82 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -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"
diff --git a/plugins/check_vsz.c b/plugins/check_vsz.c
index c8ca82bd..f53eeae3 100644
--- a/plugins/check_vsz.c
+++ b/plugins/check_vsz.c
@@ -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);
diff --git a/plugins/urlize.c b/plugins/urlize.c
index 83c37dac..c04ac0e3 100644
--- a/plugins/urlize.c
+++ b/plugins/urlize.c
@@ -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);
diff --git a/plugins/utils.c b/plugins/utils.c
index 49e4d3d7..8bec1cf1 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -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)
{
diff --git a/plugins/utils.h.in b/plugins/utils.h.in
index a21d63d6..46b152a3 100644
--- a/plugins/utils.h.in
+++ b/plugins/utils.h.in
@@ -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,