diff options
author | Jan Wagner <waja@cyconet.org> | 2014-01-30 09:35:41 +0100 |
---|---|---|
committer | Jan Wagner <waja@cyconet.org> | 2014-01-30 11:07:22 +0100 |
commit | df53473d03783ef853465c80162758bb6ee403c7 (patch) | |
tree | 7cd67f0a582c6164546c4c187aa02c6f2800ed88 | |
parent | 7310030ae7a30f61990641c5c1674531823f457f (diff) | |
download | monitoring-plugins-df53473d03783ef853465c80162758bb6ee403c7.tar.gz |
check_dig: patch to make dig honor -t option
When a timeout value is specified with the -t option, dig will sometimes
timeout before the timer is actually reached.
The problem occurs because the check_dig plugin does not pass the specified
timeout value to dig, leaving dig to timeout with it's default value which
seems to be around 10-15seconds.
To reproduce:
time ./check_dig -H 127.0.0.2 -l www.google.com -t 30
It will not run for 30secs, which is the expected behaviour.
The following will work, because the timeout is less than the default dig
timeout, so the plugin cancels the dig command:
time ./check_dig -H 127.0.0.2 -l www.google.com -t 2
This fix passes the timeout value to dig, and sets the number of retries which tends to vary from system to system by default.
Closes #1168
-rw-r--r-- | THANKS.in | 1 | ||||
-rw-r--r-- | plugins/check_dig.c | 11 |
2 files changed, 10 insertions, 2 deletions
@@ -305,3 +305,4 @@ Geoff Oakham | |||
305 | Tim Laszlo | 305 | Tim Laszlo |
306 | Stéphane Bortzmeyer | 306 | Stéphane Bortzmeyer |
307 | Luca Corti | 307 | Luca Corti |
308 | Jethro Carr | ||
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 7575995d..5638017c 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -48,6 +48,8 @@ void print_usage (void); | |||
48 | 48 | ||
49 | #define UNDEFINED 0 | 49 | #define UNDEFINED 0 |
50 | #define DEFAULT_PORT 53 | 50 | #define DEFAULT_PORT 53 |
51 | #define DEFAULT_TRIES 3 | ||
52 | #define DEFAULT_TIMEOUT 10 | ||
51 | 53 | ||
52 | char *query_address = NULL; | 54 | char *query_address = NULL; |
53 | char *record_type = "A"; | 55 | char *record_type = "A"; |
@@ -57,6 +59,7 @@ char *dig_args = ""; | |||
57 | char *query_transport = ""; | 59 | char *query_transport = ""; |
58 | int verbose = FALSE; | 60 | int verbose = FALSE; |
59 | int server_port = DEFAULT_PORT; | 61 | int server_port = DEFAULT_PORT; |
62 | int number_tries = DEFAULT_TRIES; | ||
60 | double warning_interval = UNDEFINED; | 63 | double warning_interval = UNDEFINED; |
61 | double critical_interval = UNDEFINED; | 64 | double critical_interval = UNDEFINED; |
62 | struct timeval tv; | 65 | struct timeval tv; |
@@ -72,6 +75,7 @@ main (int argc, char **argv) | |||
72 | long microsec; | 75 | long microsec; |
73 | double elapsed_time; | 76 | double elapsed_time; |
74 | int result = STATE_UNKNOWN; | 77 | int result = STATE_UNKNOWN; |
78 | timeout_interval = DEFAULT_TIMEOUT; | ||
75 | 79 | ||
76 | setlocale (LC_ALL, ""); | 80 | setlocale (LC_ALL, ""); |
77 | bindtextdomain (PACKAGE, LOCALEDIR); | 81 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -87,9 +91,12 @@ main (int argc, char **argv) | |||
87 | if (process_arguments (argc, argv) == ERROR) | 91 | if (process_arguments (argc, argv) == ERROR) |
88 | usage_va(_("Could not parse arguments")); | 92 | usage_va(_("Could not parse arguments")); |
89 | 93 | ||
94 | /* dig applies the timeout to each try, so we need to work around this */ | ||
95 | int timeout_interval_dig = ceil((double) timeout_interval / (double) number_tries); | ||
96 | |||
90 | /* get the command to run */ | 97 | /* get the command to run */ |
91 | xasprintf (&command_line, "%s %s @%s -p %d %s -t %s %s", | 98 | xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s +tries=%d +time=%d", |
92 | PATH_TO_DIG, query_transport, dns_server, server_port, query_address, record_type, dig_args); | 99 | PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport, number_tries, timeout_interval_dig); |
93 | 100 | ||
94 | alarm (timeout_interval); | 101 | alarm (timeout_interval); |
95 | gettimeofday (&tv, NULL); | 102 | gettimeofday (&tv, NULL); |