--- check_nt.c.original 2005-03-05 04:45:05.000000000 -0500 +++ check_nt.c 2005-04-23 08:35:43.000000000 -0400 @@ -282,111 +282,74 @@ break; case CHECK_COUNTER: - - - /* - CHECK_COUNTER has been modified to provide extensive perfdata information. - In order to do this, some modifications have been done to the code - and some constraints have been introduced. - - 1) For the sake of simplicity of the code, perfdata information will only be - provided when the "description" field is added. - - 2) If the counter you're going to measure is percent-based, the code will detect - the percent sign in its name and will attribute minimum (0%) and maximum (100%) - values automagically, as well the ¨%" sign to graph units. - - 3) OTOH, if the counter is "absolute", you'll have to provide the following - the counter unit - that is, the dimensions of the counter you're getting. Examples: - pages/s, packets transferred, etc. - - 4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory, - but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise. - strange things will happen when you make graphs of your data. - */ - - if (value_list == NULL) - output_message = strdup (_("No counter specified")); - else - { - preparelist (value_list); /* replace , between services with & to send the request */ - isPercent = (strchr (value_list, '%') != NULL); - - strtok (value_list, "&"); /* burn the first parameters */ - description = strtok (NULL, "&"); - counter_unit = strtok (NULL, "&"); - asprintf (&send_buffer, "%s&8&%s", req_password, value_list); - fetch_data (server_address, server_port, send_buffer); - counter_value = atof (recv_buffer); - - - if (description == NULL) - asprintf (&output_message, "%.f", counter_value); - else if (isPercent) - { - counter_unit = strdup ("%"); - allRight = TRUE; - } - - if ((counter_unit != NULL) && (!allRight)) - { - minval = strtok (NULL, "&"); - maxval = strtok (NULL, "&"); - - /* All parameters specified. Let's check the numbers */ - - fminval = (minval != NULL) ? strtod (minval, &errcvt) : -1; - fmaxval = (minval != NULL) ? strtod (maxval, &errcvt) : -1; - - if ((fminval == 0) && (minval == errcvt)) - output_message = strdup (_("Minimum value contains non-numbers")); - else - { - if ((fmaxval == 0) && (maxval == errcvt)) - output_message = strdup (_("Maximum value contains non-numbers")); - else - allRight = TRUE; /* Everything is OK. */ - - } - } - else if ((counter_unit == NULL) && (description != NULL)) - output_message = strdup (_("No unit counter specified")); - - if (allRight) - { - /* Let's format the output string, finally... */ - if (strstr(description, "%") == NULL) { - asprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit); - } else { - /* has formatting, will segv if wrong */ - asprintf (&output_message, description, counter_value); - } - asprintf (&output_message, "%s |", output_message); - asprintf (&output_message,"%s %s", output_message, - fperfdata (description, counter_value, - counter_unit, 1, warning_value, 1, critical_value, - (!(isPercent) && (minval != NULL)), fminval, - (!(isPercent) && (minval != NULL)), fmaxval)); - } - } - - if (critical_value > warning_value) - { /* Normal thresholds */ - if (check_critical_value == TRUE && counter_value >= critical_value) - return_code = STATE_CRITICAL; - else if (check_warning_value == TRUE && counter_value >= warning_value) - return_code = STATE_WARNING; - else - return_code = STATE_OK; - } - else - { /* inverse thresholds */ - return_code = STATE_OK; - if (check_critical_value == TRUE && counter_value <= critical_value) - return_code = STATE_CRITICAL; - else if (check_warning_value == TRUE && counter_value <= warning_value) - return_code = STATE_WARNING; - } + /* + * Check_Counter has been rewriten for NC_Net now it processes the pref data in + * a more consistent way to the Nagios plug-in development guidelines. + * 1) if no Units of mesurement use a 0 (zero) for the UOM in the check + * and the units will be omited from the output. + * 2) it will do MIN without a MAX + * 3) still processes custom min and max even if it is % + * 4) % has a default of min 0, max 100 + * 5) -w and -c are no longer causing a seg fault. old code said to always + * process both for perf data, but it should have checked that they were in use. + * 6) the description is only a label for perf data not a formatter... + ****************************************************************************/ + if (value_list == NULL) + output_message = strdup (_("No counter specified")); + else { + preparelist (value_list); /* replace , between services with & to send the request */ + + temp_string = strtok (value_list, "&"); + isPercent = (strchr (temp_string, '%') != NULL); + description = strtok (NULL, "&"); + counter_unit = strtok (NULL, "&"); + asprintf (&send_buffer, "%s&8&%s", req_password, value_list); + fetch_data (server_address, server_port, send_buffer); + counter_value = atof (recv_buffer); + if (isPercent) counter_unit = strdup ("%"); + if ( description != NULL && counter_unit == NULL ) + counter_unit = strdup ( "0" ); + if ( counter_unit != NULL && description != NULL) + { + if ( counter_unit[0] == '0' ) counter_unit[0] = '\0'; + minval = strtok (NULL, "&"); + maxval = strtok (NULL, "&"); + if ( minval == NULL && isPercent ) asprintf(&minval,"0"); + if ( minval != NULL ) fminval = strtod ( minval, NULL ) ; + if ( maxval == NULL && isPercent ) asprintf(&maxval,"100"); + if ( maxval != NULL ) fmaxval = strtod (maxval, NULL); + allRight = TRUE; + /* Let's format the output string, finally... */ + asprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit); + asprintf (&output_message,"%s | %s", output_message, + fperfdata (description, counter_value, + counter_unit, check_warning_value, warning_value, + check_critical_value, critical_value, + (minval != NULL), fminval, + (maxval != NULL), fmaxval )); + } + else if (isPercent) + asprintf(&output_message, "%s = %.2f %%",temp_string,counter_value); + else + asprintf(&output_message, "%s = %.2f",temp_string,counter_value); + } + if (critical_value > warning_value) + { /* Normal thresholds */ + if (check_critical_value == TRUE && counter_value >= critical_value) + return_code = STATE_CRITICAL; + else if (check_warning_value == TRUE && counter_value >= warning_value) + return_code = STATE_WARNING; + else + return_code = STATE_OK; + } + else + { /* inverse thresholds */ + return_code = STATE_OK; + if (check_critical_value == TRUE && counter_value <= critical_value) + return_code = STATE_CRITICAL; + else if (check_warning_value == TRUE && counter_value <= warning_value) + return_code = STATE_WARNING; + } break; case CHECK_FILEAGE: @@ -394,7 +357,7 @@ if (value_list==NULL) output_message = strdup (_("No counter specified")); else { - preparelist(value_list); /* replace , between services with & to send the request */ + preparelist(value_list); /* replace , between services with & to send the request */ asprintf(&send_buffer,"%s&9&%s", req_password,value_list); fetch_data (server_address, server_port, send_buffer); age_in_minutes = atoi(strtok(recv_buffer,"&")); @@ -672,13 +635,32 @@ printf (_("\ COUNTER = Check any performance counter of Windows NT/2000.\n\ Request a -l parameters with the following syntax:\n\ - -l \"\\\\\\\\counter\",\"\n\ - The parameter is optional and \n\ - is given to a printf output command which requires a float parameter.\n\ - If does not include \"%%\", it is used as a label.\n\ + -l \"\\\\\\\\counter\"[,\"