diff options
Diffstat (limited to 'plugins-root')
| -rw-r--r-- | plugins-root/check_icmp.c | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index d46d2ccc..58d8a545 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
| @@ -54,6 +54,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 54 | #endif | 54 | #endif |
| 55 | 55 | ||
| 56 | #include <sys/time.h> | 56 | #include <sys/time.h> |
| 57 | #if defined(SIOCGIFADDR) | ||
| 58 | # include <sys/ioctl.h> | ||
| 59 | #endif /* SIOCGIFADDR */ | ||
| 57 | #include <errno.h> | 60 | #include <errno.h> |
| 58 | #include <signal.h> | 61 | #include <signal.h> |
| 59 | #include <ctype.h> | 62 | #include <ctype.h> |
| @@ -146,7 +149,7 @@ static get_timevar_wrapper get_timevar(const char *str); | |||
| 146 | static time_t get_timevaldiff(struct timeval earlier, struct timeval later); | 149 | static time_t get_timevaldiff(struct timeval earlier, struct timeval later); |
| 147 | static time_t get_timevaldiff_to_now(struct timeval earlier); | 150 | static time_t get_timevaldiff_to_now(struct timeval earlier); |
| 148 | 151 | ||
| 149 | static in_addr_t get_ip_address(const char *ifname); | 152 | static in_addr_t get_ip_address(const char *ifname, const int icmp_sock); |
| 150 | static void set_source_ip(char *arg, int icmp_sock, sa_family_t addr_family); | 153 | static void set_source_ip(char *arg, int icmp_sock, sa_family_t addr_family); |
| 151 | 154 | ||
| 152 | /* Receiving data */ | 155 | /* Receiving data */ |
| @@ -1769,7 +1772,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil | |||
| 1769 | memset(&src, 0, sizeof(src)); | 1772 | memset(&src, 0, sizeof(src)); |
| 1770 | src.sin_family = addr_family; | 1773 | src.sin_family = addr_family; |
| 1771 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) { | 1774 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) { |
| 1772 | src.sin_addr.s_addr = get_ip_address(arg); | 1775 | src.sin_addr.s_addr = get_ip_address(arg, icmp_sock); |
| 1773 | } | 1776 | } |
| 1774 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) { | 1777 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) { |
| 1775 | crash("Cannot bind to IP address %s", arg); | 1778 | crash("Cannot bind to IP address %s", arg); |
| @@ -1777,8 +1780,9 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil | |||
| 1777 | } | 1780 | } |
| 1778 | 1781 | ||
| 1779 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ | 1782 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ |
| 1780 | static in_addr_t get_ip_address(const char *ifname) { | 1783 | static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { |
| 1781 | // TODO: Rewrite this so the function return an error and we exit somewhere else | 1784 | // TODO: Rewrite this so the function return an error and we exit somewhere else |
| 1785 | |||
| 1782 | struct sockaddr_in ip_address; | 1786 | struct sockaddr_in ip_address; |
| 1783 | ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy | 1787 | ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy |
| 1784 | #if defined(SIOCGIFADDR) | 1788 | #if defined(SIOCGIFADDR) |
| @@ -1792,8 +1796,11 @@ static in_addr_t get_ip_address(const char *ifname) { | |||
| 1792 | crash("Cannot determine IP address of interface %s", ifname); | 1796 | crash("Cannot determine IP address of interface %s", ifname); |
| 1793 | } | 1797 | } |
| 1794 | 1798 | ||
| 1795 | memcpy(&ip, &ifr.ifr_addr, sizeof(ip)); | 1799 | memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); |
| 1796 | #else | 1800 | #else |
| 1801 | // fake operation to make the compiler happy | ||
| 1802 | (void)icmp_sock; | ||
| 1803 | |||
| 1797 | (void)ifname; | 1804 | (void)ifname; |
| 1798 | errno = 0; | 1805 | errno = 0; |
| 1799 | crash("Cannot get interface IP address on this platform."); | 1806 | crash("Cannot get interface IP address on this platform."); |
| @@ -2043,7 +2050,7 @@ unsigned short icmp_checksum(uint16_t *packet, size_t packet_size) { | |||
| 2043 | 2050 | ||
| 2044 | /* mop up the occasional odd byte */ | 2051 | /* mop up the occasional odd byte */ |
| 2045 | if (packet_size == 1) { | 2052 | if (packet_size == 1) { |
| 2046 | sum += *((uint8_t *)packet - 1); | 2053 | sum += *((uint8_t *)packet); |
| 2047 | } | 2054 | } |
| 2048 | 2055 | ||
| 2049 | sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ | 2056 | sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ |
| @@ -2242,7 +2249,7 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes, | |||
| 2242 | * round trip jitter, but double the impact to latency | 2249 | * round trip jitter, but double the impact to latency |
| 2243 | * then add 10 for protocol latencies (in milliseconds). | 2250 | * then add 10 for protocol latencies (in milliseconds). |
| 2244 | */ | 2251 | */ |
| 2245 | EffectiveLatency = ((double)rta / 1000) + target.jitter * 2 + 10; | 2252 | EffectiveLatency = ((double)rta / 1000) + (target.jitter * 2) + 10; |
| 2246 | 2253 | ||
| 2247 | double R; | 2254 | double R; |
| 2248 | if (EffectiveLatency < 160) { | 2255 | if (EffectiveLatency < 160) { |
| @@ -2401,25 +2408,32 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes, | |||
| 2401 | if (modes.score_mode) { | 2408 | if (modes.score_mode) { |
| 2402 | mp_subcheck sc_score = mp_subcheck_init(); | 2409 | mp_subcheck sc_score = mp_subcheck_init(); |
| 2403 | sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK); | 2410 | sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK); |
| 2404 | xasprintf(&sc_score.output, "Score %f", score); | ||
| 2405 | |||
| 2406 | if (score <= crit.score) { | ||
| 2407 | sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL); | ||
| 2408 | xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score); | ||
| 2409 | } else if (score <= warn.score) { | ||
| 2410 | sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING); | ||
| 2411 | xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score); | ||
| 2412 | } | ||
| 2413 | 2411 | ||
| 2414 | if (packet_loss < 100) { | 2412 | if (target.icmp_recv > 1) { |
| 2415 | mp_perfdata pd_score = perfdata_init(); | 2413 | xasprintf(&sc_score.output, "Score %f", score); |
| 2416 | xasprintf(&pd_score.label, "%sscore", address); | 2414 | |
| 2417 | pd_score.value = mp_create_pd_value(score); | 2415 | if (score <= crit.score) { |
| 2418 | pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score)); | 2416 | sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL); |
| 2419 | pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score)); | 2417 | xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score); |
| 2420 | pd_score.min = mp_create_pd_value(0); | 2418 | } else if (score <= warn.score) { |
| 2421 | pd_score.max = mp_create_pd_value(100); | 2419 | sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING); |
| 2422 | mp_add_perfdata_to_subcheck(&sc_score, pd_score); | 2420 | xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score); |
| 2421 | } | ||
| 2422 | |||
| 2423 | if (packet_loss < 100) { | ||
| 2424 | mp_perfdata pd_score = perfdata_init(); | ||
| 2425 | xasprintf(&pd_score.label, "%sscore", address); | ||
| 2426 | pd_score.value = mp_create_pd_value(score); | ||
| 2427 | pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score)); | ||
| 2428 | pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score)); | ||
| 2429 | pd_score.min = mp_create_pd_value(0); | ||
| 2430 | pd_score.max = mp_create_pd_value(100); | ||
| 2431 | mp_add_perfdata_to_subcheck(&sc_score, pd_score); | ||
| 2432 | } | ||
| 2433 | |||
| 2434 | } else { | ||
| 2435 | // score mode disabled due to not enough received packages | ||
| 2436 | xasprintf(&sc_score.output, "Score mode disabled, not enough packets received"); | ||
| 2423 | } | 2437 | } |
| 2424 | 2438 | ||
| 2425 | mp_add_subcheck_to_subcheck(&result, sc_score); | 2439 | mp_add_subcheck_to_subcheck(&result, sc_score); |
