[Nagiosplug-checkins] CVS: nagiosplug/plugins check_dns.c,1.25,1.26

Karl DeBisschop kdebisschop at users.sourceforge.net
Wed Feb 25 00:59:06 CET 2004


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30038/plugins

Modified Files:
	check_dns.c 
Log Message:
check server for authoritative status (from Jon Hallet)

Index: check_dns.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dns.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** check_dns.c	20 Feb 2004 02:09:35 -0000	1.25
--- check_dns.c	25 Feb 2004 08:51:03 -0000	1.26
***************
*** 8,12 ****
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
--- 8,12 ----
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.
  
***************
*** 43,46 ****
--- 43,47 ----
  char expected_address[ADDRESS_LENGTH] = "";
  int match_expected_address = FALSE;
+ int expect_authority = FALSE;
  
  int
***************
*** 52,55 ****
--- 53,57 ----
  	char *address = NULL;
  	char *temp_buffer = NULL;
+ 	int non_authoritative = FALSE;
  	int result = STATE_UNKNOWN;
  	double elapsed_time;
***************
*** 57,61 ****
  	struct timeval tv;
  	int multi_address;
! 	int parse_address = FALSE;	/* This flag scans for Address: but only after Name: */
  
  	setlocale (LC_ALL, "");
--- 59,63 ----
  	struct timeval tv;
  	int multi_address;
! 	int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
  
  	setlocale (LC_ALL, "");
***************
*** 75,79 ****
  
  	/* get the command to run */
! 	asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND,	query_address, dns_server);
  
  	alarm (timeout_interval);
--- 77,81 ----
  
  	/* get the command to run */
! 	asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server);
  
  	alarm (timeout_interval);
***************
*** 112,116 ****
  		if (strstr (input_buffer, "Name:"))
  			parse_address = TRUE;
! 		else if (parse_address == TRUE && (strstr (input_buffer, "Address:") || strstr (input_buffer, "Addresses:"))) {
  			temp_buffer = index (input_buffer, ':');
  			temp_buffer++;
--- 114,119 ----
  		if (strstr (input_buffer, "Name:"))
  			parse_address = TRUE;
! 		else if (parse_address == TRUE && (strstr (input_buffer, "Address:") ||
! 		         strstr (input_buffer, "Addresses:"))) {
  			temp_buffer = index (input_buffer, ':');
  			temp_buffer++;
***************
*** 122,127 ****
  			strip(temp_buffer);
  			if (temp_buffer==NULL || strlen(temp_buffer)==0) {
! 				die (STATE_CRITICAL, _("DNS CRITICAL - '%s' returned empty host name string\n"),
! 										 NSLOOKUP_COMMAND);
  			}
  
--- 125,131 ----
  			strip(temp_buffer);
  			if (temp_buffer==NULL || strlen(temp_buffer)==0) {
! 				die (STATE_CRITICAL,
! 				     _("DNS CRITICAL - '%s' returned empty host name string\n"),
! 				     NSLOOKUP_COMMAND);
  			}
  
***************
*** 132,135 ****
--- 136,143 ----
  		}
  
+ 		else if (strstr (input_buffer, "Non-authoritative answer:")) {
+ 			non_authoritative = TRUE;
+ 		}
+ 
  		result = error_scan (input_buffer);
  		if (result != STATE_OK) {
***************
*** 164,169 ****
  	if (address==NULL || strlen(address)==0)
  		die (STATE_CRITICAL,
! 							 _("DNS CRITICAL - '%s' output parsing exited with no address\n"),
! 							 NSLOOKUP_COMMAND);
  
  	/* compare to expected address */
--- 172,177 ----
  	if (address==NULL || strlen(address)==0)
  		die (STATE_CRITICAL,
! 		     _("DNS CRITICAL - '%s' output parsing exited with no address\n"),
! 		     NSLOOKUP_COMMAND);
  
  	/* compare to expected address */
***************
*** 173,176 ****
--- 181,190 ----
  	}
  
+ 	/* check if authoritative */
+ 	if (result == STATE_OK && expect_authority && non_authoritative) {
+ 		result = STATE_CRITICAL;
+ 		asprintf(&output, _("server %s is not authoritative for %s"), dns_server, query_address);
+ 	}
+ 
  	microsec = deltime (tv);
  	elapsed_time = (double)microsec / 1.0e6;
***************
*** 189,199 ****
  	else if (result == STATE_WARNING)
  		printf (_("DNS WARNING - %s\n"),
! 						!strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
  	else if (result == STATE_CRITICAL)
  		printf (_("DNS CRITICAL - %s\n"),
! 						!strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
  	else
  		printf (_("DNS problem - %s\n"),
! 						!strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
  
  	return result;
--- 203,213 ----
  	else if (result == STATE_WARNING)
  		printf (_("DNS WARNING - %s\n"),
! 		        !strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
  	else if (result == STATE_CRITICAL)
  		printf (_("DNS CRITICAL - %s\n"),
! 		        !strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
  	else
  		printf (_("DNS problem - %s\n"),
! 		        !strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
  
  	return result;
***************
*** 205,209 ****
  
  	/* the DNS lookup timed out */
! 	if (strstr (input_buffer,	"Note:  nslookup is deprecated and may be removed from future releases.") ||
  	    strstr (input_buffer, "Consider using the `dig' or `host' programs instead.  Run nslookup with") ||
  	    strstr (input_buffer, "the `-sil[ent]' option to prevent this message from appearing."))
--- 219,223 ----
  
  	/* the DNS lookup timed out */
! 	if (strstr (input_buffer, "Note: nslookup is deprecated and may be removed from future releases.") ||
  	    strstr (input_buffer, "Consider using the `dig' or `host' programs instead.  Run nslookup with") ||
  	    strstr (input_buffer, "the `-sil[ent]' option to prevent this message from appearing."))
***************
*** 220,226 ****
  	/* Connection was refused */
  	else if (strstr (input_buffer, "Connection refused") ||
  	         (strstr (input_buffer, "** server can't find") &&
! 	          strstr (input_buffer, ": REFUSED")) ||
! 	         (strstr (input_buffer, "Refused")))
  		die (STATE_CRITICAL, _("Connection to name server %s was refused\n"), dns_server);
  
--- 234,240 ----
  	/* Connection was refused */
  	else if (strstr (input_buffer, "Connection refused") ||
+ 	         strstr (input_buffer, "Refused") ||
  	         (strstr (input_buffer, "** server can't find") &&
! 	          strstr (input_buffer, ": REFUSED")))
  		die (STATE_CRITICAL, _("Connection to name server %s was refused\n"), dns_server);
  
***************
*** 264,267 ****
--- 278,282 ----
  		{"reverse-server", required_argument, 0, 'r'},
  		{"expected-address", required_argument, 0, 'a'},
+ 		{"expect-authority", no_argument, 0, 'A'},
  		{0, 0, 0, 0}
  	};
***************
*** 275,279 ****
  
  	while (1) {
! 		c = getopt_long (argc, argv, "hVvt:H:s:r:a:", long_opts, &opt_index);
  
  		if (c == -1 || c == EOF)
--- 290,294 ----
  
  	while (1) {
! 		c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index);
  
  		if (c == -1 || c == EOF)
***************
*** 303,308 ****
  			break;
  		case 's': /* server name */
! 			/* TODO: this is_host check is probably unnecessary. Better to confirm nslookup
! 			   response matches */
  			if (is_host (optarg) == FALSE) {
  				printf (_("Invalid server name/address\n\n"));
--- 318,323 ----
  			break;
  		case 's': /* server name */
! 			/* TODO: this is_host check is probably unnecessary. */
! 			/* Better to confirm nslookup response matches */
  			if (is_host (optarg) == FALSE) {
  				printf (_("Invalid server name/address\n\n"));
***************
*** 331,334 ****
--- 346,352 ----
  			match_expected_address = TRUE;
  			break;
+ 		case 'A': /* expect authority */
+ 			expect_authority = TRUE;
+ 			break;
  		}
  	}
***************
*** 387,391 ****
     Optional DNS server you want to use for the lookup\n\
  -a, --expected-address=IP-ADDRESS\n\
!    Optional IP address you expect the DNS server to return\n"));
  
  	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
--- 405,411 ----
     Optional DNS server you want to use for the lookup\n\
  -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"));
  
  	printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
***************
*** 407,413 ****
  {
  	printf (_("\
! Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\
         %s --help\n\
!        %s --version\n"),
! 					progname, progname, progname);
  }
--- 427,432 ----
  {
  	printf (_("\
! Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n\
         %s --help\n\
!        %s --version\n"), progname, progname, progname);
  }





More information about the Commits mailing list