diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-05-05 22:52:56 +0200 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-05-05 22:52:56 +0200 |
| commit | 5fd8191a50df6be712c9143ca6d73de7878f57d1 (patch) | |
| tree | 67afdf36446aafa30f7b6daf56895dd233f01b4b /plugins-root/check_icmp.d | |
| parent | 5a6adcb7db497fba7b89471a6d58dba80330ff4a (diff) | |
| download | monitoring-plugins-5fd8191a50df6be712c9143ca6d73de7878f57d1.tar.gz | |
WIP - check_icmp refactor 3
Diffstat (limited to 'plugins-root/check_icmp.d')
| -rw-r--r-- | plugins-root/check_icmp.d/check_icmp_helpers.c | 25 | ||||
| -rw-r--r-- | plugins-root/check_icmp.d/config.h | 58 |
2 files changed, 43 insertions, 40 deletions
diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.c b/plugins-root/check_icmp.d/check_icmp_helpers.c index 2efe6e59..2a521b04 100644 --- a/plugins-root/check_icmp.d/check_icmp_helpers.c +++ b/plugins-root/check_icmp.d/check_icmp_helpers.c | |||
| @@ -10,8 +10,6 @@ unsigned int timeout = DEFAULT_TIMEOUT; | |||
| 10 | 10 | ||
| 11 | check_icmp_config check_icmp_config_init() { | 11 | check_icmp_config check_icmp_config_init() { |
| 12 | check_icmp_config tmp = { | 12 | check_icmp_config tmp = { |
| 13 | .source_ip = NULL, | ||
| 14 | |||
| 15 | .order_mode = false, | 13 | .order_mode = false, |
| 16 | .mos_mode = false, | 14 | .mos_mode = false, |
| 17 | .rta_mode = false, | 15 | .rta_mode = false, |
| @@ -20,10 +18,6 @@ check_icmp_config check_icmp_config_init() { | |||
| 20 | .score_mode = false, | 18 | .score_mode = false, |
| 21 | 19 | ||
| 22 | .min_hosts_alive = -1, | 20 | .min_hosts_alive = -1, |
| 23 | .icmp_data_size = DEFAULT_PING_DATA_SIZE, | ||
| 24 | .icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN, | ||
| 25 | .pkt_interval = DEFAULT_PKT_INTERVAL, | ||
| 26 | .target_interval = 0, | ||
| 27 | .crit = {.pl = DEFAULT_CRIT_PL, | 21 | .crit = {.pl = DEFAULT_CRIT_PL, |
| 28 | .rta = DEFAULT_CRIT_RTA, | 22 | .rta = DEFAULT_CRIT_RTA, |
| 29 | .jitter = 50.0, | 23 | .jitter = 50.0, |
| @@ -34,11 +28,18 @@ check_icmp_config check_icmp_config_init() { | |||
| 34 | .jitter = 40.0, | 28 | .jitter = 40.0, |
| 35 | .mos = 3.5, | 29 | .mos = 3.5, |
| 36 | .score = 80.0}, | 30 | .score = 80.0}, |
| 37 | .pid = {}, | 31 | |
| 38 | .mode = MODE_RTA, | ||
| 39 | .ttl = DEFAULT_TTL, | 32 | .ttl = DEFAULT_TTL, |
| 33 | .icmp_data_size = DEFAULT_PING_DATA_SIZE, | ||
| 34 | .icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN, | ||
| 35 | .pkt_interval = DEFAULT_PKT_INTERVAL, | ||
| 36 | .target_interval = 0, | ||
| 37 | .number_of_packets = DEFAULT_NUMBER_OF_PACKETS, | ||
| 38 | .source_ip = NULL, | ||
| 39 | |||
| 40 | .sender_id = {}, | ||
| 40 | 41 | ||
| 41 | .packets = DEFAULT_NUMBER_OF_PACKETS, | 42 | .mode = MODE_RTA, |
| 42 | 43 | ||
| 43 | .number_of_targets = 0, | 44 | .number_of_targets = 0, |
| 44 | .targets = NULL, | 45 | .targets = NULL, |
| @@ -168,10 +169,10 @@ unsigned int ping_target_list_append(ping_target *list, ping_target *elem) { | |||
| 168 | return result; | 169 | return result; |
| 169 | } | 170 | } |
| 170 | 171 | ||
| 171 | void check_icmp_timeout_handler(int signal, siginfo_t * info, void *ucontext) { | 172 | void check_icmp_timeout_handler(int signal, siginfo_t *info, void *ucontext) { |
| 172 | // Ignore unused arguments | 173 | // Ignore unused arguments |
| 173 | (void) info; | 174 | (void)info; |
| 174 | (void) ucontext; | 175 | (void)ucontext; |
| 175 | mp_subcheck timeout_sc = mp_subcheck_init(); | 176 | mp_subcheck timeout_sc = mp_subcheck_init(); |
| 176 | timeout_sc = mp_set_subcheck_state(timeout_sc, socket_timeout_state); | 177 | timeout_sc = mp_set_subcheck_state(timeout_sc, socket_timeout_state); |
| 177 | 178 | ||
diff --git a/plugins-root/check_icmp.d/config.h b/plugins-root/check_icmp.d/config.h index deae9bec..3599c0f0 100644 --- a/plugins-root/check_icmp.d/config.h +++ b/plugins-root/check_icmp.d/config.h | |||
| @@ -10,20 +10,38 @@ | |||
| 10 | #include <netinet/ip_icmp.h> | 10 | #include <netinet/ip_icmp.h> |
| 11 | #include <netinet/icmp6.h> | 11 | #include <netinet/icmp6.h> |
| 12 | #include <arpa/inet.h> | 12 | #include <arpa/inet.h> |
| 13 | #include <stdint.h> | ||
| 13 | #include "./check_icmp_helpers.h" | 14 | #include "./check_icmp_helpers.h" |
| 14 | 15 | ||
| 15 | /* threshold structure. all values are maximum allowed, exclusive */ | 16 | /* threshold structure. all values are maximum allowed, exclusive */ |
| 16 | typedef struct threshold { | 17 | typedef struct { |
| 17 | unsigned char pl; /* max allowed packet loss in percent */ | 18 | unsigned char pl; /* max allowed packet loss in percent */ |
| 18 | unsigned int rta; /* roundtrip time average, microseconds */ | 19 | unsigned int rta; /* roundtrip time average, microseconds */ |
| 19 | double jitter; /* jitter time average, microseconds */ | 20 | double jitter; /* jitter time average, microseconds */ |
| 20 | double mos; /* MOS */ | 21 | double mos; /* MOS */ |
| 21 | double score; /* Score */ | 22 | double score; /* Score */ |
| 22 | } threshold; | 23 | } check_icmp_threshold; |
| 23 | 24 | ||
| 24 | typedef struct { | 25 | /* the different modes of this program are as follows: |
| 25 | char *source_ip; | 26 | * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping) |
| 27 | * MODE_HOSTCHECK: Return immediately upon any sign of life | ||
| 28 | * In addition, sends packets to ALL addresses assigned | ||
| 29 | * to this host (as returned by gethostbyname() or | ||
| 30 | * gethostbyaddr() and expects one host only to be checked at | ||
| 31 | * a time. Therefore, any packet response what so ever will | ||
| 32 | * count as a sign of life, even when received outside | ||
| 33 | * crit.rta limit. Do not misspell any additional IP's. | ||
| 34 | * MODE_ALL: Requires packets from ALL requested IP to return OK (default). | ||
| 35 | * MODE_ICMP: Default Mode | ||
| 36 | */ | ||
| 37 | typedef enum { | ||
| 38 | MODE_RTA, | ||
| 39 | MODE_HOSTCHECK, | ||
| 40 | MODE_ALL, | ||
| 41 | MODE_ICMP, | ||
| 42 | } check_icmp_execution_mode; | ||
| 26 | 43 | ||
| 44 | typedef struct { | ||
| 27 | bool order_mode; | 45 | bool order_mode; |
| 28 | bool mos_mode; | 46 | bool mos_mode; |
| 29 | bool rta_mode; | 47 | bool rta_mode; |
| @@ -32,18 +50,20 @@ typedef struct { | |||
| 32 | bool score_mode; | 50 | bool score_mode; |
| 33 | 51 | ||
| 34 | int min_hosts_alive; | 52 | int min_hosts_alive; |
| 53 | check_icmp_threshold crit; | ||
| 54 | check_icmp_threshold warn; | ||
| 55 | |||
| 56 | unsigned long ttl; | ||
| 35 | unsigned short icmp_data_size; | 57 | unsigned short icmp_data_size; |
| 36 | unsigned short icmp_pkt_size; | 58 | unsigned short icmp_pkt_size; |
| 37 | unsigned int pkt_interval; | 59 | unsigned int pkt_interval; |
| 38 | unsigned int target_interval; | 60 | unsigned int target_interval; |
| 39 | threshold crit; | 61 | unsigned short number_of_packets; |
| 40 | threshold warn; | 62 | char *source_ip; |
| 41 | pid_t pid; | ||
| 42 | 63 | ||
| 43 | int mode; | 64 | uint16_t sender_id; // PID of the main process, which is used as an ID in packets |
| 44 | unsigned long ttl; | ||
| 45 | 65 | ||
| 46 | unsigned short packets; | 66 | check_icmp_execution_mode mode; |
| 47 | 67 | ||
| 48 | unsigned short number_of_targets; | 68 | unsigned short number_of_targets; |
| 49 | ping_target *targets; | 69 | ping_target *targets; |
| @@ -78,24 +98,6 @@ typedef struct icmp_ping_data { | |||
| 78 | #define DEFAULT_TIMEOUT 10 | 98 | #define DEFAULT_TIMEOUT 10 |
| 79 | #define DEFAULT_TTL 64 | 99 | #define DEFAULT_TTL 64 |
| 80 | 100 | ||
| 81 | /* the different modes of this program are as follows: | ||
| 82 | * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping) | ||
| 83 | * MODE_HOSTCHECK: Return immediately upon any sign of life | ||
| 84 | * In addition, sends packets to ALL addresses assigned | ||
| 85 | * to this host (as returned by gethostbyname() or | ||
| 86 | * gethostbyaddr() and expects one host only to be checked at | ||
| 87 | * a time. Therefore, any packet response what so ever will | ||
| 88 | * count as a sign of life, even when received outside | ||
| 89 | * crit.rta limit. Do not misspell any additional IP's. | ||
| 90 | * MODE_ALL: Requires packets from ALL requested IP to return OK (default). | ||
| 91 | * MODE_ICMP: implement something similar to check_icmp (MODE_RTA without | ||
| 92 | * tcp and udp args does this) | ||
| 93 | */ | ||
| 94 | #define MODE_RTA 0 | ||
| 95 | #define MODE_HOSTCHECK 1 | ||
| 96 | #define MODE_ALL 2 | ||
| 97 | #define MODE_ICMP 3 | ||
| 98 | |||
| 99 | #define DEFAULT_NUMBER_OF_PACKETS 5 | 101 | #define DEFAULT_NUMBER_OF_PACKETS 5 |
| 100 | 102 | ||
| 101 | #define PACKET_BACKOFF_FACTOR 1.5 | 103 | #define PACKET_BACKOFF_FACTOR 1.5 |
