--- ../../original_sources/nagios-plugins-1.4.2/plugins/check_dns.c 2004-12-29 19:41:39.000000000 -0500 +++ nagios-plugins-1.4.2/plugins/check_dns.c 2005-10-19 22:54:35.000000000 -0400 @@ -45,6 +45,8 @@ char expected_address[ADDRESS_LENGTH] = ""; int match_expected_address = FALSE; int expect_authority = FALSE; +double elapsed_warn_time = 0.0; +double elapsed_crit_time = 0.0; int main (int argc, char **argv) @@ -193,6 +195,21 @@ microsec = deltime (tv); elapsed_time = (double)microsec / 1.0e6; + + /* check elapsed time */ + if ((result == STATE_OK) && + ((elapsed_warn_time != 0.0) && (elapsed_warn_time <= elapsed_time)) && + ((elapsed_crit_time == 0.0) || elapsed_crit_time > elapsed_time) ) { + result = STATE_WARNING; + asprintf(&output, _("server %s responded too slowly. %.5f seconds response time."), dns_server, elapsed_time); + } + + if ((result == STATE_OK) && (elapsed_crit_time != 0) && + (elapsed_crit_time <= elapsed_time) ) { + result = STATE_CRITICAL; + asprintf(&output, _("server %s responded too slowly. %.5f seconds response time."), dns_server, elapsed_time); + } + if (result == STATE_OK) { if (strchr (address, ',') == NULL) multi_address = FALSE; @@ -200,7 +217,7 @@ multi_address = TRUE; printf ("DNS %s: ", _("OK")); - printf (ngettext("%.3f second response time ", "%.3f seconds response time ", elapsed_time), elapsed_time); + printf (ngettext("%.5f second response time ", "%.5f seconds response time ", elapsed_time), elapsed_time); printf (_("%s returns %s"), query_address, address); printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); } @@ -294,6 +311,8 @@ {"reverse-server", required_argument, 0, 'r'}, {"expected-address", required_argument, 0, 'a'}, {"expect-authority", no_argument, 0, 'A'}, + {"warning", required_argument, 0, 'w'}, + {"critical", required_argument, 0, 'c'}, {0, 0, 0, 0} }; @@ -305,7 +324,7 @@ strcpy (argv[c], "-t"); while (1) { - c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index); + c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index); if (c == -1 || c == EOF) break; @@ -358,6 +377,12 @@ case 'A': /* expect authority */ expect_authority = TRUE; break; + case 'w': /* elapsed time > warning */ + elapsed_warn_time = atof (optarg); + break; + case 'c': /* elapsed time > critical */ + elapsed_crit_time = atof (optarg); + break; } } @@ -387,11 +412,13 @@ validate_arguments () { if (query_address[0] == 0) - return ERROR; - else - return OK; -} + usage4 (_("Can't determine/parse address to query.")); + + if ( elapsed_crit_time != 0.0 && elapsed_warn_time > elapsed_crit_time ) + usage4 (_("Warning time must be less than critical time.")); + return OK; +} void print_help (void) @@ -419,7 +446,13 @@ -a, --expected-address=IP-ADDRESS\n\ Optional IP address you expect the DNS server to return\n\ -A, --expect-authority\n\ - Optionally expect the DNS server to be authoritative for the lookup\n")); + Optionally expect the DNS server to be authoritative for the lookup\n\ +-w, --warning=seconds\n\ + Return warning if elapsed time exceeds value. Default is 0.0 seconds (off).\n\ +-c, --critical=seconds\n\ + Return critical if elapsed time exceeds value. Default is 0.0 seconds (off).\n\ +\n\ +seconds are floating point values. Set to 0 turn off check.\n")); printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); @@ -431,5 +464,5 @@ print_usage (void) { printf ("\ -Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname); +Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname); }