diff options
Diffstat (limited to 'plugins-root/check_icmp.d/check_icmp_helpers.c')
-rw-r--r-- | plugins-root/check_icmp.d/check_icmp_helpers.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.c b/plugins-root/check_icmp.d/check_icmp_helpers.c index 8f6d7362..2efe6e59 100644 --- a/plugins-root/check_icmp.d/check_icmp_helpers.c +++ b/plugins-root/check_icmp.d/check_icmp_helpers.c | |||
@@ -5,6 +5,9 @@ | |||
5 | #include "./check_icmp_helpers.h" | 5 | #include "./check_icmp_helpers.h" |
6 | #include "../../plugins/netutils.h" | 6 | #include "../../plugins/netutils.h" |
7 | 7 | ||
8 | // timeout as a global variable to make it available to the timeout handler | ||
9 | unsigned int timeout = DEFAULT_TIMEOUT; | ||
10 | |||
8 | check_icmp_config check_icmp_config_init() { | 11 | check_icmp_config check_icmp_config_init() { |
9 | check_icmp_config tmp = { | 12 | check_icmp_config tmp = { |
10 | .source_ip = NULL, | 13 | .source_ip = NULL, |
@@ -33,11 +36,14 @@ check_icmp_config check_icmp_config_init() { | |||
33 | .score = 80.0}, | 36 | .score = 80.0}, |
34 | .pid = {}, | 37 | .pid = {}, |
35 | .mode = MODE_RTA, | 38 | .mode = MODE_RTA, |
36 | .timeout = DEFAULT_TIMEOUT, | ||
37 | .ttl = DEFAULT_TTL, | 39 | .ttl = DEFAULT_TTL, |
38 | 40 | ||
39 | .packets = DEFAULT_NUMBER_OF_PACKETS, | 41 | .packets = DEFAULT_NUMBER_OF_PACKETS, |
42 | |||
40 | .number_of_targets = 0, | 43 | .number_of_targets = 0, |
44 | .targets = NULL, | ||
45 | |||
46 | .number_of_hosts = 0, | ||
41 | .hosts = NULL, | 47 | .hosts = NULL, |
42 | }; | 48 | }; |
43 | return tmp; | 49 | return tmp; |
@@ -140,3 +146,43 @@ check_icmp_target_container check_icmp_target_container_init() { | |||
140 | }; | 146 | }; |
141 | return tmp; | 147 | return tmp; |
142 | } | 148 | } |
149 | |||
150 | unsigned int ping_target_list_append(ping_target *list, ping_target *elem) { | ||
151 | if (elem == NULL || list == NULL) { | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | while (list->next != NULL) { | ||
156 | list = list->next; | ||
157 | } | ||
158 | |||
159 | list->next = elem; | ||
160 | |||
161 | unsigned int result = 1; | ||
162 | |||
163 | while (elem->next != NULL) { | ||
164 | result++; | ||
165 | elem = elem->next; | ||
166 | } | ||
167 | |||
168 | return result; | ||
169 | } | ||
170 | |||
171 | void check_icmp_timeout_handler(int signal, siginfo_t * info, void *ucontext) { | ||
172 | // Ignore unused arguments | ||
173 | (void) info; | ||
174 | (void) ucontext; | ||
175 | mp_subcheck timeout_sc = mp_subcheck_init(); | ||
176 | timeout_sc = mp_set_subcheck_state(timeout_sc, socket_timeout_state); | ||
177 | |||
178 | if (signal == SIGALRM) { | ||
179 | xasprintf(&timeout_sc.output, _("timeout after %d seconds\n"), timeout); | ||
180 | } else { | ||
181 | xasprintf(&timeout_sc.output, _("timeout after %d seconds\n"), timeout); | ||
182 | } | ||
183 | |||
184 | mp_check overall = mp_check_init(); | ||
185 | mp_add_subcheck_to_check(&overall, timeout_sc); | ||
186 | |||
187 | mp_exit(overall); | ||
188 | } | ||