diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_dig.c | 4 | ||||
-rw-r--r-- | plugins/check_dns.c | 4 | ||||
-rw-r--r-- | plugins/check_fping.c | 30 | ||||
-rw-r--r-- | plugins/check_hpjd.c | 4 | ||||
-rw-r--r-- | plugins/check_nagios.c | 4 | ||||
-rw-r--r-- | plugins/check_ping.c | 2 | ||||
-rw-r--r-- | plugins/check_snmp.c | 16 | ||||
-rw-r--r-- | plugins/check_vsz.c | 8 | ||||
-rw-r--r-- | plugins/urlize.c | 2 | ||||
-rw-r--r-- | plugins/utils.c | 38 | ||||
-rw-r--r-- | plugins/utils.h.in | 8 |
11 files changed, 96 insertions, 24 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 57609ac..384b380 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -98,7 +98,7 @@ main (int argc, char **argv) | |||
98 | 98 | ||
99 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 99 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
100 | /* If we get anything on STDERR, at least set warning */ | 100 | /* If we get anything on STDERR, at least set warning */ |
101 | result = max (result, STATE_WARNING); | 101 | result = max_state (result, STATE_WARNING); |
102 | printf ("%s", input_buffer); | 102 | printf ("%s", input_buffer); |
103 | if (!strcmp (output, "")) | 103 | if (!strcmp (output, "")) |
104 | strcpy (output, 1 + index (input_buffer, ':')); | 104 | strcpy (output, 1 + index (input_buffer, ':')); |
@@ -108,7 +108,7 @@ main (int argc, char **argv) | |||
108 | 108 | ||
109 | /* close the pipe */ | 109 | /* close the pipe */ |
110 | if (spclose (child_process)) { | 110 | if (spclose (child_process)) { |
111 | result = max (result, STATE_WARNING); | 111 | result = max_state (result, STATE_WARNING); |
112 | if (!strcmp (output, "")) | 112 | if (!strcmp (output, "")) |
113 | strcpy (output, "nslookup returned error status"); | 113 | strcpy (output, "nslookup returned error status"); |
114 | } | 114 | } |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index eaff437..a0d6e85 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -150,7 +150,7 @@ main (int argc, char **argv) | |||
150 | /* scan stderr */ | 150 | /* scan stderr */ |
151 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 151 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
152 | if (error_scan (input_buffer) != STATE_OK) { | 152 | if (error_scan (input_buffer) != STATE_OK) { |
153 | result = max (result, error_scan (input_buffer)); | 153 | result = max_state (result, error_scan (input_buffer)); |
154 | output = strscpy (output, 1 + index (input_buffer, ':')); | 154 | output = strscpy (output, 1 + index (input_buffer, ':')); |
155 | } | 155 | } |
156 | } | 156 | } |
@@ -160,7 +160,7 @@ main (int argc, char **argv) | |||
160 | 160 | ||
161 | /* close stdout */ | 161 | /* close stdout */ |
162 | if (spclose (child_process)) { | 162 | if (spclose (child_process)) { |
163 | result = max (result, STATE_WARNING); | 163 | result = max_state (result, STATE_WARNING); |
164 | if (!strcmp (output, "")) | 164 | if (!strcmp (output, "")) |
165 | output = strscpy (output, "nslookup returned error status"); | 165 | output = strscpy (output, "nslookup returned error status"); |
166 | } | 166 | } |
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index f6531a5..9a2dd55 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
@@ -93,21 +93,22 @@ main (int argc, char **argv) | |||
93 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 93 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
94 | if (verbose) | 94 | if (verbose) |
95 | printf ("%s", input_buffer); | 95 | printf ("%s", input_buffer); |
96 | status = max (status, textscan (input_buffer)); | 96 | status = max_state (status, textscan (input_buffer)); |
97 | } | 97 | } |
98 | 98 | ||
99 | /* If we get anything on STDERR, at least set warning */ | 99 | /* If we get anything on STDERR, at least set warning */ |
100 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 100 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
101 | status = max (status, STATE_WARNING); | 101 | status = max_state (status, STATE_WARNING); |
102 | if (verbose) | 102 | if (verbose) |
103 | printf ("%s", input_buffer); | 103 | printf ("%s", input_buffer); |
104 | status = max (status, textscan (input_buffer)); | 104 | status = max_state (status, textscan (input_buffer)); |
105 | } | 105 | } |
106 | (void) fclose (child_stderr); | 106 | (void) fclose (child_stderr); |
107 | 107 | ||
108 | /* close the pipe */ | 108 | /* close the pipe */ |
109 | if (spclose (child_process)) | 109 | if (spclose (child_process)) |
110 | status = max (status, STATE_WARNING); | 110 | /* need to use max_state not max */ |
111 | status = max_state (status, STATE_WARNING); | ||
111 | 112 | ||
112 | printf ("FPING %s - %s\n", state_text (status), server_name); | 113 | printf ("FPING %s - %s\n", state_text (status), server_name); |
113 | 114 | ||
@@ -166,8 +167,27 @@ textscan (char *buf) | |||
166 | state_text (status), server_name, loss, rta); | 167 | state_text (status), server_name, loss, rta); |
167 | 168 | ||
168 | } | 169 | } |
170 | else if(strstr (buf, "xmt/rcv/%loss") ) { | ||
171 | /* no min/max/avg if host was unreachable in fping v2.2.b1 */ | ||
172 | losstr = strstr (buf, "="); | ||
173 | losstr = 1 + strstr (losstr, "/"); | ||
174 | losstr = 1 + strstr (losstr, "/"); | ||
175 | loss = strtod (losstr, NULL); | ||
176 | if (loss == 100) | ||
177 | status = STATE_CRITICAL; | ||
178 | else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl) | ||
179 | status = STATE_CRITICAL; | ||
180 | else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl) | ||
181 | status = STATE_WARNING; | ||
182 | else | ||
183 | status = STATE_OK; | ||
184 | |||
185 | terminate (status, "FPING %s - %s (loss=%f%% )\n", | ||
186 | state_text (status), server_name, loss ); | ||
187 | |||
188 | } | ||
169 | else { | 189 | else { |
170 | status = max (status, STATE_WARNING); | 190 | status = max_state (status, STATE_WARNING); |
171 | } | 191 | } |
172 | 192 | ||
173 | return status; | 193 | return status; |
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 9d1878a..b45dfcc 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -285,14 +285,14 @@ main (int argc, char **argv) | |||
285 | 285 | ||
286 | /* WARNING if output found on stderr */ | 286 | /* WARNING if output found on stderr */ |
287 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 287 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) |
288 | result = max (result, STATE_WARNING); | 288 | result = max_state (result, STATE_WARNING); |
289 | 289 | ||
290 | /* close stderr */ | 290 | /* close stderr */ |
291 | (void) fclose (child_stderr); | 291 | (void) fclose (child_stderr); |
292 | 292 | ||
293 | /* close the pipe */ | 293 | /* close the pipe */ |
294 | if (spclose (child_process)) | 294 | if (spclose (child_process)) |
295 | result = max (result, STATE_WARNING); | 295 | result = max_state (result, STATE_WARNING); |
296 | 296 | ||
297 | /* if there wasn't any output, display an error */ | 297 | /* if there wasn't any output, display an error */ |
298 | if (line == 0) { | 298 | if (line == 0) { |
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index 0425835..ea79d24 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c | |||
@@ -101,14 +101,14 @@ main (int argc, char **argv) | |||
101 | 101 | ||
102 | /* If we get anything on stderr, at least set warning */ | 102 | /* If we get anything on stderr, at least set warning */ |
103 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 103 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) |
104 | result = max (result, STATE_WARNING); | 104 | result = max_state (result, STATE_WARNING); |
105 | 105 | ||
106 | /* close stderr */ | 106 | /* close stderr */ |
107 | (void) fclose (child_stderr); | 107 | (void) fclose (child_stderr); |
108 | 108 | ||
109 | /* close the pipe */ | 109 | /* close the pipe */ |
110 | if (spclose (child_process)) | 110 | if (spclose (child_process)) |
111 | result = max (result, STATE_WARNING); | 111 | result = max_state (result, STATE_WARNING); |
112 | 112 | ||
113 | /* reset the alarm handler */ | 113 | /* reset the alarm handler */ |
114 | alarm (0); | 114 | alarm (0); |
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 420f148..835d9c1 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -483,7 +483,7 @@ run_ping (char *command_line) | |||
483 | 483 | ||
484 | /* close the pipe - WARNING if status is set */ | 484 | /* close the pipe - WARNING if status is set */ |
485 | if (spclose (child_process)) | 485 | if (spclose (child_process)) |
486 | result = max (result, STATE_WARNING); | 486 | result = max_state (result, STATE_WARNING); |
487 | 487 | ||
488 | return result; | 488 | return result; |
489 | } | 489 | } |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 2f970b3..8e977e8 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -97,6 +97,7 @@ char *community = NULL; | |||
97 | char oid[MAX_INPUT_BUFFER] = ""; | 97 | char oid[MAX_INPUT_BUFFER] = ""; |
98 | char *label = NULL; | 98 | char *label = NULL; |
99 | char *units = NULL; | 99 | char *units = NULL; |
100 | char *port = NULL; | ||
100 | char string_value[MAX_INPUT_BUFFER] = ""; | 101 | char string_value[MAX_INPUT_BUFFER] = ""; |
101 | char **labels = NULL; | 102 | char **labels = NULL; |
102 | char **unitv = NULL; | 103 | char **unitv = NULL; |
@@ -259,7 +260,7 @@ main (int argc, char **argv) | |||
259 | iresult = STATE_WARNING; | 260 | iresult = STATE_WARNING; |
260 | } | 261 | } |
261 | 262 | ||
262 | result = max (result, iresult); | 263 | result = max_state (result, iresult); |
263 | 264 | ||
264 | if (nlabels > 1 && i < nlabels && labels[i] != NULL) | 265 | if (nlabels > 1 && i < nlabels && labels[i] != NULL) |
265 | outbuff = ssprintf | 266 | outbuff = ssprintf |
@@ -290,14 +291,14 @@ main (int argc, char **argv) | |||
290 | 291 | ||
291 | /* WARNING if output found on stderr */ | 292 | /* WARNING if output found on stderr */ |
292 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 293 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) |
293 | result = max (result, STATE_WARNING); | 294 | result = max_state (result, STATE_WARNING); |
294 | 295 | ||
295 | /* close stderr */ | 296 | /* close stderr */ |
296 | (void) fclose (child_stderr); | 297 | (void) fclose (child_stderr); |
297 | 298 | ||
298 | /* close the pipe */ | 299 | /* close the pipe */ |
299 | if (spclose (child_process)) | 300 | if (spclose (child_process)) |
300 | result = max (result, STATE_WARNING); | 301 | result = max_state (result, STATE_WARNING); |
301 | 302 | ||
302 | if (nunits > 0) | 303 | if (nunits > 0) |
303 | printf ("%s %s -%s\n", label, state_text (result), outbuff); | 304 | printf ("%s %s -%s\n", label, state_text (result), outbuff); |
@@ -348,6 +349,12 @@ process_arguments (int argc, char **argv) | |||
348 | if (units == NULL) | 349 | if (units == NULL) |
349 | units = strscpy (NULL, ""); | 350 | units = strscpy (NULL, ""); |
350 | 351 | ||
352 | if (port == NULL) | ||
353 | port = strscpy(NULL,"161"); | ||
354 | |||
355 | if (port == NULL) | ||
356 | port = strscpy(NULL,"161"); | ||
357 | |||
351 | return c; | 358 | return c; |
352 | } | 359 | } |
353 | 360 | ||
@@ -409,6 +416,7 @@ call_getopt (int argc, char **argv) | |||
409 | case 'r': | 416 | case 'r': |
410 | case 'l': | 417 | case 'l': |
411 | case 'u': | 418 | case 'u': |
419 | case 'p': | ||
412 | i++; | 420 | i++; |
413 | } | 421 | } |
414 | 422 | ||
@@ -608,6 +616,8 @@ print_help (char *cmd) | |||
608 | " (default is \"public\")\n" | 616 | " (default is \"public\")\n" |
609 | " -u, --units=STRING\n" | 617 | " -u, --units=STRING\n" |
610 | " Units label(s) for output data (e.g., 'sec.').\n" | 618 | " Units label(s) for output data (e.g., 'sec.').\n" |
619 | " -p, --port=STRING\n" | ||
620 | " TCP port number target is listening on.\n" | ||
611 | " -d, --delimiter=STRING\n" | 621 | " -d, --delimiter=STRING\n" |
612 | " Delimiter to use when parsing returned data. Default is \"%s\"\n" | 622 | " Delimiter to use when parsing returned data. Default is \"%s\"\n" |
613 | " Any data on the right hand side of the delimiter is considered\n" | 623 | " 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 c8ca82b..f53eeae 100644 --- a/plugins/check_vsz.c +++ b/plugins/check_vsz.c | |||
@@ -93,7 +93,7 @@ main (int argc, char **argv) | |||
93 | terminate (STATE_UNKNOWN, | 93 | terminate (STATE_UNKNOWN, |
94 | "check_vsz: could not malloc message (1)"); | 94 | "check_vsz: could not malloc message (1)"); |
95 | sprintf (message, "%s %s(%d)", message, proc_name, proc_size); | 95 | sprintf (message, "%s %s(%d)", message, proc_name, proc_size); |
96 | result = max (result, STATE_WARNING); | 96 | result = max_state (result, STATE_WARNING); |
97 | } | 97 | } |
98 | if (proc_size > crit) { | 98 | if (proc_size > crit) { |
99 | result = STATE_CRITICAL; | 99 | result = STATE_CRITICAL; |
@@ -107,7 +107,7 @@ main (int argc, char **argv) | |||
107 | "check_vsz: could not malloc message (2)"); | 107 | "check_vsz: could not malloc message (2)"); |
108 | sprintf (message, "%s %d", message, proc_size); | 108 | sprintf (message, "%s %d", message, proc_size); |
109 | if (proc_size > warn) { | 109 | if (proc_size > warn) { |
110 | result = max (result, STATE_WARNING); | 110 | result = max_state (result, STATE_WARNING); |
111 | } | 111 | } |
112 | if (proc_size > crit) { | 112 | if (proc_size > crit) { |
113 | result = STATE_CRITICAL; | 113 | result = STATE_CRITICAL; |
@@ -118,13 +118,13 @@ main (int argc, char **argv) | |||
118 | 118 | ||
119 | /* If we get anything on STDERR, at least set warning */ | 119 | /* If we get anything on STDERR, at least set warning */ |
120 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 120 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) |
121 | result = max (result, STATE_WARNING); | 121 | result = max_state (result, STATE_WARNING); |
122 | 122 | ||
123 | (void) fclose (child_stderr); | 123 | (void) fclose (child_stderr); |
124 | 124 | ||
125 | /* close the pipe */ | 125 | /* close the pipe */ |
126 | if (spclose (child_process)) | 126 | if (spclose (child_process)) |
127 | result = max (result, STATE_WARNING); | 127 | result = max_state (result, STATE_WARNING); |
128 | 128 | ||
129 | if (result == STATE_OK) | 129 | if (result == STATE_OK) |
130 | printf ("ok (all VSZ<%d): %s\n", warn, message); | 130 | printf ("ok (all VSZ<%d): %s\n", warn, message); |
diff --git a/plugins/urlize.c b/plugins/urlize.c index 83c37da..c04ac0e 100644 --- a/plugins/urlize.c +++ b/plugins/urlize.c | |||
@@ -110,7 +110,7 @@ main (int argc, char **argv) | |||
110 | 110 | ||
111 | /* WARNING if output found on stderr */ | 111 | /* WARNING if output found on stderr */ |
112 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 112 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) |
113 | result = max (result, STATE_WARNING); | 113 | result = max_state (result, STATE_WARNING); |
114 | 114 | ||
115 | /* close stderr */ | 115 | /* close stderr */ |
116 | (void) fclose (child_stderr); | 116 | (void) fclose (child_stderr); |
diff --git a/plugins/utils.c b/plugins/utils.c index 49e4d3d..8bec1cf 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -58,6 +58,44 @@ char *strpcat (char *dest, const char *src, const char *str); | |||
58 | 58 | ||
59 | #define max(a,b) ((a)>(b))?(a):(b) | 59 | #define max(a,b) ((a)>(b))?(a):(b) |
60 | 60 | ||
61 | /* ************************************************************************** | ||
62 | * max_state(result, STATE_x) | ||
63 | * compares STATE_x to result and returns result if STATE_x is less than a based on the following | ||
64 | * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL | ||
65 | * | ||
66 | * Note that numerically the above does not hold | ||
67 | ****************************************************************************/ | ||
68 | |||
69 | int | ||
70 | max_state(int a, int b) | ||
71 | { | ||
72 | if(a == STATE_CRITICAL){ | ||
73 | return a; | ||
74 | } | ||
75 | else if (a == STATE_WARNING) { | ||
76 | |||
77 | if (b == STATE_CRITICAL){ | ||
78 | return b; | ||
79 | }else { | ||
80 | return a; | ||
81 | } | ||
82 | } | ||
83 | else if (a == STATE_OK) { | ||
84 | |||
85 | if ( b== STATE_CRITICAL || b == STATE_WARNING) { | ||
86 | return b; | ||
87 | }else{ | ||
88 | return a; | ||
89 | } | ||
90 | } | ||
91 | else { | ||
92 | /* a == UNKNOWN */ | ||
93 | return b; | ||
94 | } | ||
95 | |||
96 | |||
97 | } | ||
98 | |||
61 | char * | 99 | char * |
62 | my_basename (char *path) | 100 | my_basename (char *path) |
63 | { | 101 | { |
diff --git a/plugins/utils.h.in b/plugins/utils.h.in index a21d63d..46b152a 100644 --- a/plugins/utils.h.in +++ b/plugins/utils.h.in | |||
@@ -1,4 +1,4 @@ | |||
1 | /* header file for nagios plugins uitls.c */ | 1 | /* header file for nagios plugins utils.c */ |
2 | 2 | ||
3 | /* this file should be included in all plugins */ | 3 | /* this file should be included in all plugins */ |
4 | 4 | ||
@@ -55,6 +55,9 @@ char *ssprintf (char *str, const char *fmt, ...); | |||
55 | char *strpcpy (char *dest, const char *src, const char *str); | 55 | char *strpcpy (char *dest, const char *src, const char *str); |
56 | char *strpcat (char *dest, const char *src, const char *str); | 56 | char *strpcat (char *dest, const char *src, const char *str); |
57 | 57 | ||
58 | /* Handle comparisions for STATE_* */ | ||
59 | int max_state(int, int); | ||
60 | |||
58 | #define max(a,b) ((a)>(b))?(a):(b) | 61 | #define max(a,b) ((a)>(b))?(a):(b) |
59 | 62 | ||
60 | #define usage(msg) {\ | 63 | #define usage(msg) {\ |
@@ -73,7 +76,8 @@ exit(STATE_UNKNOWN);\ | |||
73 | (a)==0?"OK":\ | 76 | (a)==0?"OK":\ |
74 | (a)==1?"WARNING":\ | 77 | (a)==1?"WARNING":\ |
75 | (a)==2?"CRITICAL":\ | 78 | (a)==2?"CRITICAL":\ |
76 | (a)==-2?"DEPENDENT":\ | 79 | (a)==3?"UNKNOWN":\ |
80 | (a)==4?"DEPENDENT":\ | ||
77 | "UNKNOWN" | 81 | "UNKNOWN" |
78 | 82 | ||
79 | /* The idea here is that, although not every plugin will use all of these, | 83 | /* The idea here is that, although not every plugin will use all of these, |