diff options
Diffstat (limited to 'plugins/check_fping.c')
-rw-r--r-- | plugins/check_fping.c | 78 |
1 files changed, 72 insertions, 6 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 675a547..c7cce97 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
@@ -52,6 +52,8 @@ void print_help (void); | |||
52 | void print_usage (void); | 52 | void print_usage (void); |
53 | 53 | ||
54 | char *server_name = NULL; | 54 | char *server_name = NULL; |
55 | char *sourceip = NULL; | ||
56 | char *sourceif = NULL; | ||
55 | int packet_size = PACKET_SIZE; | 57 | int packet_size = PACKET_SIZE; |
56 | int packet_count = PACKET_COUNT; | 58 | int packet_count = PACKET_COUNT; |
57 | int target_timeout = 0; | 59 | int target_timeout = 0; |
@@ -72,6 +74,8 @@ main (int argc, char **argv) | |||
72 | /* normaly should be int result = STATE_UNKNOWN; */ | 74 | /* normaly should be int result = STATE_UNKNOWN; */ |
73 | 75 | ||
74 | int status = STATE_UNKNOWN; | 76 | int status = STATE_UNKNOWN; |
77 | int result = 0; | ||
78 | char *fping_prog = NULL; | ||
75 | char *server = NULL; | 79 | char *server = NULL; |
76 | char *command_line = NULL; | 80 | char *command_line = NULL; |
77 | char *input_buffer = NULL; | 81 | char *input_buffer = NULL; |
@@ -95,8 +99,21 @@ main (int argc, char **argv) | |||
95 | xasprintf(&option_string, "%s-t %d ", option_string, target_timeout); | 99 | xasprintf(&option_string, "%s-t %d ", option_string, target_timeout); |
96 | if (packet_interval) | 100 | if (packet_interval) |
97 | xasprintf(&option_string, "%s-p %d ", option_string, packet_interval); | 101 | xasprintf(&option_string, "%s-p %d ", option_string, packet_interval); |
98 | 102 | if (sourceip) | |
99 | xasprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING, | 103 | xasprintf(&option_string, "%s-S %s ", option_string, sourceip); |
104 | if (sourceif) | ||
105 | xasprintf(&option_string, "%s-I %s ", option_string, sourceif); | ||
106 | |||
107 | #ifdef PATH_TO_FPING6 | ||
108 | if (address_family == AF_INET6) | ||
109 | fping_prog = strdup(PATH_TO_FPING6); | ||
110 | else | ||
111 | fping_prog = strdup(PATH_TO_FPING); | ||
112 | #else | ||
113 | fping_prog = strdup(PATH_TO_FPING); | ||
114 | #endif | ||
115 | |||
116 | xasprintf (&command_line, "%s %s-b %d -c %d %s", fping_prog, | ||
100 | option_string, packet_size, packet_count, server); | 117 | option_string, packet_size, packet_count, server); |
101 | 118 | ||
102 | if (verbose) | 119 | if (verbose) |
@@ -130,10 +147,24 @@ main (int argc, char **argv) | |||
130 | (void) fclose (child_stderr); | 147 | (void) fclose (child_stderr); |
131 | 148 | ||
132 | /* close the pipe */ | 149 | /* close the pipe */ |
133 | if (spclose (child_process)) | 150 | if (result = spclose (child_process)) |
134 | /* need to use max_state not max */ | 151 | /* need to use max_state not max */ |
135 | status = max_state (status, STATE_WARNING); | 152 | status = max_state (status, STATE_WARNING); |
136 | 153 | ||
154 | if (result > 1 ) { | ||
155 | status = max_state (status, STATE_UNKNOWN); | ||
156 | if (result == 2) { | ||
157 | die (STATE_UNKNOWN, _("FPING UNKNOWN - IP address not found\n")); | ||
158 | } | ||
159 | if (result == 3) { | ||
160 | die (STATE_UNKNOWN, _("FPING UNKNOWN - invalid commandline argument\n")); | ||
161 | } | ||
162 | if (result == 4) { | ||
163 | die (STATE_UNKNOWN, _("FPING UNKNOWN - failed system call\n")); | ||
164 | } | ||
165 | |||
166 | } | ||
167 | |||
137 | printf ("FPING %s - %s\n", state_text (status), server_name); | 168 | printf ("FPING %s - %s\n", state_text (status), server_name); |
138 | 169 | ||
139 | return status; | 170 | return status; |
@@ -159,6 +190,10 @@ textscan (char *buf) | |||
159 | "host"); | 190 | "host"); |
160 | 191 | ||
161 | } | 192 | } |
193 | else if (strstr (buf, "Operation not permitted") || strstr (buf, "No such device") ) { | ||
194 | die (STATE_UNKNOWN, _("FPING UNKNOWN - %s parameter error\n"), | ||
195 | "host"); | ||
196 | } | ||
162 | else if (strstr (buf, "is down")) { | 197 | else if (strstr (buf, "is down")) { |
163 | die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); | 198 | die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); |
164 | 199 | ||
@@ -232,6 +267,8 @@ process_arguments (int argc, char **argv) | |||
232 | int option = 0; | 267 | int option = 0; |
233 | static struct option longopts[] = { | 268 | static struct option longopts[] = { |
234 | {"hostname", required_argument, 0, 'H'}, | 269 | {"hostname", required_argument, 0, 'H'}, |
270 | {"sourceip", required_argument, 0, 'S'}, | ||
271 | {"sourceif", required_argument, 0, 'I'}, | ||
235 | {"critical", required_argument, 0, 'c'}, | 272 | {"critical", required_argument, 0, 'c'}, |
236 | {"warning", required_argument, 0, 'w'}, | 273 | {"warning", required_argument, 0, 'w'}, |
237 | {"bytes", required_argument, 0, 'b'}, | 274 | {"bytes", required_argument, 0, 'b'}, |
@@ -241,6 +278,8 @@ process_arguments (int argc, char **argv) | |||
241 | {"verbose", no_argument, 0, 'v'}, | 278 | {"verbose", no_argument, 0, 'v'}, |
242 | {"version", no_argument, 0, 'V'}, | 279 | {"version", no_argument, 0, 'V'}, |
243 | {"help", no_argument, 0, 'h'}, | 280 | {"help", no_argument, 0, 'h'}, |
281 | {"use-ipv4", no_argument, 0, '4'}, | ||
282 | {"use-ipv6", no_argument, 0, '6'}, | ||
244 | {0, 0, 0, 0} | 283 | {0, 0, 0, 0} |
245 | }; | 284 | }; |
246 | 285 | ||
@@ -258,7 +297,7 @@ process_arguments (int argc, char **argv) | |||
258 | } | 297 | } |
259 | 298 | ||
260 | while (1) { | 299 | while (1) { |
261 | c = getopt_long (argc, argv, "+hVvH:c:w:b:n:T:i:", longopts, &option); | 300 | c = getopt_long (argc, argv, "+hVvH:S:c:w:b:n:T:i:I:46", longopts, &option); |
262 | 301 | ||
263 | if (c == -1 || c == EOF || c == 1) | 302 | if (c == -1 || c == EOF || c == 1) |
264 | break; | 303 | break; |
@@ -281,6 +320,24 @@ process_arguments (int argc, char **argv) | |||
281 | } | 320 | } |
282 | server_name = strscpy (server_name, optarg); | 321 | server_name = strscpy (server_name, optarg); |
283 | break; | 322 | break; |
323 | case 'S': /* sourceip */ | ||
324 | if (is_host (optarg) == FALSE) { | ||
325 | usage2 (_("Invalid hostname/address"), optarg); | ||
326 | } | ||
327 | sourceip = strscpy (sourceip, optarg); | ||
328 | break; | ||
329 | case 'I': /* sourceip */ | ||
330 | sourceif = strscpy (sourceif, optarg); | ||
331 | case '4': /* IPv4 only */ | ||
332 | address_family = AF_INET; | ||
333 | break; | ||
334 | case '6': /* IPv6 only */ | ||
335 | #ifdef USE_IPV6 | ||
336 | address_family = AF_INET6; | ||
337 | #else | ||
338 | usage (_("IPv6 support not available\n")); | ||
339 | #endif | ||
340 | break; | ||
284 | case 'c': | 341 | case 'c': |
285 | get_threshold (optarg, rv); | 342 | get_threshold (optarg, rv); |
286 | if (rv[RTA]) { | 343 | if (rv[RTA]) { |
@@ -402,6 +459,8 @@ print_help (void) | |||
402 | printf (UT_HELP_VRSN); | 459 | printf (UT_HELP_VRSN); |
403 | printf (UT_EXTRA_OPTS); | 460 | printf (UT_EXTRA_OPTS); |
404 | 461 | ||
462 | printf (UT_IPv46); | ||
463 | |||
405 | printf (" %s\n", "-H, --hostname=HOST"); | 464 | printf (" %s\n", "-H, --hostname=HOST"); |
406 | printf (" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)")); | 465 | printf (" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)")); |
407 | printf (" %s\n", "-w, --warning=THRESHOLD"); | 466 | printf (" %s\n", "-w, --warning=THRESHOLD"); |
@@ -413,15 +472,22 @@ print_help (void) | |||
413 | printf (" %s\n", "-n, --number=INTEGER"); | 472 | printf (" %s\n", "-n, --number=INTEGER"); |
414 | printf (" %s (default: %d)\n", _("number of ICMP packets to send"),PACKET_COUNT); | 473 | printf (" %s (default: %d)\n", _("number of ICMP packets to send"),PACKET_COUNT); |
415 | printf (" %s\n", "-T, --target-timeout=INTEGER"); | 474 | printf (" %s\n", "-T, --target-timeout=INTEGER"); |
416 | printf (" %s (default: fping's default for -t)\n", _("Target timeout (ms)"),PACKET_COUNT); | 475 | printf (" %s (default: fping's default for -t)\n", _("Target timeout (ms)")); |
417 | printf (" %s\n", "-i, --interval=INTEGER"); | 476 | printf (" %s\n", "-i, --interval=INTEGER"); |
418 | printf (" %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets"),PACKET_COUNT); | 477 | printf (" %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets")); |
478 | printf (" %s\n", "-S, --sourceip=HOST"); | ||
479 | printf (" %s\n", _("name or IP Address of sourceip")); | ||
480 | printf (" %s\n", "-I, --sourceif=IF"); | ||
481 | printf (" %s\n", _("source interface name")); | ||
419 | printf (UT_VERBOSE); | 482 | printf (UT_VERBOSE); |
420 | printf ("\n"); | 483 | printf ("\n"); |
421 | printf (" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); | 484 | printf (" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); |
422 | printf (" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of")); | 485 | printf (" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of")); |
423 | printf (" %s\n", _("packet loss to trigger an alarm state.")); | 486 | printf (" %s\n", _("packet loss to trigger an alarm state.")); |
424 | 487 | ||
488 | printf ("\n"); | ||
489 | printf (" %s\n", _("IPv4 is used by default. Specify -6 to use IPv6.")); | ||
490 | |||
425 | printf (UT_SUPPORT); | 491 | printf (UT_SUPPORT); |
426 | } | 492 | } |
427 | 493 | ||