[Nagiosplug-checkins] SF.net SVN: nagiosplug: [2011] nagiosplug/trunk
psychotrahe at users.sourceforge.net
psychotrahe at users.sourceforge.net
Mon Jun 9 21:47:36 CEST 2008
Revision: 2011
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2011&view=rev
Author: psychotrahe
Date: 2008-06-09 12:47:36 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
Added testcases for check_dig
check_dig's -l option is mandatory now (#1986306)
Modified Paths:
--------------
nagiosplug/trunk/NEWS
nagiosplug/trunk/plugins/check_dig.c
Added Paths:
-----------
nagiosplug/trunk/plugins/t/check_dig.t
Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS 2008-06-02 16:22:35 UTC (rev 2010)
+++ nagiosplug/trunk/NEWS 2008-06-09 19:47:36 UTC (rev 2011)
@@ -4,6 +4,8 @@
Fix Debian bug #460097: check_http --max-age broken (Hilko Bengen)
Optimised pst3 for systems with large number of processes (Duncan Ferguson)
Updated Nagios::Plugin to 0.27
+ Fix Debian bug #479013: check_dig's -l is mandatory now (sf.net #1986306)
+ check_dig now returns CRITICAL instead of WARNING when no answer section is found
1.4.12 27th May 2008
Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren)
Modified: nagiosplug/trunk/plugins/check_dig.c
===================================================================
--- nagiosplug/trunk/plugins/check_dig.c 2008-06-02 16:22:35 UTC (rev 2010)
+++ nagiosplug/trunk/plugins/check_dig.c 2008-06-09 19:47:36 UTC (rev 2011)
@@ -143,8 +143,10 @@
}
}
- if (result == STATE_UNKNOWN)
+ if (result == STATE_UNKNOWN) {
msg = (char *)_("No ANSWER SECTION found");
+ result = STATE_CRITICAL;
+ }
/* If we get anything on STDERR, at least set warning */
if(chld_err.buflen > 0) {
@@ -295,7 +297,10 @@
int
validate_arguments (void)
{
- return OK;
+ if (query_address != NULL)
+ return OK;
+ else
+ return ERROR;
}
@@ -357,7 +362,7 @@
print_usage (void)
{
printf (_("Usage:"));
- printf ("%s -H <host> -l <query_address> [-p <server port>]\n", progname);
+ printf ("%s -l <query_address> [-H <host>] [-p <server port>]\n", progname);
printf (" [-T <query type>] [-w <warning interval>] [-c <critical interval>]\n");
printf (" [-t <timeout>] [-a <expected answer address>] [-v]\n");
}
Added: nagiosplug/trunk/plugins/t/check_dig.t
===================================================================
--- nagiosplug/trunk/plugins/t/check_dig.t (rev 0)
+++ nagiosplug/trunk/plugins/t/check_dig.t 2008-06-09 19:47:36 UTC (rev 2011)
@@ -0,0 +1,85 @@
+#! /usr/bin/perl -w -I ..
+#
+# Domain Name Server (DNS) Tests via check_dig
+#
+# $Id$
+#
+
+use strict;
+use Test::More;
+use NPTest;
+
+plan skip_all => "check_dig not compiled" unless (-x "check_dig");
+
+plan tests => 12;
+
+my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/';
+
+my $hostname_valid = getTestParameter(
+ "NP_HOSTNAME_VALID",
+ "A valid (known to DNS) hostname",
+ "nagios.com"
+ );
+
+my $hostname_valid_ip = getTestParameter(
+ "NP_HOSTNAME_VALID_IP",
+ "The IP address of the valid hostname $hostname_valid",
+ "66.118.156.50",
+ );
+
+my $hostname_valid_reverse = getTestParameter(
+ "NP_HOSTNAME_VALID_REVERSE",
+ "The hostname of $hostname_valid_ip",
+ "66-118-156-50.static.sagonet.net.",
+ );
+
+my $hostname_invalid = getTestParameter(
+ "NP_HOSTNAME_INVALID",
+ "An invalid (not known to DNS) hostname",
+ "nosuchhost.altinity.com",
+ );
+
+my $dns_server = getTestParameter(
+ "NP_DNS_SERVER",
+ "A non default (remote) DNS server",
+ );
+
+my $res;
+
+SKIP: {
+ skip "check_dig.t: not enough parameters given",
+ 12 unless ($hostname_valid && $hostname_valid_ip && $hostname_valid_reverse && $hostname_invalid && $dns_server);
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5");
+ cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
+ like ( $res->output, $successOutput, "Output OK" );
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 0.00001");
+ cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 5");
+ cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -t 1");
+ cmp_ok( $res->return_code, '==', 3, "Invalid command line -l missing");
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_invalid -t 1");
+ cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5");
+ cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
+ like ( $res->output, $successOutput, "Output OK" );
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5");
+ cmp_ok( $res->return_code, '==', 0, "Got expected address");
+
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a 10.10.10.10 -t 5");
+ cmp_ok( $res->return_code, '==', 1, "Got wrong address");
+
+ my $ip_reverse = $hostname_valid_ip;
+ $ip_reverse =~ s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$4.$3.$2.$1.in-addr.arpa/;
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $ip_reverse -a $hostname_valid_reverse -T PTR -t 5");
+ cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
+ like ( $res->output, $successOutput, "Output OK");
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list