[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ups.c,1.4,1.5

Karl DeBisschop kdebisschop at users.sourceforge.net
Fri Nov 22 02:53:05 CET 2002


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

Modified Files:
	check_ups.c 
Log Message:
add replace battery condition, replace unchecked strcat calls with asprintf (I do not think buffer overflow was possible here, but lets be consistent)

Index: check_ups.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ups.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** check_ups.c	12 Nov 2002 11:26:01 -0000	1.4
--- check_ups.c	22 Nov 2002 10:52:18 -0000	1.5
***************
*** 32,36 ****
  * Kroll's "Smart UPS Tools" be installed on the remote host.  If you
  * don't have the package installed on your system, you can download
! * it from http://www.exploits.org/~rkroll/smartupstools
  *
  * License Information:
--- 32,36 ----
  * Kroll's "Smart UPS Tools" be installed on the remote host.  If you
  * don't have the package installed on your system, you can download
! * it from http://www.exploits.org/nut
  *
  * License Information:
***************
*** 67,84 ****
  #define PORT	3305
  
! #define UPS_NONE	0							/* no supported options */
! #define UPS_UTILITY	1						/* supports utility line voltage */
! #define UPS_BATTPCT	2						/* supports percent battery remaining */
! #define UPS_STATUS	4						/* supports UPS status */
! #define UPS_TEMP	8							/* supports UPS temperature */
! #define UPS_LOADPCT	16					/* supports load percent */
! 
! #define UPSSTATUS_NONE		0
! #define UPSSTATUS_OFF		1
! #define UPSSTATUS_OL		2
! #define UPSSTATUS_OB		4
! #define UPSSTATUS_LB		8
! #define UPSSTATUS_CAL		16
! #define UPSSTATUS_UNKOWN	32
  
  int server_port = PORT;
--- 67,85 ----
  #define PORT	3305
  
! #define UPS_NONE     0   /* no supported options */
! #define UPS_UTILITY  1   /* supports utility line voltage */
! #define UPS_BATTPCT  2   /* supports percent battery remaining */
! #define UPS_STATUS   4   /* supports UPS status */
! #define UPS_TEMP     8   /* supports UPS temperature */
! #define UPS_LOADPCT	16   /* supports load percent */
! 
! #define UPSSTATUS_NONE     0
! #define UPSSTATUS_OFF      1
! #define UPSSTATUS_OL       2
! #define UPSSTATUS_OB       4
! #define UPSSTATUS_LB       8
! #define UPSSTATUS_CAL     16
! #define UPSSTATUS_RB      32  /*Replace Battery */
! #define UPSSTATUS_UNKOWN  64
  
  int server_port = PORT;
***************
*** 97,101 ****
  double ups_load_percent = 0.0L;
  double ups_temperature = 0.0L;
! char ups_status[MAX_INPUT_BUFFER] = "N/A";
  
  int determine_status (void);
--- 98,102 ----
  double ups_load_percent = 0.0L;
  double ups_temperature = 0.0L;
! char *ups_status = "N/A";
  
  int determine_status (void);
***************
*** 112,116 ****
  {
  	int result = STATE_OK;
! 	char output_message[MAX_INPUT_BUFFER];
  	char temp_buffer[MAX_INPUT_BUFFER];
  
--- 113,117 ----
  {
  	int result = STATE_OK;
! 	char *message;
  	char temp_buffer[MAX_INPUT_BUFFER];
  
***************
*** 135,167 ****
  		if (determine_status () != OK)
  			return STATE_CRITICAL;
! 		ups_status[0] = 0;
  		result = STATE_OK;
  
  		if (status & UPSSTATUS_OFF) {
! 			strcpy (ups_status, "Off");
  			result = STATE_CRITICAL;
  		}
  		else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) ==
  						 (UPSSTATUS_OB | UPSSTATUS_LB)) {
! 			strcpy (ups_status, "On Battery, Low Battery");
  			result = STATE_CRITICAL;
  		}
  		else {
  			if (status & UPSSTATUS_OL) {
! 				strcat (ups_status, "Online");
  			}
  			if (status & UPSSTATUS_OB) {
! 				strcat (ups_status, "On Battery");
  				result = STATE_WARNING;
  			}
  			if (status & UPSSTATUS_LB) {
! 				strcat (ups_status, ", Low Battery");
  				result = STATE_WARNING;
  			}
  			if (status & UPSSTATUS_CAL) {
! 				strcat (ups_status, ", Calibrating");
  			}
  			if (status & UPSSTATUS_UNKOWN) {
! 				strcat (ups_status, ", Unknown");
  			}
  		}
--- 136,172 ----
  		if (determine_status () != OK)
  			return STATE_CRITICAL;
! 		asprintf (&ups_status, "");
  		result = STATE_OK;
  
  		if (status & UPSSTATUS_OFF) {
! 			asprintf (&ups_status, "Off");
  			result = STATE_CRITICAL;
  		}
  		else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) ==
  						 (UPSSTATUS_OB | UPSSTATUS_LB)) {
! 			asprintf (&ups_status, "On Battery, Low Battery");
  			result = STATE_CRITICAL;
  		}
  		else {
  			if (status & UPSSTATUS_OL) {
! 				asprintf (&ups_status, "%s%s", ups_status, "Online");
  			}
  			if (status & UPSSTATUS_OB) {
! 				asprintf (&ups_status, "%s%s", ups_status, "On Battery");
  				result = STATE_WARNING;
  			}
  			if (status & UPSSTATUS_LB) {
! 				asprintf (&ups_status, "%s%s", ups_status, ", Low Battery");
  				result = STATE_WARNING;
  			}
  			if (status & UPSSTATUS_CAL) {
! 				asprintf (&ups_status, "%s%s", ups_status, ", Calibrating");
! 			}
! 			if (status & UPSSTATUS_RB) {
! 				asprintf (&ups_status, "%s%s", ups_status, ", Replace Battery");
! 				result = STATE_WARNING;
  			}
  			if (status & UPSSTATUS_UNKOWN) {
! 				asprintf (&ups_status, "%s%s", ups_status, ", Unknown");
  			}
  		}
***************
*** 249,282 ****
  
  
! 	sprintf (output_message, "UPS %s - ",
! 					 (result == STATE_OK) ? "ok" : "problem");
  
! 	if (supported_options & UPS_STATUS) {
! 		sprintf (temp_buffer, "Status=%s ", ups_status);
! 		strcat (output_message, temp_buffer);
! 	}
! 	if (supported_options & UPS_UTILITY) {
! 		sprintf (temp_buffer, "Utility=%3.1fV ", ups_utility_voltage);
! 		strcat (output_message, temp_buffer);
! 	}
! 	if (supported_options & UPS_BATTPCT) {
! 		sprintf (temp_buffer, "Batt=%3.1f%% ", ups_battery_percent);
! 		strcat (output_message, temp_buffer);
! 	}
! 	if (supported_options & UPS_LOADPCT) {
! 		sprintf (temp_buffer, "Load=%3.1f%% ", ups_load_percent);
! 		strcat (output_message, temp_buffer);
! 	}
! 	if (supported_options & UPS_TEMP) {
! 		sprintf (temp_buffer, "Temp=%3.1fF", ups_temperature);
! 		strcat (output_message, temp_buffer);
! 	}
! 	if (supported_options == UPS_NONE) {
! 		sprintf (temp_buffer,
! 						 "UPS does not appear to support any available options\n");
! 		strcat (output_message, temp_buffer);
! 	}
  
! 	printf ("%s\n", output_message);
  
  	return result;
--- 254,278 ----
  
  
! 	asprintf (&message, "UPS %s - ", (result == STATE_OK) ? "ok" : "problem");
  
! 	if (supported_options & UPS_STATUS)
! 		asprintf (&message, "%sStatus=%s ", message, ups_status);
! 
! 	if (supported_options & UPS_UTILITY)
! 		asprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage);
! 
! 	if (supported_options & UPS_BATTPCT)
! 		asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent);
! 
! 	if (supported_options & UPS_LOADPCT)
! 		asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent);
! 
! 	if (supported_options & UPS_TEMP)
! 		asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature);
! 
! 	if (supported_options == UPS_NONE)
! 		asprintf (&message, "UPS does not support any available options\n");
  
! 	printf ("%s\n", message);
  
  	return result;
***************
*** 314,317 ****
--- 310,315 ----
  		else if (!strcmp (ptr, "CAL"))
  			status |= UPSSTATUS_CAL;
+ 		else if (!strcmp (ptr, "RB"))
+ 			status |= UPSSTATUS_RB;
  		else
  			status |= UPSSTATUS_UNKOWN;





More information about the Commits mailing list