summaryrefslogtreecommitdiffstats
path: root/plugins/check_nt.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2004-08-23 21:58:09 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2004-08-23 21:58:09 +0000
commitc68da24cf2a3ea3c3a57d7c3b4a16bbabb3a0c09 (patch)
treede24252f30fef60c2a9d8d1e5fc14be082b78318 /plugins/check_nt.c
parent33cffe8f87e58de3e38e9146584fb05371eb7de3 (diff)
downloadmonitoring-plugins-c68da24cf2a3ea3c3a57d7c3b4a16bbabb3a0c09.tar.gz
Restore divisor for memory size reported by Windows. Also, implements warning
and critical levels for performance counters. (Paulo Afonso Graner Fessel) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@892 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r--plugins/check_nt.c148
1 files changed, 111 insertions, 37 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index ef0a66b5..25645eaa 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -81,7 +81,8 @@ int main(int argc, char **argv){
81 char *perfdata=NULL; 81 char *perfdata=NULL;
82 char *temp_string=NULL; 82 char *temp_string=NULL;
83 char *temp_string_perf=NULL; 83 char *temp_string_perf=NULL;
84 char *description=NULL; 84 char *description=NULL,*counter_unit = NULL;
85 char *minval = NULL, *maxval = NULL, *errcvt = NULL;
85 86
86 double total_disk_space=0; 87 double total_disk_space=0;
87 double free_disk_space=0; 88 double free_disk_space=0;
@@ -90,6 +91,7 @@ int main(int argc, char **argv){
90 double critical_used_space=0; 91 double critical_used_space=0;
91 double mem_commitLimit=0; 92 double mem_commitLimit=0;
92 double mem_commitByte=0; 93 double mem_commitByte=0;
94 double fminval = 0, fmaxval = 0;
93 unsigned long utilization; 95 unsigned long utilization;
94 unsigned long uptime; 96 unsigned long uptime;
95 unsigned long age_in_minutes; 97 unsigned long age_in_minutes;
@@ -99,6 +101,9 @@ int main(int argc, char **argv){
99 int uphours=0; 101 int uphours=0;
100 int upminutes=0; 102 int upminutes=0;
101 103
104 int isPercent = FALSE;
105 int allRight = FALSE;
106
102 setlocale (LC_ALL, ""); 107 setlocale (LC_ALL, "");
103 bindtextdomain (PACKAGE, LOCALEDIR); 108 bindtextdomain (PACKAGE, LOCALEDIR);
104 textdomain (PACKAGE); 109 textdomain (PACKAGE);
@@ -252,12 +257,13 @@ int main(int argc, char **argv){
252 warning_used_space = ((float)warning_value / 100) * mem_commitLimit; 257 warning_used_space = ((float)warning_value / 100) * mem_commitLimit;
253 critical_used_space = ((float)critical_value / 100) * mem_commitLimit; 258 critical_used_space = ((float)critical_value / 100) * mem_commitLimit;
254 259
255 // Changed divisor in following line from 1048567 to 3044515 to accurately reflect memory size 260 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
261 which equals RAM + Pagefiles. */
256 asprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"), 262 asprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"),
257 mem_commitLimit / 3044515, mem_commitByte / 3044515, percent_used_space, 263 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,
258 (mem_commitLimit - mem_commitByte) / 3044515, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100); 264 (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
259 asprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 3044515, 265 asprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567,
260 warning_used_space / 3044515, critical_used_space / 3044515, mem_commitLimit / 3044515); 266 warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);
261 267
262 return_code=STATE_OK; 268 return_code=STATE_OK;
263 if(check_critical_value==TRUE && percent_used_space >= critical_value) 269 if(check_critical_value==TRUE && percent_used_space >= critical_value)
@@ -269,40 +275,108 @@ int main(int argc, char **argv){
269 275
270 case CHECK_COUNTER: 276 case CHECK_COUNTER:
271 277
272 if (value_list==NULL)
273 output_message = strdup (_("No counter specified"));
274 else {
275 preparelist(value_list); /* replace , between services with & to send the request */
276 asprintf(&send_buffer,"%s&8&%s", req_password,value_list);
277 fetch_data (server_address, server_port, send_buffer);
278 strtok(value_list,"&"); /* burn the first parameters */
279 description = strtok(NULL,"&");
280 counter_value = atof(recv_buffer);
281 278
282 if (description == NULL) 279 /*
283 asprintf(&output_message, "%.f", counter_value); 280 CHECK_COUNTER has been modified to provide extensive perfdata information.
284 else 281 In order to do this, some modifications have been done to the code
285 asprintf(&output_message,"%s = %.f", description, counter_value); 282 and some constraints have been introduced.
286 asprintf(&perfdata,"'%s'=%.f", description, counter_value); 283
287 284 1) For the sake of simplicity of the code, perfdata information will only be
288 if (critical_value > warning_value) { /* Normal thresholds */ 285 provided when the "description" field is added.
289 if(check_critical_value==TRUE && counter_value >= critical_value) 286
290 return_code=STATE_CRITICAL; 287 2) If the counter you're going to measure is percent-based, the code will detect
291 else if (check_warning_value==TRUE && counter_value >= warning_value) 288 the percent sign in its name and will attribute minimum (0%) and maximum (100%)
292 return_code=STATE_WARNING; 289 values automagically, as well the ¨%" sign to graph units.
293 else 290
294 return_code=STATE_OK; 291 3) OTOH, if the counter is "absolute", you'll have to provide the following
295 } 292 the counter unit - that is, the dimensions of the counter you're getting. Examples:
296 else { /* inverse thresholds */ 293 pages/s, packets transferred, etc.
297 return_code=STATE_OK; 294
298 if(check_critical_value==TRUE && counter_value <= critical_value) 295 4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory,
299 return_code=STATE_CRITICAL; 296 but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise.
300 else if (check_warning_value==TRUE && counter_value <= warning_value) 297 strange things will happen when you make graphs of your data.
301 return_code=STATE_WARNING; 298 */
302 } 299
300 if (value_list == NULL)
301 output_message = strdup (_("No counter specified"));
302 else
303 {
304 preparelist (value_list); /* replace , between services with & to send the request */
305 isPercent = (strchr (value_list, '%') != NULL);
306
307 strtok (value_list, "&"); /* burn the first parameters */
308 description = strtok (NULL, "&");
309 counter_unit = strtok (NULL, "&");
310 asprintf (&send_buffer, "%s&8&%s", req_password, value_list);
311 fetch_data (server_address, server_port, send_buffer);
312 counter_value = atof (recv_buffer);
313
314
315 if (description == NULL)
316 asprintf (&output_message, "%.f", counter_value);
317 else if (isPercent)
318 {
319 counter_unit = strdup (_("%"));
320 allRight = TRUE;
321 }
322
323 if ((counter_unit != NULL) && (!allRight))
324 {
325 minval = strtok (NULL, "&");
326 maxval = strtok (NULL, "&");
327
328 /* All parameters specified. Let's check the numbers */
329
330 fminval = (minval != NULL) ? strtod (minval, &errcvt) : -1;
331 fmaxval = (minval != NULL) ? strtod (maxval, &errcvt) : -1;
332
333 if ((fminval == 0) && (minval == errcvt))
334 output_message = strdup (_("Minimum value contains non-numbers"));
335 else
336 {
337 if ((fmaxval == 0) && (maxval == errcvt))
338 output_message = strdup (_("Maximum value contains non-numbers"));
339 else
340 allRight = TRUE; /* Everything is OK. */
341
342 }
343 }
344 else if ((counter_unit == NULL) && (description != NULL))
345 output_message = strdup (_("No unit counter specified"));
346
347 if (allRight)
348 {
349 /* Let's format the output string, finally... */
350
351 asprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
352 output_message = strcat (output_message, "|");
353 output_message = strcat (output_message,
354 fperfdata (description, counter_value, counter_unit,
355 1, warning_value, 1, critical_value,
356 (!(isPercent) && (minval != NULL)), fminval,
357 (!(isPercent) && (minval != NULL)), fmaxval));
358 }
303 } 359 }
304 break;
305 360
361 if (critical_value > warning_value)
362 { /* Normal thresholds */
363 if (check_critical_value == TRUE && counter_value >= critical_value)
364 return_code = STATE_CRITICAL;
365 else if (check_warning_value == TRUE && counter_value >= warning_value)
366 return_code = STATE_WARNING;
367 else
368 return_code = STATE_OK;
369 }
370 else
371 { /* inverse thresholds */
372 return_code = STATE_OK;
373 if (check_critical_value == TRUE && counter_value <= critical_value)
374 return_code = STATE_CRITICAL;
375 else if (check_warning_value == TRUE && counter_value <= warning_value)
376 return_code = STATE_WARNING;
377 }
378 break;
379
306 case CHECK_FILEAGE: 380 case CHECK_FILEAGE:
307 381
308 if (value_list==NULL) 382 if (value_list==NULL)