summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_dns.c30
-rw-r--r--plugins/t/check_dns.t8
2 files changed, 34 insertions, 4 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 2a3e376..3b94a7a 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -45,6 +45,7 @@ int verbose = FALSE;
45char expected_address[ADDRESS_LENGTH] = ""; 45char expected_address[ADDRESS_LENGTH] = "";
46int match_expected_address = FALSE; 46int match_expected_address = FALSE;
47int expect_authority = FALSE; 47int expect_authority = FALSE;
48thresholds *time_thresholds = NULL;
48 49
49int 50int
50main (int argc, char **argv) 51main (int argc, char **argv)
@@ -183,7 +184,14 @@ main (int argc, char **argv)
183 else 184 else
184 multi_address = TRUE; 185 multi_address = TRUE;
185 186
186 printf ("DNS %s: ", _("OK")); 187 result = get_status(elapsed_time, time_thresholds);
188 if (result == STATE_OK) {
189 printf ("DNS %s: ", _("OK"));
190 } else if (result == STATE_WARNING) {
191 printf ("DNS %s: ", _("WARNING"));
192 } else if (result == STATE_CRITICAL) {
193 printf ("DNS %s: ", _("CRITICAL"));
194 }
187 printf (ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time); 195 printf (ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time);
188 printf (_(". %s returns %s"), query_address, address); 196 printf (_(". %s returns %s"), query_address, address);
189 printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); 197 printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
@@ -266,6 +274,8 @@ int
266process_arguments (int argc, char **argv) 274process_arguments (int argc, char **argv)
267{ 275{
268 int c; 276 int c;
277 char *warning = NULL;
278 char *critical = NULL;
269 279
270 int opt_index = 0; 280 int opt_index = 0;
271 static struct option long_opts[] = { 281 static struct option long_opts[] = {
@@ -278,6 +288,8 @@ process_arguments (int argc, char **argv)
278 {"reverse-server", required_argument, 0, 'r'}, 288 {"reverse-server", required_argument, 0, 'r'},
279 {"expected-address", required_argument, 0, 'a'}, 289 {"expected-address", required_argument, 0, 'a'},
280 {"expect-authority", no_argument, 0, 'A'}, 290 {"expect-authority", no_argument, 0, 'A'},
291 {"warning", no_argument, 0, 'w'},
292 {"critical", no_argument, 0, 'c'},
281 {0, 0, 0, 0} 293 {0, 0, 0, 0}
282 }; 294 };
283 295
@@ -289,7 +301,7 @@ process_arguments (int argc, char **argv)
289 strcpy (argv[c], "-t"); 301 strcpy (argv[c], "-t");
290 302
291 while (1) { 303 while (1) {
292 c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index); 304 c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index);
293 305
294 if (c == -1 || c == EOF) 306 if (c == -1 || c == EOF)
295 break; 307 break;
@@ -336,6 +348,12 @@ process_arguments (int argc, char **argv)
336 case 'A': /* expect authority */ 348 case 'A': /* expect authority */
337 expect_authority = TRUE; 349 expect_authority = TRUE;
338 break; 350 break;
351 case 'w':
352 warning = optarg;
353 break;
354 case 'c':
355 critical = optarg;
356 break;
339 default: /* args not parsable */ 357 default: /* args not parsable */
340 usage_va(_("Unknown argument - %s"), optarg); 358 usage_va(_("Unknown argument - %s"), optarg);
341 } 359 }
@@ -356,6 +374,8 @@ process_arguments (int argc, char **argv)
356 strcpy (dns_server, argv[c++]); 374 strcpy (dns_server, argv[c++]);
357 } 375 }
358 376
377 set_thresholds(&time_thresholds, warning, critical);
378
359 return validate_arguments (); 379 return validate_arguments ();
360} 380}
361 381
@@ -395,6 +415,10 @@ print_help (void)
395 printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with .")); 415 printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with ."));
396 printf (" -A, --expect-authority\n"); 416 printf (" -A, --expect-authority\n");
397 printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); 417 printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
418 printf (" -w, --warning=seconds\n");
419 printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off"));
420 printf (" -c, --critical=seconds\n");
421 printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off"));
398 422
399 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 423 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
400 printf (_(UT_SUPPORT)); 424 printf (_(UT_SUPPORT));
@@ -406,5 +430,5 @@ print_usage (void)
406{ 430{
407 printf (_("Usage:")); 431 printf (_("Usage:"));
408 432
409 printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname); 433 printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname);
410} 434}
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index 5d750d3..9a95e80 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -11,7 +11,7 @@ use NPTest;
11 11
12plan skip_all => "check_dns not compiled" unless (-x "check_dns"); 12plan skip_all => "check_dns not compiled" unless (-x "check_dns");
13 13
14plan tests => 11; 14plan tests => 13;
15 15
16my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; 16my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/';
17 17
@@ -50,6 +50,12 @@ $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
50cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid"); 50cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
51like ( $res->output, $successOutput, "Output OK" ); 51like ( $res->output, $successOutput, "Output OK" );
52 52
53$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 0");
54cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
55
56$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
57cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
58
53$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1"); 59$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
54cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid"); 60cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
55 61