summaryrefslogtreecommitdiffstats
path: root/plugins-root
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/check_icmp.c77
1 files changed, 45 insertions, 32 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 35cae3ed..e536e31c 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -55,7 +55,7 @@ const char *email = "devel@monitoring-plugins.org";
55 55
56#include <sys/time.h> 56#include <sys/time.h>
57#if defined(SIOCGIFADDR) 57#if defined(SIOCGIFADDR)
58#include <sys/ioctl.h> 58# include <sys/ioctl.h>
59#endif /* SIOCGIFADDR */ 59#endif /* SIOCGIFADDR */
60#include <errno.h> 60#include <errno.h>
61#include <signal.h> 61#include <signal.h>
@@ -277,15 +277,6 @@ typedef struct {
277 check_icmp_config config; 277 check_icmp_config config;
278} check_icmp_config_wrapper; 278} check_icmp_config_wrapper;
279check_icmp_config_wrapper process_arguments(int argc, char **argv) { 279check_icmp_config_wrapper process_arguments(int argc, char **argv) {
280 /* get calling name the old-fashioned way for portability instead
281 * of relying on the glibc-ism __progname */
282 char *ptr = strrchr(argv[0], '/');
283 if (ptr) {
284 progname = &ptr[1];
285 } else {
286 progname = argv[0];
287 }
288
289 check_icmp_config_wrapper result = { 280 check_icmp_config_wrapper result = {
290 .errorcode = OK, 281 .errorcode = OK,
291 .config = check_icmp_config_init(), 282 .config = check_icmp_config_init(),
@@ -828,6 +819,14 @@ int main(int argc, char **argv) {
828 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */ 819 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */
829 environ = NULL; 820 environ = NULL;
830 821
822 /* determine program- and service-name quickly */
823 progname = strrchr(argv[0], '/');
824 if (progname != NULL) {
825 progname++;
826 } else {
827 progname = argv[0];
828 }
829
831 /* Parse extra opts if any */ 830 /* Parse extra opts if any */
832 argv = np_extra_opts(&argc, argv, progname); 831 argv = np_extra_opts(&argc, argv, progname);
833 832
@@ -1470,10 +1469,13 @@ static recvfrom_wto_wrapper recvfrom_wto(const check_icmp_socket_set sockset, vo
1470 }; 1469 };
1471 1470
1472 ssize_t ret; 1471 ssize_t ret;
1473 if (FD_ISSET(sockset.socket4, &read_fds)) { 1472
1473 // Test explicitly whether sockets are in use
1474 // this is necessary at least on OpenBSD where FD_ISSET will segfault otherwise
1475 if ((sockset.socket4 != -1) && FD_ISSET(sockset.socket4, &read_fds)) {
1474 ret = recvmsg(sockset.socket4, &hdr, 0); 1476 ret = recvmsg(sockset.socket4, &hdr, 0);
1475 result.recv_proto = AF_INET; 1477 result.recv_proto = AF_INET;
1476 } else if (FD_ISSET(sockset.socket6, &read_fds)) { 1478 } else if ((sockset.socket6 != -1) && FD_ISSET(sockset.socket6, &read_fds)) {
1477 ret = recvmsg(sockset.socket6, &hdr, 0); 1479 ret = recvmsg(sockset.socket6, &hdr, 0);
1478 result.recv_proto = AF_INET6; 1480 result.recv_proto = AF_INET6;
1479 } else { 1481 } else {
@@ -1782,6 +1784,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil
1782/* TODO: Move this to netutils.c and also change check_dhcp to use that. */ 1784/* TODO: Move this to netutils.c and also change check_dhcp to use that. */
1783static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { 1785static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) {
1784 // TODO: Rewrite this so the function return an error and we exit somewhere else 1786 // TODO: Rewrite this so the function return an error and we exit somewhere else
1787
1785 struct sockaddr_in ip_address; 1788 struct sockaddr_in ip_address;
1786 ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy 1789 ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy
1787#if defined(SIOCGIFADDR) 1790#if defined(SIOCGIFADDR)
@@ -1797,6 +1800,9 @@ static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) {
1797 1800
1798 memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); 1801 memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address));
1799#else 1802#else
1803 // fake operation to make the compiler happy
1804 (void)icmp_sock;
1805
1800 (void)ifname; 1806 (void)ifname;
1801 errno = 0; 1807 errno = 0;
1802 crash("Cannot get interface IP address on this platform."); 1808 crash("Cannot get interface IP address on this platform.");
@@ -2046,7 +2052,7 @@ unsigned short icmp_checksum(uint16_t *packet, size_t packet_size) {
2046 2052
2047 /* mop up the occasional odd byte */ 2053 /* mop up the occasional odd byte */
2048 if (packet_size == 1) { 2054 if (packet_size == 1) {
2049 sum += *((uint8_t *)packet - 1); 2055 sum += *((uint8_t *)packet);
2050 } 2056 }
2051 2057
2052 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ 2058 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
@@ -2245,7 +2251,7 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes,
2245 * round trip jitter, but double the impact to latency 2251 * round trip jitter, but double the impact to latency
2246 * then add 10 for protocol latencies (in milliseconds). 2252 * then add 10 for protocol latencies (in milliseconds).
2247 */ 2253 */
2248 EffectiveLatency = ((double)rta / 1000) + target.jitter * 2 + 10; 2254 EffectiveLatency = ((double)rta / 1000) + (target.jitter * 2) + 10;
2249 2255
2250 double R; 2256 double R;
2251 if (EffectiveLatency < 160) { 2257 if (EffectiveLatency < 160) {
@@ -2404,25 +2410,32 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes,
2404 if (modes.score_mode) { 2410 if (modes.score_mode) {
2405 mp_subcheck sc_score = mp_subcheck_init(); 2411 mp_subcheck sc_score = mp_subcheck_init();
2406 sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK); 2412 sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK);
2407 xasprintf(&sc_score.output, "Score %f", score);
2408
2409 if (score <= crit.score) {
2410 sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL);
2411 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score);
2412 } else if (score <= warn.score) {
2413 sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING);
2414 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score);
2415 }
2416 2413
2417 if (packet_loss < 100) { 2414 if (target.icmp_recv > 1) {
2418 mp_perfdata pd_score = perfdata_init(); 2415 xasprintf(&sc_score.output, "Score %f", score);
2419 xasprintf(&pd_score.label, "%sscore", address); 2416
2420 pd_score.value = mp_create_pd_value(score); 2417 if (score <= crit.score) {
2421 pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score)); 2418 sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL);
2422 pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score)); 2419 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score);
2423 pd_score.min = mp_create_pd_value(0); 2420 } else if (score <= warn.score) {
2424 pd_score.max = mp_create_pd_value(100); 2421 sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING);
2425 mp_add_perfdata_to_subcheck(&sc_score, pd_score); 2422 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score);
2423 }
2424
2425 if (packet_loss < 100) {
2426 mp_perfdata pd_score = perfdata_init();
2427 xasprintf(&pd_score.label, "%sscore", address);
2428 pd_score.value = mp_create_pd_value(score);
2429 pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score));
2430 pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score));
2431 pd_score.min = mp_create_pd_value(0);
2432 pd_score.max = mp_create_pd_value(100);
2433 mp_add_perfdata_to_subcheck(&sc_score, pd_score);
2434 }
2435
2436 } else {
2437 // score mode disabled due to not enough received packages
2438 xasprintf(&sc_score.output, "Score mode disabled, not enough packets received");
2426 } 2439 }
2427 2440
2428 mp_add_subcheck_to_subcheck(&result, sc_score); 2441 mp_add_subcheck_to_subcheck(&result, sc_score);