[Nagiosplug-checkins] CVS: nagiosplug/plugins check_nagios.c,1.5,1.6

Ton Voon tonvoon at users.sourceforge.net
Tue Mar 25 19:40:08 CET 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv560

Modified Files:
	check_nagios.c 
Log Message:
Uses same ps command as check_procs


Index: check_nagios.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_nagios.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** check_nagios.c	11 Mar 2003 22:22:11 -0000	1.5
--- check_nagios.c	26 Mar 2003 03:39:13 -0000	1.6
***************
*** 41,44 ****
--- 41,46 ----
  int expire_minutes = 0;
  
+ int verbose = 0;
+ 
  int
  main (int argc, char **argv)
***************
*** 52,55 ****
--- 54,63 ----
  	char *temp_ptr;
  	FILE *fp;
+ 	int procuid = 0;
+ 	int procppid = 0;
+ 	char procstat[8];
+ 	char procprog[MAX_INPUT_BUFFER];
+ 	char *procargs;
+ 	int pos, cols;
  
  	if (process_arguments (argc, argv) == ERROR)
***************
*** 83,89 ****
  
  	/* run the command to check for the Nagios process.. */
! 	child_process = spopen (PS_RAW_COMMAND);
  	if (child_process == NULL) {
! 		printf ("Could not open pipe: %s\n", PS_RAW_COMMAND);
  		return STATE_UNKNOWN;
  	}
--- 91,97 ----
  
  	/* run the command to check for the Nagios process.. */
! 	child_process = spopen (PS_COMMAND);
  	if (child_process == NULL) {
! 		printf ("Could not open pipe: %s\n", PS_COMMAND);
  		return STATE_UNKNOWN;
  	}
***************
*** 91,101 ****
  	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
  	if (child_stderr == NULL) {
! 		printf ("Could not open stderr for %s\n", PS_RAW_COMMAND);
  	}
  
  	/* count the number of matching Nagios processes... */
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
! 		if (!strstr(input_buffer, argv[0]) && strstr(input_buffer, process_string))
! 			proc_entries++;
  	}
  
--- 99,120 ----
  	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
  	if (child_stderr == NULL) {
! 		printf ("Could not open stderr for %s\n", PS_COMMAND);
  	}
  
+ 	fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
+ 
  	/* count the number of matching Nagios processes... */
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
! 		cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
! 		if ( cols >= 4 ) {
! 			asprintf (&procargs, "%s", input_buffer + pos);
! 			strip (procargs);
! 			
! 			if (!strstr(procargs, argv[0]) && strstr(procargs, process_string)) {
! 				proc_entries++;
! 				if (verbose)
! 					printf ("Found process: %s\n", procargs);
! 			}
! 		}
  	}
  
***************
*** 152,155 ****
--- 171,175 ----
  		{"version", no_argument, 0, 'V'},
  		{"help", no_argument, 0, 'h'},
+ 		{"verbose", no_argument, 0, 'v'},
  		{0, 0, 0, 0}
  	};
***************
*** 171,175 ****
  
  	while (1) {
! 		c = getopt_long (argc, argv, "+hVF:C:e:", long_options, &option_index);
  
  		if (c == -1 || c == EOF || c == 1)
--- 191,195 ----
  
  	while (1) {
! 		c = getopt_long (argc, argv, "+hVvF:C:e:", long_options, &option_index);
  
  		if (c == -1 || c == EOF || c == 1)
***************
*** 187,197 ****
  			print_revision (progname, "$Revision$");
  			exit (STATE_OK);
! 		case 'F':									/* hostname */
  			status_log = optarg;
  			break;
! 		case 'C':									/* hostname */
  			process_string = optarg;
  			break;
! 		case 'e':									/* hostname */
  			if (is_intnonneg (optarg))
  				expire_minutes = atoi (optarg);
--- 207,217 ----
  			print_revision (progname, "$Revision$");
  			exit (STATE_OK);
! 		case 'F':									/* status log */
  			status_log = optarg;
  			break;
! 		case 'C':									/* command */
  			process_string = optarg;
  			break;
! 		case 'e':									/* expiry time */
  			if (is_intnonneg (optarg))
  				expire_minutes = atoi (optarg);
***************
*** 200,203 ****
--- 220,226 ----
  									 "Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n",
  									 progname);
+ 			break;
+ 		case 'v':
+ 			verbose++;
  			break;
  		}





More information about the Commits mailing list