summaryrefslogtreecommitdiffstats
path: root/plugins/check_fping.c
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2022-01-22 19:01:49 (GMT)
committerwaja <waja@users.noreply.github.com>2022-01-22 21:25:21 (GMT)
commit3bcc64396d8768d984eb58eb0a80213c2a8528ca (patch)
tree1a7a74163692f744b386618a6f88bcca6b2877ce /plugins/check_fping.c
parentb14e251d0f28cc2acb93df79da099bb3cdb5ec08 (diff)
downloadmonitoring-plugins-3bcc64396d8768d984eb58eb0a80213c2a8528ca.tar.gz
Fixes the positioning of the code and some other changes
Diffstat (limited to 'plugins/check_fping.c')
-rw-r--r--plugins/check_fping.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 540650a..be9362a 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -37,6 +37,7 @@ const char *email = "devel@monitoring-plugins.org";
37#include "popen.h" 37#include "popen.h"
38#include "netutils.h" 38#include "netutils.h"
39#include "utils.h" 39#include "utils.h"
40#include <stdbool.h>
40 41
41enum { 42enum {
42 PACKET_COUNT = 1, 43 PACKET_COUNT = 1,
@@ -65,7 +66,7 @@ double crta;
65double wrta; 66double wrta;
66int cpl_p = FALSE; 67int cpl_p = FALSE;
67int wpl_p = FALSE; 68int wpl_p = FALSE;
68int alive_p = FALSE; 69bool alive_p = FALSE;
69int crta_p = FALSE; 70int crta_p = FALSE;
70int wrta_p = FALSE; 71int wrta_p = FALSE;
71 72
@@ -148,23 +149,12 @@ main (int argc, char **argv)
148 (void) fclose (child_stderr); 149 (void) fclose (child_stderr);
149 150
150 /* close the pipe */ 151 /* close the pipe */
151 if (result = spclose (child_process)) 152 result = spclose (child_process);
153 if (result) {
152 /* need to use max_state not max */ 154 /* need to use max_state not max */
153 status = max_state (status, STATE_WARNING); 155 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 } 156 }
166 157
167
168 if (result > 1 ) { 158 if (result > 1 ) {
169 status = max_state (status, STATE_UNKNOWN); 159 status = max_state (status, STATE_UNKNOWN);
170 if (result == 2) { 160 if (result == 2) {
@@ -185,10 +175,7 @@ main (int argc, char **argv)
185} 175}
186 176
187 177
188 178int textscan (char *buf) {
189int
190textscan (char *buf)
191{
192 char *rtastr = NULL; 179 char *rtastr = NULL;
193 char *losstr = NULL; 180 char *losstr = NULL;
194 char *xmtstr = NULL; 181 char *xmtstr = NULL;
@@ -197,6 +184,20 @@ textscan (char *buf)
197 double xmt; 184 double xmt;
198 int status = STATE_UNKNOWN; 185 int status = STATE_UNKNOWN;
199 186
187 /* stops testing after the first successful reply. */
188 if (alive_p && strstr(buf, "avg, 0% loss)")) {
189 rtastr = strstr (buf, "ms (");
190 rtastr = 1 + index(rtastr, '(');
191 rta = strtod(rtastr, NULL);
192 loss=strtod("0",NULL);
193 die (STATE_OK,
194 _("FPING %s - %s (rta=%f ms)|%s\n"),
195 state_text (STATE_OK), server_name,rta,
196 /* No loss since we only waited for the first reply
197 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), */
198 fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));
199 }
200
200 if (strstr (buf, "not found")) { 201 if (strstr (buf, "not found")) {
201 die (STATE_CRITICAL, _("FPING UNKNOWN - %s not found\n"), server_name); 202 die (STATE_CRITICAL, _("FPING UNKNOWN - %s not found\n"), server_name);
202 203
@@ -289,12 +290,10 @@ process_arguments (int argc, char **argv)
289 static struct option longopts[] = { 290 static struct option longopts[] = {
290 {"hostname", required_argument, 0, 'H'}, 291 {"hostname", required_argument, 0, 'H'},
291 {"sourceip", required_argument, 0, 'S'}, 292 {"sourceip", required_argument, 0, 'S'},
292 case 'a': /* host alive mode */
293 alive_p = TRUE;
294 break;
295 {"sourceif", required_argument, 0, 'I'}, 293 {"sourceif", required_argument, 0, 'I'},
296 {"critical", required_argument, 0, 'c'}, 294 {"critical", required_argument, 0, 'c'},
297 {"warning", required_argument, 0, 'w'}, 295 {"warning", required_argument, 0, 'w'},
296 {"alive", no_argument, 0, 'a'},
298 {"bytes", required_argument, 0, 'b'}, 297 {"bytes", required_argument, 0, 'b'},
299 {"number", required_argument, 0, 'n'}, 298 {"number", required_argument, 0, 'n'},
300 {"target-timeout", required_argument, 0, 'T'}, 299 {"target-timeout", required_argument, 0, 'T'},
@@ -329,6 +328,9 @@ process_arguments (int argc, char **argv)
329 switch (c) { 328 switch (c) {
330 case '?': /* print short usage statement if args not parsable */ 329 case '?': /* print short usage statement if args not parsable */
331 usage5 (); 330 usage5 ();
331 case 'a': /* host alive mode */
332 alive_p = TRUE;
333 break;
332 case 'h': /* help */ 334 case 'h': /* help */
333 print_help (); 335 print_help ();
334 exit (STATE_UNKNOWN); 336 exit (STATE_UNKNOWN);
@@ -433,9 +435,6 @@ get_threshold (char *arg, char *rv[2])
433 arg2 = 1 + strpbrk (arg1, ",:"); 435 arg2 = 1 + strpbrk (arg1, ",:");
434 436
435 if (arg2) { 437 if (arg2) {
436 printf (" %s\n", "-a");
437 printf (" %s\n", _("Return OK after first successfull reply"));
438
439 arg1[strcspn (arg1, ",:")] = 0; 438 arg1[strcspn (arg1, ",:")] = 0;
440 if (strstr (arg1, "%") && strstr (arg2, "%")) 439 if (strstr (arg1, "%") && strstr (arg2, "%"))
441 die (STATE_UNKNOWN, 440 die (STATE_UNKNOWN,
@@ -466,9 +465,7 @@ get_threshold (char *arg, char *rv[2])
466} 465}
467 466
468 467
469void 468void print_help (void) {
470print_help (void)
471{
472 469
473 print_revision (progname, NP_VERSION); 470 print_revision (progname, NP_VERSION);
474 471
@@ -494,6 +491,8 @@ print_help (void)
494 printf (" %s\n", _("warning threshold pair")); 491 printf (" %s\n", _("warning threshold pair"));
495 printf (" %s\n", "-c, --critical=THRESHOLD"); 492 printf (" %s\n", "-c, --critical=THRESHOLD");
496 printf (" %s\n", _("critical threshold pair")); 493 printf (" %s\n", _("critical threshold pair"));
494 printf (" %s\n", "-a, --alive");
495 printf (" %s\n", _("Return OK after first successfull reply"));
497 printf (" %s\n", "-b, --bytes=INTEGER"); 496 printf (" %s\n", "-b, --bytes=INTEGER");
498 printf (" %s (default: %d)\n", _("size of ICMP packet"),PACKET_SIZE); 497 printf (" %s (default: %d)\n", _("size of ICMP packet"),PACKET_SIZE);
499 printf (" %s\n", "-n, --number=INTEGER"); 498 printf (" %s\n", "-n, --number=INTEGER");