[Nagiosplug-checkins] CVS: nagiosplug/plugins check_snmp.c,1.6,1.7

Karl DeBisschop kdebisschop at users.sourceforge.net
Sun Oct 20 13:23:02 CEST 2002


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv21464

Modified Files:
	check_snmp.c 
Log Message:
fixed scanning for multiple OIDs, which was not working


Index: check_snmp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_snmp.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** check_snmp.c	20 Oct 2002 18:49:00 -0000	1.6
--- check_snmp.c	20 Oct 2002 20:22:20 -0000	1.7
***************
*** 95,99 ****
  char *server_address = NULL;
  char *community = NULL;
! char oid[MAX_INPUT_BUFFER] = "";
  char *label = NULL;
  char *units = NULL;
--- 95,99 ----
  char *server_address = NULL;
  char *community = NULL;
! char *oid = NULL;
  char *label = NULL;
  char *units = NULL;
***************
*** 106,109 ****
--- 106,110 ----
  int nunits = 0;
  int unitv_size = 8;
+ int verbose = FALSE;
  unsigned long lower_warn_lim[MAX_OIDS];
  unsigned long upper_warn_lim[MAX_OIDS];
***************
*** 145,152 ****
  
  	/* create the command line to execute */
! 	asprintf
! 		(&command_line,
! 		 "%s -p %s -m ALL -v 1 %s -c %s %s",
! 		 PATH_TO_SNMPGET, port, server_address, community, oid);
  
  	/* run the command */
--- 146,153 ----
  
  	/* create the command line to execute */
! 	asprintf (&command_line, "%s -p %s -m ALL -v 1 %s -c %s %s",
! 	          PATH_TO_SNMPGET, port, server_address, community, oid);
! 	if (verbose)
! 		printf ("%s\n", command_line);
  
  	/* run the command */
***************
*** 162,167 ****
  	}
  
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
! 		output = strscat (output, input_buffer);
  
  	ptr = output;
--- 163,172 ----
  	}
  
+ 	asprintf (&output, "");
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
! 		asprintf (&output, "%s%s", output, input_buffer);
! 
! 	if (verbose)
! 		printf ("%s\n", output);
  
  	ptr = output;
***************
*** 265,277 ****
  
  		if (nlabels > 1 && i < nlabels && labels[i] != NULL)
! 			asprintf
! 				(&outbuff,
! 				 "%s%s%s %s%s%s",
! 				 outbuff,
! 				 (i == 0) ? " " : output_delim,
! 				 labels[i], mark (iresult), show, mark (iresult));
  		else
! 			asprintf (&outbuff, "%s%s%s%s%s", outbuff,
! 				 (i == 0) ? " " : output_delim, mark (iresult), show, mark (iresult));
  
  		if (nunits > 0 && i < nunits)
--- 270,279 ----
  
  		if (nlabels > 1 && i < nlabels && labels[i] != NULL)
! 			asprintf (&outbuff, "%s%s%s %s%s%s", outbuff,
! 			          (i == 0) ? " " : output_delim,
! 			          labels[i], mark (iresult), show, mark (iresult));
  		else
! 			asprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim,
! 			          mark (iresult), show, mark (iresult));
  
  		if (nunits > 0 && i < nunits)
***************
*** 311,360 ****
  process_arguments (int argc, char **argv)
  {
- 	int c;
- 
- 	if (argc < 2)
- 		return ERROR;
- 
- 	for (c = 1; c < argc; c++) {
- 		if (strcmp ("-to", argv[c]) == 0)
- 			strcpy (argv[c], "-t");
- 		if (strcmp ("-wv", argv[c]) == 0)
- 			strcpy (argv[c], "-w");
- 		if (strcmp ("-cv", argv[c]) == 0)
- 			strcpy (argv[c], "-c");
- 	}
- 
- 	c = 0;
- 	while (c += (call_getopt (argc - c, &argv[c]))) {
- 		if (argc <= c)
- 			break;
- 		if (server_address == NULL)
- 			server_address = strscpy (NULL, argv[c]);
- 	}
- 
- 	if (community == NULL)
- 		community = strscpy (NULL, "public");
- 
- 	if (delimiter == NULL)
- 		delimiter = strscpy (NULL, DEFAULT_DELIMITER);
- 
- 	if (output_delim == NULL)
- 		output_delim = strscpy (NULL, DEFAULT_OUTPUT_DELIMITER);
- 
- 	if (label == NULL)
- 		label = strscpy (NULL, "SNMP");
- 
- 	if (units == NULL)
- 		units = strscpy (NULL, "");
- 
- 	if (port == NULL)
- 		port = strscpy(NULL,"161");
- 
- 	return c;
- }
- 
- int
- call_getopt (int argc, char **argv)
- {
  	char *ptr;
  	int c, i = 1;
--- 313,316 ----
***************
*** 364,373 ****
  	int option_index = 0;
  	static struct option long_options[] = {
! 		{"help", no_argument, 0, 'h'},
! 		{"version", no_argument, 0, 'V'},
! 		{"timeout", required_argument, 0, 't'},
! 		{"critical", required_argument, 0, 'c'},
! 		{"warning", required_argument, 0, 'w'},
! 		{"hostname", required_argument, 0, 'H'},
  		{"community", required_argument, 0, 'C'},
  		{"oid", required_argument, 0, 'o'},
--- 320,324 ----
  	int option_index = 0;
  	static struct option long_options[] = {
! 		STD_LONG_OPTS,
  		{"community", required_argument, 0, 'C'},
  		{"oid", required_argument, 0, 'o'},
***************
*** 386,389 ****
--- 337,356 ----
  #endif
  
+ 	if (argc < 2)
+ 		return ERROR;
+ 
+ 	/* reverse compatibility for very old non-POSIX usage forms */
+ 	for (c = 1; c < argc; c++) {
+ 		if (strcmp ("-to", argv[c]) == 0)
+ 			strcpy (argv[c], "-t");
+ 		if (strcmp ("-wv", argv[c]) == 0)
+ 			strcpy (argv[c], "-w");
+ 		if (strcmp ("-cv", argv[c]) == 0)
+ 			strcpy (argv[c], "-c");
+ 	}
+ 
+ 	/* initialize some args */
+ 	asprintf (&oid, "");
+ 
  	while (1) {
  #ifdef HAVE_GETOPT_H
***************
*** 398,420 ****
  			break;
  
- 		i++;
- 		switch (c) {
- 		case 't':
- 		case 'c':
- 		case 'w':
- 		case 'H':
- 		case 'C':
- 		case 'o':
- 		case 'd':
- 		case 'D':
- 		case 's':
- 		case 'R':
- 		case 'r':
- 		case 'l':
- 		case 'u':
- 		case 'p':
- 			i++;
- 		}
- 
  		switch (c) {
  		case '?':									/* help */
--- 365,368 ----
***************
*** 428,431 ****
--- 376,382 ----
  			print_revision (my_basename (argv[0]), "$Revision$");
  			exit (STATE_OK);
+ 		case 'v': /* verbose */
+ 			verbose = TRUE;
+ 			break;
  		case 't':									/* timeout period */
  			if (!is_integer (optarg)) {
***************
*** 473,481 ****
  		case 'o':									/* object identifier */
  			for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
! 				ptr[0] = ' ';
! 			strncpy (oid, optarg, sizeof (oid) - 1);
! 			oid[sizeof (oid) - 1] = 0;
  			for (ptr = optarg, j = 1; (ptr = index (ptr, ' ')); ptr++)
! 				j++;
  			break;
  		case 'd':									/* delimiter */
--- 424,431 ----
  		case 'o':									/* object identifier */
  			for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
! 				ptr[0] = ' '; /* relpace comma with space */
  			for (ptr = optarg, j = 1; (ptr = index (ptr, ' ')); ptr++)
! 				j++; /* count OIDs */
! 			asprintf (&oid, "%s %s", oid, optarg);
  			break;
  		case 'd':									/* delimiter */
***************
*** 579,582 ****
--- 529,555 ----
  		}
  	}
+ 
+ 	c = optind;
+ 	if (server_address == NULL)
+ 		server_address = strscpy (NULL, argv[c++]);
+ 
+ 	if (community == NULL)
+ 		community = strscpy (NULL, "public");
+ 
+ 	if (delimiter == NULL)
+ 		delimiter = strscpy (NULL, DEFAULT_DELIMITER);
+ 
+ 	if (output_delim == NULL)
+ 		output_delim = strscpy (NULL, DEFAULT_OUTPUT_DELIMITER);
+ 
+ 	if (label == NULL)
+ 		label = strscpy (NULL, "SNMP");
+ 
+ 	if (units == NULL)
+ 		units = strscpy (NULL, "");
+ 
+ 	if (port == NULL)
+ 		port = strscpy(NULL,"161");
+ 
  	return i;
  }





More information about the Commits mailing list