diff options
Diffstat (limited to 'plugins-root')
| -rw-r--r-- | plugins-root/check_icmp.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 35cae3ed..58d8a545 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> |
| @@ -1782,6 +1782,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. */ | 1782 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ |
| 1783 | static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { | 1783 | static 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 | 1784 | // TODO: Rewrite this so the function return an error and we exit somewhere else |
| 1785 | |||
| 1785 | struct sockaddr_in ip_address; | 1786 | struct sockaddr_in ip_address; |
| 1786 | 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 |
| 1787 | #if defined(SIOCGIFADDR) | 1788 | #if defined(SIOCGIFADDR) |
| @@ -1797,6 +1798,9 @@ static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { | |||
| 1797 | 1798 | ||
| 1798 | memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); | 1799 | memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); |
| 1799 | #else | 1800 | #else |
| 1801 | // fake operation to make the compiler happy | ||
| 1802 | (void)icmp_sock; | ||
| 1803 | |||
| 1800 | (void)ifname; | 1804 | (void)ifname; |
| 1801 | errno = 0; | 1805 | errno = 0; |
| 1802 | crash("Cannot get interface IP address on this platform."); | 1806 | crash("Cannot get interface IP address on this platform."); |
| @@ -2046,7 +2050,7 @@ unsigned short icmp_checksum(uint16_t *packet, size_t packet_size) { | |||
| 2046 | 2050 | ||
| 2047 | /* mop up the occasional odd byte */ | 2051 | /* mop up the occasional odd byte */ |
| 2048 | if (packet_size == 1) { | 2052 | if (packet_size == 1) { |
| 2049 | sum += *((uint8_t *)packet - 1); | 2053 | sum += *((uint8_t *)packet); |
| 2050 | } | 2054 | } |
| 2051 | 2055 | ||
| 2052 | sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ | 2056 | sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ |
| @@ -2245,7 +2249,7 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes, | |||
| 2245 | * round trip jitter, but double the impact to latency | 2249 | * round trip jitter, but double the impact to latency |
| 2246 | * then add 10 for protocol latencies (in milliseconds). | 2250 | * then add 10 for protocol latencies (in milliseconds). |
| 2247 | */ | 2251 | */ |
| 2248 | EffectiveLatency = ((double)rta / 1000) + target.jitter * 2 + 10; | 2252 | EffectiveLatency = ((double)rta / 1000) + (target.jitter * 2) + 10; |
| 2249 | 2253 | ||
| 2250 | double R; | 2254 | double R; |
| 2251 | if (EffectiveLatency < 160) { | 2255 | if (EffectiveLatency < 160) { |
| @@ -2404,25 +2408,32 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes, | |||
| 2404 | if (modes.score_mode) { | 2408 | if (modes.score_mode) { |
| 2405 | mp_subcheck sc_score = mp_subcheck_init(); | 2409 | mp_subcheck sc_score = mp_subcheck_init(); |
| 2406 | sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK); | 2410 | 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 | 2411 | ||
| 2417 | if (packet_loss < 100) { | 2412 | if (target.icmp_recv > 1) { |
| 2418 | mp_perfdata pd_score = perfdata_init(); | 2413 | xasprintf(&sc_score.output, "Score %f", score); |
| 2419 | xasprintf(&pd_score.label, "%sscore", address); | 2414 | |
| 2420 | pd_score.value = mp_create_pd_value(score); | 2415 | if (score <= crit.score) { |
| 2421 | 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); |
| 2422 | 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); |
| 2423 | pd_score.min = mp_create_pd_value(0); | 2418 | } else if (score <= warn.score) { |
| 2424 | pd_score.max = mp_create_pd_value(100); | 2419 | sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING); |
| 2425 | 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"); | ||
| 2426 | } | 2437 | } |
| 2427 | 2438 | ||
| 2428 | mp_add_subcheck_to_subcheck(&result, sc_score); | 2439 | mp_add_subcheck_to_subcheck(&result, sc_score); |
