[Nagiosplug-checkins] CVS: nagiosplug/plugins check_ups.c,1.11,1.12

Karl DeBisschop kdebisschop at users.sourceforge.net
Sun Nov 16 23:20:29 CET 2003


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

Modified Files:
	check_ups.c 
Log Message:
add perfdata

Index: check_ups.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ups.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** check_ups.c	22 Aug 2003 06:22:38 -0000	1.11
--- check_ups.c	17 Nov 2003 07:19:17 -0000	1.12
***************
*** 53,58 ****
  double warning_value = 0.0;
  double critical_value = 0.0;
! int check_warning_value = FALSE;
! int check_critical_value = FALSE;
  int check_variable = UPS_NONE;
  int supported_options = UPS_NONE;
--- 53,58 ----
  double warning_value = 0.0;
  double critical_value = 0.0;
! int check_warn = FALSE;
! int check_crit = FALSE;
  int check_variable = UPS_NONE;
  int supported_options = UPS_NONE;
***************
*** 79,82 ****
--- 79,83 ----
  	int result = STATE_OK;
  	char *message;
+ 	char *data;
  	char temp_buffer[MAX_INPUT_BUFFER];
  	double ups_utility_deviation = 0.0;
***************
*** 141,144 ****
--- 142,146 ----
  			}
  		}
+ 		asprintf (&message, "%sStatus=%s ", message, ups_status);
  	}
  
***************
*** 150,153 ****
--- 152,156 ----
  
  		ups_utility_voltage = atof (temp_buffer);
+ 		asprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage);
  
  		if (ups_utility_voltage > 120.0)
***************
*** 157,165 ****
  
  		if (check_variable == UPS_UTILITY) {
! 			if (check_critical_value == TRUE
! 					&& ups_utility_deviation >= critical_value) result = STATE_CRITICAL;
! 			else if (check_warning_value == TRUE
! 							 && ups_utility_deviation >= warning_value
! 							 && result < STATE_WARNING) result = STATE_WARNING;
  		}
  	}
--- 160,178 ----
  
  		if (check_variable == UPS_UTILITY) {
! 			if (check_crit==TRUE && ups_utility_deviation>=critical_value) {
! 				result = STATE_CRITICAL;
! 			}
! 			else if (check_warn==TRUE && ups_utility_deviation>=warning_value) {
! 				result = max_state (result, STATE_WARNING);
! 			}
! 			asprintf (&data, "%s ",
! 			          perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV",
! 			                    check_warn, (long)(1000*warning_value),
! 			                    check_crit, (long)(1000*critical_value),
! 			                    TRUE, 0, FALSE, 0));
! 		} else {
! 			asprintf (&data, "%s ",
! 			          perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV",
! 			                    FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
  		}
  	}
***************
*** 172,182 ****
  
  		ups_battery_percent = atof (temp_buffer);
  
  		if (check_variable == UPS_BATTPCT) {
! 			if (check_critical_value == TRUE
! 					&& ups_battery_percent <= critical_value) result = STATE_CRITICAL;
! 			else if (check_warning_value == TRUE
! 							 && ups_battery_percent <= warning_value
! 							 && result < STATE_WARNING) result = STATE_WARNING;
  		}
  	}
--- 185,206 ----
  
  		ups_battery_percent = atof (temp_buffer);
+ 		asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent);
  
  		if (check_variable == UPS_BATTPCT) {
! 			if (check_crit==TRUE && ups_battery_percent <= critical_value) {
! 				result = STATE_CRITICAL;
! 			}
! 			else if (check_warn==TRUE && ups_battery_percent<=warning_value) {
! 				result = max_state (result, STATE_WARNING);
! 			}
! 			asprintf (&data, "%s ",
! 			          perfdata ("battery", (long)ups_battery_percent, "%",
! 			                    check_warn, (long)(1000*warning_value),
! 			                    check_crit, (long)(1000*critical_value),
! 			                    TRUE, 0, TRUE, 100));
! 		} else {
! 			asprintf (&data, "%s ",
! 			          perfdata ("battery", (long)ups_battery_percent, "%",
! 			                    FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100));
  		}
  	}
***************
*** 189,199 ****
  
  		ups_load_percent = atof (temp_buffer);
  
  		if (check_variable == UPS_LOADPCT) {
! 			if (check_critical_value == TRUE && ups_load_percent >= critical_value)
  				result = STATE_CRITICAL;
! 			else if (check_warning_value == TRUE
! 							 && ups_load_percent >= warning_value && result < STATE_WARNING)
! 				result = STATE_WARNING;
  		}
  	}
--- 213,234 ----
  
  		ups_load_percent = atof (temp_buffer);
+ 		asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent);
  
  		if (check_variable == UPS_LOADPCT) {
! 			if (check_crit==TRUE && ups_load_percent>=critical_value) {
  				result = STATE_CRITICAL;
! 			}
! 			else if (check_warn==TRUE && ups_load_percent>=warning_value) {
! 				result = max_state (result, STATE_WARNING);
! 			}
! 			asprintf (&data, "%s ",
! 			          perfdata ("load", (long)ups_load_percent, "%",
! 			                    check_warn, (long)(1000*warning_value),
! 			                    check_crit, (long)(1000*critical_value),
! 			                    TRUE, 0, TRUE, 100));
! 		} else {
! 			asprintf (&data, "%s ",
! 			          perfdata ("load", (long)ups_load_percent, "%",
! 			                    FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100));
  		}
  	}
***************
*** 206,249 ****
  
  		ups_temperature = (atof (temp_buffer) * 1.8) + 32;
  
  		if (check_variable == UPS_TEMP) {
! 			if (check_critical_value == TRUE && ups_temperature >= critical_value)
  				result = STATE_CRITICAL;
! 			else if (check_warning_value == TRUE && ups_temperature >= warning_value
! 							 && result < STATE_WARNING)
! 				result = STATE_WARNING;
  		}
  	}
  
  	/* if the UPS does not support any options we are looking for, report an error */
! 	if (supported_options == UPS_NONE)
  		result = STATE_CRITICAL;
  
  	/* reset timeout */
  	alarm (0);
  
! 
! 	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;
  }
--- 241,275 ----
  
  		ups_temperature = (atof (temp_buffer) * 1.8) + 32;
+ 		asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature);
  
  		if (check_variable == UPS_TEMP) {
! 			if (check_crit==TRUE && ups_temperature>=critical_value) {
  				result = STATE_CRITICAL;
! 			}
! 			else if (check_warn == TRUE && ups_temperature>=warning_value) {
! 				result = max_state (result, STATE_WARNING);
! 			}
! 			asprintf (&data, "%s ",
! 			          perfdata ("temp", (long)ups_temperature, "degF",
! 			                    check_warn, (long)(1000*warning_value),
! 			                    check_crit, (long)(1000*critical_value),
! 			                    TRUE, 0, FALSE, 0));
! 		} else {
! 			asprintf (&data, "%s ",
! 			          perfdata ("temp", (long)ups_temperature, "degF",
! 			                    FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
  		}
  	}
  
  	/* if the UPS does not support any options we are looking for, report an error */
! 	if (supported_options == UPS_NONE) {
  		result = STATE_CRITICAL;
+ 		asprintf (&message, "UPS does not support any available options\n");
+ 	}
  
  	/* reset timeout */
  	alarm (0);
  
! 	printf ("UPS %s - %s|%s\n", state_text(result), message, data);
  	return result;
  }
***************
*** 463,467 ****
  			if (is_intnonneg (optarg)) {
  				critical_value = atoi (optarg);
! 				check_critical_value = TRUE;
  			}
  			else {
--- 489,493 ----
  			if (is_intnonneg (optarg)) {
  				critical_value = atoi (optarg);
! 				check_crit = TRUE;
  			}
  			else {
***************
*** 472,476 ****
  			if (is_intnonneg (optarg)) {
  				warning_value = atoi (optarg);
! 				check_warning_value = TRUE;
  			}
  			else {
--- 498,502 ----
  			if (is_intnonneg (optarg)) {
  				warning_value = atoi (optarg);
! 				check_warn = TRUE;
  			}
  			else {





More information about the Commits mailing list