diff options
author | Jan Wagner <waja@cyconet.org> | 2022-01-21 11:04:14 +0100 |
---|---|---|
committer | waja <waja@users.noreply.github.com> | 2022-01-22 22:25:21 +0100 |
commit | b14e251d0f28cc2acb93df79da099bb3cdb5ec08 (patch) | |
tree | 8d8136f1c3721903942d044e1d02414b60fd5b84 | |
parent | cf669f5ff51b746569ded30e990b9d53e5234da0 (diff) | |
download | monitoring-plugins-b14e251d0f28cc2acb93df79da099bb3cdb5ec08.tar.gz |
Implements 'host-alive' mode (Closes. #1027)
To reduce the check-duration, it addes a host-alive flag which stops testing
after the first successful reply.
-rw-r--r-- | plugins/check_fping.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 521d0fef..540650ae 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
@@ -65,6 +65,7 @@ double crta; | |||
65 | double wrta; | 65 | double wrta; |
66 | int cpl_p = FALSE; | 66 | int cpl_p = FALSE; |
67 | int wpl_p = FALSE; | 67 | int wpl_p = FALSE; |
68 | int alive_p = FALSE; | ||
68 | int crta_p = FALSE; | 69 | int crta_p = FALSE; |
69 | int wrta_p = FALSE; | 70 | int wrta_p = FALSE; |
70 | 71 | ||
@@ -150,6 +151,19 @@ main (int argc, char **argv) | |||
150 | if (result = spclose (child_process)) | 151 | if (result = spclose (child_process)) |
151 | /* need to use max_state not max */ | 152 | /* need to use max_state not max */ |
152 | status = max_state (status, STATE_WARNING); | 153 | status = max_state (status, STATE_WARNING); |
154 | if (alive_p && strstr (buf, "avg, 0% loss)")){ | ||
155 | rtastr = strstr (buf, "ms ("); | ||
156 | rtastr = 1 + index (rtastr, '('); | ||
157 | rta = strtod (rtastr, NULL); | ||
158 | loss=strtod ("0",NULL); | ||
159 | die (STATE_OK, | ||
160 | _("FPING %s - %s (rta=%f ms)|%s %s\n"), | ||
161 | state_text (STATE_OK), server_name,rta, | ||
162 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), | ||
163 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); | ||
164 | |||
165 | } | ||
166 | |||
153 | 167 | ||
154 | if (result > 1 ) { | 168 | if (result > 1 ) { |
155 | status = max_state (status, STATE_UNKNOWN); | 169 | status = max_state (status, STATE_UNKNOWN); |
@@ -275,6 +289,9 @@ process_arguments (int argc, char **argv) | |||
275 | static struct option longopts[] = { | 289 | static struct option longopts[] = { |
276 | {"hostname", required_argument, 0, 'H'}, | 290 | {"hostname", required_argument, 0, 'H'}, |
277 | {"sourceip", required_argument, 0, 'S'}, | 291 | {"sourceip", required_argument, 0, 'S'}, |
292 | case 'a': /* host alive mode */ | ||
293 | alive_p = TRUE; | ||
294 | break; | ||
278 | {"sourceif", required_argument, 0, 'I'}, | 295 | {"sourceif", required_argument, 0, 'I'}, |
279 | {"critical", required_argument, 0, 'c'}, | 296 | {"critical", required_argument, 0, 'c'}, |
280 | {"warning", required_argument, 0, 'w'}, | 297 | {"warning", required_argument, 0, 'w'}, |
@@ -304,7 +321,7 @@ process_arguments (int argc, char **argv) | |||
304 | } | 321 | } |
305 | 322 | ||
306 | while (1) { | 323 | while (1) { |
307 | c = getopt_long (argc, argv, "+hVvH:S:c:w:b:n:T:i:I:46", longopts, &option); | 324 | c = getopt_long (argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:46", longopts, &option); |
308 | 325 | ||
309 | if (c == -1 || c == EOF || c == 1) | 326 | if (c == -1 || c == EOF || c == 1) |
310 | break; | 327 | break; |
@@ -416,6 +433,9 @@ get_threshold (char *arg, char *rv[2]) | |||
416 | arg2 = 1 + strpbrk (arg1, ",:"); | 433 | arg2 = 1 + strpbrk (arg1, ",:"); |
417 | 434 | ||
418 | if (arg2) { | 435 | if (arg2) { |
436 | printf (" %s\n", "-a"); | ||
437 | printf (" %s\n", _("Return OK after first successfull reply")); | ||
438 | |||
419 | arg1[strcspn (arg1, ",:")] = 0; | 439 | arg1[strcspn (arg1, ",:")] = 0; |
420 | if (strstr (arg1, "%") && strstr (arg2, "%")) | 440 | if (strstr (arg1, "%") && strstr (arg2, "%")) |
421 | die (STATE_UNKNOWN, | 441 | die (STATE_UNKNOWN, |