diff options
author | Oliver Skibbe <oliskibbe@gmail.com> | 2015-09-28 14:22:09 +0200 |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2021-11-18 18:51:27 +0100 |
commit | a2eb4e8210deb37133ece1e6e94aad4e6c5bea14 (patch) | |
tree | dc81e6a69db1a8d45ca2c9f0ba566f9ae9a60c84 | |
parent | d6d2254312aede137dcd998a4cdfa26ecd07e379 (diff) | |
download | monitoring-plugins-a2eb4e8210deb37133ece1e6e94aad4e6c5bea14.tar.gz |
* check_ping: added option for packet size
- added option (-s/--packetsize) for setting packet size
(limited to 65528 Bytes, according to RFC791)
- added DEFAULT_PACKET_SIZE constant with 56 Bytes)
- disabled ping check for UnixWare in autoconf: if condition and
with_ping_command had different syntax
-rw-r--r-- | configure.ac | 37 | ||||
-rw-r--r-- | plugins/check_ping.c | 36 |
2 files changed, 63 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac index dfc37b5e..5e2a0b38 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1079,6 +1079,7 @@ AC_ARG_WITH(ping_command, | |||
1079 | AC_MSG_CHECKING(for ICMP ping syntax) | 1079 | AC_MSG_CHECKING(for ICMP ping syntax) |
1080 | ac_cv_ping_packets_first=no | 1080 | ac_cv_ping_packets_first=no |
1081 | ac_cv_ping_has_timeout=no | 1081 | ac_cv_ping_has_timeout=no |
1082 | ac_cv_ping_has_packetsize=no | ||
1082 | if test -n "$with_ping_command" | 1083 | if test -n "$with_ping_command" |
1083 | then | 1084 | then |
1084 | AC_MSG_RESULT([(command-line) $with_ping_command]) | 1085 | AC_MSG_RESULT([(command-line) $with_ping_command]) |
@@ -1102,12 +1103,22 @@ then | |||
1102 | ac_cv_ping_has_timeout=yes | 1103 | ac_cv_ping_has_timeout=yes |
1103 | AC_MSG_RESULT([$with_ping_command]) | 1104 | AC_MSG_RESULT([$with_ping_command]) |
1104 | 1105 | ||
1105 | elif [[ "z$ac_cv_uname_s" = "zUnixWare" ]] && \ | 1106 | # XXX with_ping_command not same like if condition |
1106 | $PATH_TO_PING -n -s 127.0.0.1 56 1 2>/dev/null | \ | 1107 | #elif [[ "z$ac_cv_uname_s" = "zUnixWare" ]] && \ |
1108 | # $PATH_TO_PING -n -s 127.0.0.1 56 1 2>/dev/null | \ | ||
1109 | # egrep -i "^round-trip|^rtt" >/dev/null | ||
1110 | #then | ||
1111 | # with_ping_command="$PATH_TO_PING -n -U -c %d %s" | ||
1112 | # ac_cv_ping_packets_first=yes | ||
1113 | # AC_MSG_RESULT([$with_ping_command]) | ||
1114 | |||
1115 | elif $PATH_TO_PING -n -U -w 10 -c 1 -s 56 127.0.0.1 2>/dev/null | \ | ||
1107 | egrep -i "^round-trip|^rtt" >/dev/null | 1116 | egrep -i "^round-trip|^rtt" >/dev/null |
1108 | then | 1117 | then |
1109 | with_ping_command="$PATH_TO_PING -n -U -c %d %s" | 1118 | with_ping_command="$PATH_TO_PING -n -U -w %d -c %d -s %d %s" |
1110 | ac_cv_ping_packets_first=yes | 1119 | ac_cv_ping_packets_first=yes |
1120 | ac_cv_ping_has_timeout=yes | ||
1121 | ac_cv_ping_has_packetsize=yes | ||
1111 | AC_MSG_RESULT([$with_ping_command]) | 1122 | AC_MSG_RESULT([$with_ping_command]) |
1112 | 1123 | ||
1113 | elif $PATH_TO_PING -4 -n -U -w 10 -c 1 127.0.0.1 2>/dev/null | \ | 1124 | elif $PATH_TO_PING -4 -n -U -w 10 -c 1 127.0.0.1 2>/dev/null | \ |
@@ -1126,6 +1137,14 @@ then | |||
1126 | ac_cv_ping_has_timeout=yes | 1137 | ac_cv_ping_has_timeout=yes |
1127 | AC_MSG_RESULT([$with_ping_command]) | 1138 | AC_MSG_RESULT([$with_ping_command]) |
1128 | 1139 | ||
1140 | elif $PATH_TO_PING -n -U -c 1 -s 56 127.0.0.1 2>/dev/null | \ | ||
1141 | egrep -i "^round-trip|^rtt" >/dev/null | ||
1142 | then | ||
1143 | with_ping_command="$PATH_TO_PING -n -U -c %d -s %d %s" | ||
1144 | ac_cv_ping_packets_first=yes | ||
1145 | ac_cv_ping_has_packetsize=yes | ||
1146 | AC_MSG_RESULT([$with_ping_command]) | ||
1147 | |||
1129 | elif $PATH_TO_PING -n -U -c 1 127.0.0.1 2>/dev/null | \ | 1148 | elif $PATH_TO_PING -n -U -c 1 127.0.0.1 2>/dev/null | \ |
1130 | egrep -i "^round-trip|^rtt" >/dev/null | 1149 | egrep -i "^round-trip|^rtt" >/dev/null |
1131 | then | 1150 | then |
@@ -1155,13 +1174,15 @@ then | |||
1155 | elif $PATH_TO_PING -n -s 127.0.0.1 56 1 2>/dev/null | \ | 1174 | elif $PATH_TO_PING -n -s 127.0.0.1 56 1 2>/dev/null | \ |
1156 | egrep -i "^round-trip|^rtt" >/dev/null | 1175 | egrep -i "^round-trip|^rtt" >/dev/null |
1157 | then | 1176 | then |
1158 | with_ping_command="$PATH_TO_PING -n -s %s 56 %d" | 1177 | with_ping_command="$PATH_TO_PING -n -s %s %d %d" |
1178 | ac_cv_ping_has_packetsize=yes | ||
1159 | AC_MSG_RESULT([$with_ping_command]) | 1179 | AC_MSG_RESULT([$with_ping_command]) |
1160 | 1180 | ||
1161 | elif $PATH_TO_PING -n -h 127.0.0.1 -s 56 -c 1 2>/dev/null | \ | 1181 | elif $PATH_TO_PING -n -h 127.0.0.1 -s 56 -c 1 2>/dev/null | \ |
1162 | egrep -i "^round-trip|^rtt" >/dev/null | 1182 | egrep -i "^round-trip|^rtt" >/dev/null |
1163 | then | 1183 | then |
1164 | with_ping_command="$PATH_TO_PING -n -h %s -s 56 -c %d" | 1184 | with_ping_command="$PATH_TO_PING -n -h %s -s %d -c %d" |
1185 | ac_cv_ping_has_packetsize=yes | ||
1165 | AC_MSG_RESULT([$with_ping_command]) | 1186 | AC_MSG_RESULT([$with_ping_command]) |
1166 | 1187 | ||
1167 | elif $PATH_TO_PING -n -s 56 -c 1 127.0.0.1 2>/dev/null | \ | 1188 | elif $PATH_TO_PING -n -s 56 -c 1 127.0.0.1 2>/dev/null | \ |
@@ -1197,6 +1218,12 @@ then | |||
1197 | [Define if ping has its own timeout option that should be set]) | 1218 | [Define if ping has its own timeout option that should be set]) |
1198 | fi | 1219 | fi |
1199 | 1220 | ||
1221 | if test "x$ac_cv_ping_has_packetsize" != "xno" | ||
1222 | then | ||
1223 | AC_DEFINE(PING_HAS_PACKETSIZE,1, | ||
1224 | [Define if ping has an option for custom packet size]) | ||
1225 | fi | ||
1226 | |||
1200 | AC_ARG_WITH(ping6_command, | 1227 | AC_ARG_WITH(ping6_command, |
1201 | ACX_HELP_STRING([--with-ping6-command=SYNTAX], | 1228 | ACX_HELP_STRING([--with-ping6-command=SYNTAX], |
1202 | [sets syntax for ICMPv6 ping]), | 1229 | [sets syntax for ICMPv6 ping]), |
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index ba7af373..de173f9f 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -44,7 +44,8 @@ const char *email = "devel@monitoring-plugins.org"; | |||
44 | 44 | ||
45 | enum { | 45 | enum { |
46 | UNKNOWN_PACKET_LOSS = 200, /* 200% */ | 46 | UNKNOWN_PACKET_LOSS = 200, /* 200% */ |
47 | DEFAULT_MAX_PACKETS = 5 /* default no. of ICMP ECHO packets */ | 47 | DEFAULT_MAX_PACKETS = 5, /* default no. of ICMP ECHO packets */ |
48 | DEFAULT_PACKET_SIZE = 56 /* default size of ICMP ECHO packets */ | ||
48 | }; | 49 | }; |
49 | 50 | ||
50 | int process_arguments (int, char **); | 51 | int process_arguments (int, char **); |
@@ -64,6 +65,7 @@ char **addresses = NULL; | |||
64 | int n_addresses = 0; | 65 | int n_addresses = 0; |
65 | int max_addr = 1; | 66 | int max_addr = 1; |
66 | int max_packets = -1; | 67 | int max_packets = -1; |
68 | int packet_size = DEFAULT_PACKET_SIZE; | ||
67 | int verbose = 0; | 69 | int verbose = 0; |
68 | 70 | ||
69 | float rta = UNKNOWN_TRIP_TIME; | 71 | float rta = UNKNOWN_TRIP_TIME; |
@@ -122,13 +124,21 @@ main (int argc, char **argv) | |||
122 | 124 | ||
123 | /* does the host address of number of packets argument come first? */ | 125 | /* does the host address of number of packets argument come first? */ |
124 | #ifdef PING_PACKETS_FIRST | 126 | #ifdef PING_PACKETS_FIRST |
125 | # ifdef PING_HAS_TIMEOUT | 127 | # if defined(PING_HAS_TIMEOUT) && defined(PING_HAS_PACKETSIZE) |
128 | xasprintf (&cmd, rawcmd, timeout_interval, max_packets, packet_size, addresses[i]); | ||
129 | # elif defined(PING_HAS_TIMEOUT) | ||
126 | xasprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]); | 130 | xasprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]); |
131 | # elif defined(PING_HAS_PACKETSIZE) | ||
132 | xasprintf (&cmd, rawcmd, max_packets, packet_size, addresses[i]); | ||
127 | # else | 133 | # else |
128 | xasprintf (&cmd, rawcmd, max_packets, addresses[i]); | 134 | xasprintf (&cmd, rawcmd, max_packets, addresses[i]); |
129 | # endif | 135 | # endif |
130 | #else | 136 | #else |
131 | xasprintf (&cmd, rawcmd, addresses[i], max_packets); | 137 | # ifdef PING_HAS_PACKETSIZE |
138 | xasprintf (&cmd, rawcmd, addresses[i], packet_size, max_packets); | ||
139 | # else | ||
140 | xasprintf (&cmd, rawcmd, addresses[i], max_packets); | ||
141 | # endif | ||
132 | #endif | 142 | #endif |
133 | 143 | ||
134 | if (verbose >= 2) | 144 | if (verbose >= 2) |
@@ -202,6 +212,7 @@ process_arguments (int argc, char **argv) | |||
202 | static struct option longopts[] = { | 212 | static struct option longopts[] = { |
203 | STD_LONG_OPTS, | 213 | STD_LONG_OPTS, |
204 | {"packets", required_argument, 0, 'p'}, | 214 | {"packets", required_argument, 0, 'p'}, |
215 | {"packetsize",required_argument, 0, 's'}, | ||
205 | {"nohtml", no_argument, 0, 'n'}, | 216 | {"nohtml", no_argument, 0, 'n'}, |
206 | {"link", no_argument, 0, 'L'}, | 217 | {"link", no_argument, 0, 'L'}, |
207 | {"use-ipv4", no_argument, 0, '4'}, | 218 | {"use-ipv4", no_argument, 0, '4'}, |
@@ -220,7 +231,7 @@ process_arguments (int argc, char **argv) | |||
220 | } | 231 | } |
221 | 232 | ||
222 | while (1) { | 233 | while (1) { |
223 | c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option); | 234 | c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:s:", longopts, &option); |
224 | 235 | ||
225 | if (c == -1 || c == EOF) | 236 | if (c == -1 || c == EOF) |
226 | break; | 237 | break; |
@@ -277,6 +288,12 @@ process_arguments (int argc, char **argv) | |||
277 | else | 288 | else |
278 | usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg); | 289 | usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg); |
279 | break; | 290 | break; |
291 | case 's': /* number of packets to send */ | ||
292 | if (is_intnonneg (optarg)) | ||
293 | packet_size = atoi (optarg); | ||
294 | else | ||
295 | usage2 (_("<packet_size> (%s) must be a non-negative number\n"), optarg); | ||
296 | break; | ||
280 | case 'n': /* no HTML */ | 297 | case 'n': /* no HTML */ |
281 | display_html = FALSE; | 298 | display_html = FALSE; |
282 | break; | 299 | break; |
@@ -307,6 +324,7 @@ process_arguments (int argc, char **argv) | |||
307 | } | 324 | } |
308 | } | 325 | } |
309 | 326 | ||
327 | /* XXX shouldnt this be in function validate_arguments ? */ | ||
310 | if (wpl == UNKNOWN_PACKET_LOSS) { | 328 | if (wpl == UNKNOWN_PACKET_LOSS) { |
311 | if (is_intpercent (argv[c]) == FALSE) { | 329 | if (is_intpercent (argv[c]) == FALSE) { |
312 | printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]); | 330 | printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]); |
@@ -359,6 +377,7 @@ process_arguments (int argc, char **argv) | |||
359 | return ERROR; | 377 | return ERROR; |
360 | } | 378 | } |
361 | } | 379 | } |
380 | /* XXX END shouldnt this be in function validate_arguments ? */ | ||
362 | 381 | ||
363 | return validate_arguments (); | 382 | return validate_arguments (); |
364 | } | 383 | } |
@@ -387,6 +406,10 @@ validate_arguments () | |||
387 | float max_seconds; | 406 | float max_seconds; |
388 | int i; | 407 | int i; |
389 | 408 | ||
409 | if (packet_size > 65528) { | ||
410 | printf (_("max packet size cannot be larger than 65528 Bytes")); | ||
411 | return ERROR; | ||
412 | } | ||
390 | if (wrta < 0.0) { | 413 | if (wrta < 0.0) { |
391 | printf (_("<wrta> was not set\n")); | 414 | printf (_("<wrta> was not set\n")); |
392 | return ERROR; | 415 | return ERROR; |
@@ -591,6 +614,9 @@ print_help (void) | |||
591 | printf (" %s\n", "-p, --packets=INTEGER"); | 614 | printf (" %s\n", "-p, --packets=INTEGER"); |
592 | printf (" %s ", _("number of ICMP ECHO packets to send")); | 615 | printf (" %s ", _("number of ICMP ECHO packets to send")); |
593 | printf (_("(Default: %d)\n"), DEFAULT_MAX_PACKETS); | 616 | printf (_("(Default: %d)\n"), DEFAULT_MAX_PACKETS); |
617 | printf (" %s\n", "-s, --packetsize=INTEGER"); | ||
618 | printf (" %s ", _("size of ICMP ECHO packet to send")); | ||
619 | printf (_("(Default: %d)\n"), DEFAULT_PACKET_SIZE); | ||
594 | printf (" %s\n", "-L, --link"); | 620 | printf (" %s\n", "-L, --link"); |
595 | printf (" %s\n", _("show HTML in the plugin output (obsoleted by urlize)")); | 621 | printf (" %s\n", _("show HTML in the plugin output (obsoleted by urlize)")); |
596 | 622 | ||
@@ -615,5 +641,5 @@ print_usage (void) | |||
615 | { | 641 | { |
616 | printf ("%s\n", _("Usage:")); | 642 | printf ("%s\n", _("Usage:")); |
617 | printf ("%s -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n", progname); | 643 | printf ("%s -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n", progname); |
618 | printf (" [-p packets] [-t timeout] [-4|-6]\n"); | 644 | printf (" [-p packets] [-s packetsize] [-t timeout] [-4|-6]\n"); |
619 | } | 645 | } |