From df53473d03783ef853465c80162758bb6ee403c7 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Thu, 30 Jan 2014 09:35:41 +0100 Subject: 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 --- THANKS.in | 1 + plugins/check_dig.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/THANKS.in b/THANKS.in index aef787c2..2cfa54ec 100644 --- a/THANKS.in +++ b/THANKS.in @@ -305,3 +305,4 @@ Geoff Oakham Tim Laszlo Stéphane Bortzmeyer Luca Corti +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); #define UNDEFINED 0 #define DEFAULT_PORT 53 +#define DEFAULT_TRIES 3 +#define DEFAULT_TIMEOUT 10 char *query_address = NULL; char *record_type = "A"; @@ -57,6 +59,7 @@ char *dig_args = ""; char *query_transport = ""; int verbose = FALSE; int server_port = DEFAULT_PORT; +int number_tries = DEFAULT_TRIES; double warning_interval = UNDEFINED; double critical_interval = UNDEFINED; struct timeval tv; @@ -72,6 +75,7 @@ main (int argc, char **argv) long microsec; double elapsed_time; int result = STATE_UNKNOWN; + timeout_interval = DEFAULT_TIMEOUT; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); @@ -87,9 +91,12 @@ main (int argc, char **argv) if (process_arguments (argc, argv) == ERROR) usage_va(_("Could not parse arguments")); + /* dig applies the timeout to each try, so we need to work around this */ + int timeout_interval_dig = ceil((double) timeout_interval / (double) number_tries); + /* get the command to run */ - xasprintf (&command_line, "%s %s @%s -p %d %s -t %s %s", - PATH_TO_DIG, query_transport, dns_server, server_port, query_address, record_type, dig_args); + xasprintf (&command_line, "%s @%s -p %d %s -t %s %s %s +tries=%d +time=%d", + PATH_TO_DIG, dns_server, server_port, query_address, record_type, dig_args, query_transport, number_tries, timeout_interval_dig); alarm (timeout_interval); gettimeofday (&tv, NULL); -- cgit v1.2.3-74-g34f1