diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2026-06-11 02:40:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-11 02:40:07 +0200 |
| commit | 1372654e8a2d392db35aae8f62586d55319ccb3c (patch) | |
| tree | 016ba24eda7a01d2b764c036e5e963493f1199f1 /plugins | |
| parent | cc8d5b55dea3862d274891c1e91804576006d28b (diff) | |
| download | monitoring-plugins-1372654e8a2d392db35aae8f62586d55319ccb3c.tar.gz | |
* check_ntp_time: add polling delay
NTP server can have rate limiting which might be triggered by
check_ntp_time due to many requests in a short time span.
This patch adds a default delay (of 0.5s) between requests to each server
and a command line option (--poll-delay) to make this delay
configurable.
Co-authored-by: Lorenz Kästle <lorenz@vulgrim.de>
* check_ntp_time: verify whether socket path fits into address struct
check_ntp_time could be give a too long (>108 bytes) socket path
to work with, which would potentially crash the program.
This patch validates to length beforehand and stops execution
in that case.
Co-authored-by: Lorenz Kästle <lorenz@vulgrim.de>
---------
Co-authored-by: Paul Crawford <paul@crawford-space.co.uk>
Co-authored-by: Lorenz Kästle <lorenz@vulgrim.de>
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_ntp_time.c | 6 | ||||
| -rw-r--r-- | plugins/check_ntp_time.d/config.h | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 3e23d0bf..2d9a6f40 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #include "thresholds.h" | 43 | #include "thresholds.h" |
| 44 | #include "check_ntp_time.d/config.h" | 44 | #include "check_ntp_time.d/config.h" |
| 45 | #include <netinet/in.h> | 45 | #include <netinet/in.h> |
| 46 | #include <string.h> | ||
| 46 | #include <sys/socket.h> | 47 | #include <sys/socket.h> |
| 47 | 48 | ||
| 48 | static int verbose = 0; | 49 | static int verbose = 0; |
| @@ -395,7 +396,10 @@ static offset_request_wrapper offset_request(const char *host, const char *port, | |||
| 395 | .sun_family = AF_UNIX, | 396 | .sun_family = AF_UNIX, |
| 396 | }; | 397 | }; |
| 397 | 398 | ||
| 398 | strncpy(unix_socket.sun_path, host, strlen(host)); | 399 | if (strlen(host) > sizeof(unix_socket.sun_path)) { |
| 400 | die(STATE_UNKNOWN, "host argument is too long (%lu) for a socket path\n", strlen(host)); | ||
| 401 | } | ||
| 402 | strncpy(unix_socket.sun_path, host, sizeof(unix_socket.sun_path)); | ||
| 399 | 403 | ||
| 400 | if (connect(socklist[0], &unix_socket, sizeof(unix_socket))) { | 404 | if (connect(socklist[0], &unix_socket, sizeof(unix_socket))) { |
| 401 | /* don't die here, because it is enough if there is one server | 405 | /* don't die here, because it is enough if there is one server |
diff --git a/plugins/check_ntp_time.d/config.h b/plugins/check_ntp_time.d/config.h index 9bbd82aa..c1aa142c 100644 --- a/plugins/check_ntp_time.d/config.h +++ b/plugins/check_ntp_time.d/config.h | |||
| @@ -5,6 +5,9 @@ | |||
| 5 | #include "thresholds.h" | 5 | #include "thresholds.h" |
| 6 | #include <stddef.h> | 6 | #include <stddef.h> |
| 7 | 7 | ||
| 8 | /* Time in microseconds to delay between polling to avoid a blocking response. */ | ||
| 9 | const long default_polling_delay = 500000L; | ||
| 10 | |||
| 8 | typedef struct { | 11 | typedef struct { |
| 9 | char *server_address; | 12 | char *server_address; |
| 10 | char *port; | 13 | char *port; |
| @@ -15,6 +18,7 @@ typedef struct { | |||
| 15 | mp_thresholds offset_thresholds; | 18 | mp_thresholds offset_thresholds; |
| 16 | 19 | ||
| 17 | bool output_format_is_set; | 20 | bool output_format_is_set; |
| 21 | long poll_delay; | ||
| 18 | mp_output_format output_format; | 22 | mp_output_format output_format; |
| 19 | } check_ntp_time_config; | 23 | } check_ntp_time_config; |
| 20 | 24 | ||
| @@ -29,6 +33,7 @@ check_ntp_time_config check_ntp_time_config_init() { | |||
| 29 | .offset_thresholds = mp_thresholds_init(), | 33 | .offset_thresholds = mp_thresholds_init(), |
| 30 | 34 | ||
| 31 | .output_format_is_set = false, | 35 | .output_format_is_set = false, |
| 36 | .poll_delay = default_polling_delay, | ||
| 32 | }; | 37 | }; |
| 33 | 38 | ||
| 34 | mp_range warning = mp_range_init(); | 39 | mp_range warning = mp_range_init(); |
