summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7de561c)
raw | patch | inline | side by side (parent: 7de561c)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 22 Mar 2006 16:45:57 +0000 (16:45 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 22 Mar 2006 16:45:57 +0000 (16:45 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1346 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_dns.c | patch | blob | history | |
plugins/t/check_dns.t | patch | blob | history |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 2a3e376028f8f653b9089296c43d1601d64a0c90..3b94a7abd87f6e8a6e17623c435f5f45c7a3eda6 100644 (file)
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
char expected_address[ADDRESS_LENGTH] = "";
int match_expected_address = FALSE;
int expect_authority = FALSE;
+thresholds *time_thresholds = NULL;
int
main (int argc, char **argv)
else
multi_address = TRUE;
- printf ("DNS %s: ", _("OK"));
+ result = get_status(elapsed_time, time_thresholds);
+ if (result == STATE_OK) {
+ printf ("DNS %s: ", _("OK"));
+ } else if (result == STATE_WARNING) {
+ printf ("DNS %s: ", _("WARNING"));
+ } else if (result == STATE_CRITICAL) {
+ printf ("DNS %s: ", _("CRITICAL"));
+ }
printf (ngettext("%.3f second response time", "%.3f 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));
process_arguments (int argc, char **argv)
{
int c;
+ char *warning = NULL;
+ char *critical = NULL;
int opt_index = 0;
static struct option long_opts[] = {
{"reverse-server", required_argument, 0, 'r'},
{"expected-address", required_argument, 0, 'a'},
{"expect-authority", no_argument, 0, 'A'},
+ {"warning", no_argument, 0, 'w'},
+ {"critical", no_argument, 0, 'c'},
{0, 0, 0, 0}
};
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;
case 'A': /* expect authority */
expect_authority = TRUE;
break;
+ case 'w':
+ warning = optarg;
+ break;
+ case 'c':
+ critical = optarg;
+ break;
default: /* args not parsable */
usage_va(_("Unknown argument - %s"), optarg);
}
strcpy (dns_server, argv[c++]);
}
+ set_thresholds(&time_thresholds, warning, critical);
+
return validate_arguments ();
}
printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with ."));
printf (" -A, --expect-authority\n");
printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
+ printf (" -w, --warning=seconds\n");
+ printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off"));
+ printf (" -c, --critical=seconds\n");
+ printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off"));
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
printf (_(UT_SUPPORT));
{
printf (_("Usage:"));
- printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname);
+ printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname);
}
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index 5d750d3f34e7db32dd8717e5c2a12e2421bf2c35..9a95e808598b8521a578d3c2ab7b5a6999e2babe 100644 (file)
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
plan skip_all => "check_dns not compiled" unless (-x "check_dns");
-plan tests => 11;
+plan tests => 13;
my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/';
cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
like ( $res->output, $successOutput, "Output OK" );
+$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 0");
+cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
+
+$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
+cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
+
$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");