[Nagiosplug-checkins] CVS: nagiosplug/plugins check_by_ssh.c,1.18,1.19

Karl DeBisschop kdebisschop at users.sourceforge.net
Fri Feb 20 21:50:06 CET 2004


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

Modified Files:
	check_by_ssh.c 
Log Message:
add option to ignore a specified number of lines on stderr
(to suppress a login banner)


Index: check_by_ssh.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_by_ssh.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** check_by_ssh.c	22 Aug 2003 06:22:37 -0000	1.18
--- check_by_ssh.c	21 Feb 2004 05:37:34 -0000	1.19
***************
*** 34,37 ****
--- 34,38 ----
  int commands = 0;
  int services = 0;
+ int skip_lines = 0;
  char *remotecmd = NULL;
  char *comm = NULL;
***************
*** 102,114 ****
  		asprintf (&result_text, "%s%s", result_text, input_buffer);
  
- 
  	/* WARNING if output found on stderr */
! 	if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
! 		printf ("%s\n", input_buffer);
! 		while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
! 			printf ("%s\n", input_buffer);
! 		return STATE_WARNING;
  	}
  	(void) fclose (child_stderr);
  
  
--- 103,120 ----
  		asprintf (&result_text, "%s%s", result_text, input_buffer);
  
  	/* WARNING if output found on stderr */
! 	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
! 		if (skip_lines > 0) {
! 			if (input_buffer[strlen(input_buffer)-1] == '\n') {
! 				skip_lines--;
! 			}
! 		} else {
! 			printf ("%s", input_buffer);
! 			result = STATE_WARNING;
! 		}
  	}
  	(void) fclose (child_stderr);
+ 	if (result == STATE_WARNING)
+ 		return result;
  
  
***************
*** 190,193 ****
--- 196,200 ----
  		{"logname", required_argument, 0, 'l'},
  		{"command", required_argument, 0, 'C'},
+ 		{"skip", required_argument, 0, 'S'},
  		{"proto1", no_argument, 0, '1'},
  		{"proto2", no_argument, 0, '2'},
***************
*** 205,209 ****
  
  	while (1) {
! 		c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", longopts,
  									 &option);
  
--- 212,216 ----
  
  	while (1) {
! 		c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:S:n:s:", longopts,
  									 &option);
  
***************
*** 276,279 ****
--- 283,293 ----
  				asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
  			asprintf (&remotecmd, "%s%s", remotecmd, optarg);
+ 			break;
+ 		case 'S':									/* Skip n lines in the output to ignore system banner */
+ 			if (!is_integer (optarg))
+ 				usage2 (_("skip lines must be an integer"), optarg);
+ 			else
+ 				skip_lines = atoi (optarg);
+ 			break;
  		}
  	}
***************
*** 354,357 ****
--- 368,373 ----
   -2, --proto2\n\
      tell ssh to use Protocol 2\n\
+  -S, --skiplines=n\n\
+     Ignore first n lines on STDERR (to suppress a logon banner)\n\
   -f\n\
      tells ssh to fork rather than create a tty\n"));





More information about the Commits mailing list