summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c49
1 files changed, 22 insertions, 27 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 03f0949..91cc097 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -134,7 +134,6 @@ char *path;
134char *exclude_device; 134char *exclude_device;
135char *units; 135char *units;
136uintmax_t mult = 1024 * 1024; 136uintmax_t mult = 1024 * 1024;
137int verbose = 0;
138int erronly = FALSE; 137int erronly = FALSE;
139int display_mntp = FALSE; 138int display_mntp = FALSE;
140int exact_match = FALSE; 139int exact_match = FALSE;
@@ -178,7 +177,8 @@ main (int argc, char **argv)
178 struct name_list *seen = NULL; 177 struct name_list *seen = NULL;
179 struct stat *stat_buf; 178 struct stat *stat_buf;
180 179
181 preamble = strdup (" - free space:"); 180 np_set_mynames(argv[0], "DISK");
181 preamble = strdup (" free space:");
182 output = strdup (""); 182 output = strdup ("");
183 details = strdup (""); 183 details = strdup ("");
184 perf = strdup (""); 184 perf = strdup ("");
@@ -228,12 +228,12 @@ main (int argc, char **argv)
228 /* Process for every path in list */ 228 /* Process for every path in list */
229 for (path = path_select_list; path; path=path->name_next) { 229 for (path = path_select_list; path; path=path->name_next) {
230 230
231 if (verbose > 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL) 231 if (path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL)
232 printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end, 232 np_debug(4, "Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
233 path->freespace_percent->critical->end); 233 path->freespace_percent->critical->end);
234 234
235 if (verbose > 3 && path->group != NULL) 235 if (path->group != NULL)
236 printf("Group of %s: %s\n",path->name,path->group); 236 np_debug(4, "Group of %s: %s\n",path->name,path->group);
237 237
238 /* reset disk result */ 238 /* reset disk result */
239 disk_result = STATE_UNKNOWN; 239 disk_result = STATE_UNKNOWN;
@@ -270,8 +270,7 @@ main (int argc, char **argv)
270 fsp.fsu_files += tmpfsp.fsu_files; /* Total file nodes. */ 270 fsp.fsu_files += tmpfsp.fsu_files; /* Total file nodes. */
271 fsp.fsu_ffree += tmpfsp.fsu_ffree; /* Free file nodes. */ 271 fsp.fsu_ffree += tmpfsp.fsu_ffree; /* Free file nodes. */
272 272
273 if (verbose > 3) 273 np_debug(4, "Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
274 printf("Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
275 /* printf("Group %s: add %u blocks (%s)\n", temp_list->name); // path->group, tmpfsp.fsu_bavail, temp_list->name); */ 274 /* printf("Group %s: add %u blocks (%s)\n", temp_list->name); // path->group, tmpfsp.fsu_bavail, temp_list->name); */
276 275
277 np_add_name(&seen, temp_list->best_match->me_mountdir); 276 np_add_name(&seen, temp_list->best_match->me_mountdir);
@@ -318,35 +317,33 @@ main (int argc, char **argv)
318 dused_inodes_percent = calculate_percent(fsp.fsu_files - fsp.fsu_ffree, fsp.fsu_files); 317 dused_inodes_percent = calculate_percent(fsp.fsu_files - fsp.fsu_ffree, fsp.fsu_files);
319 dfree_inodes_percent = 100 - dused_inodes_percent; 318 dfree_inodes_percent = 100 - dused_inodes_percent;
320 319
321 if (verbose >= 3) { 320 np_debug(3, "For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g\n",
322 printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g\n",
323 me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent); 321 me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent);
324 }
325 322
326 /* Threshold comparisons */ 323 /* Threshold comparisons */
327 324
328 temp_result = get_status(dfree_units, path->freespace_units); 325 temp_result = get_status(dfree_units, path->freespace_units);
329 if (verbose >=3) printf("Freespace_units result=%d\n", temp_result); 326 np_debug(3, "Freespace_units result=%d\n", temp_result);
330 disk_result = max_state( disk_result, temp_result ); 327 disk_result = max_state( disk_result, temp_result );
331 328
332 temp_result = get_status(dfree_pct, path->freespace_percent); 329 temp_result = get_status(dfree_pct, path->freespace_percent);
333 if (verbose >=3) printf("Freespace%% result=%d\n", temp_result); 330 np_debug(3, "Freespace%% result=%d\n", temp_result);
334 disk_result = max_state( disk_result, temp_result ); 331 disk_result = max_state( disk_result, temp_result );
335 332
336 temp_result = get_status(dused_units, path->usedspace_units); 333 temp_result = get_status(dused_units, path->usedspace_units);
337 if (verbose >=3) printf("Usedspace_units result=%d\n", temp_result); 334 np_debug(3, "Usedspace_units result=%d\n", temp_result);
338 disk_result = max_state( disk_result, temp_result ); 335 disk_result = max_state( disk_result, temp_result );
339 336
340 temp_result = get_status(dused_pct, path->usedspace_percent); 337 temp_result = get_status(dused_pct, path->usedspace_percent);
341 if (verbose >=3) printf("Usedspace_percent result=%d\n", temp_result); 338 np_debug(3, "Usedspace_percent result=%d\n", temp_result);
342 disk_result = max_state( disk_result, temp_result ); 339 disk_result = max_state( disk_result, temp_result );
343 340
344 temp_result = get_status(dused_inodes_percent, path->usedinodes_percent); 341 temp_result = get_status(dused_inodes_percent, path->usedinodes_percent);
345 if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result); 342 np_debug(3, "Usedinodes_percent result=%d\n", temp_result);
346 disk_result = max_state( disk_result, temp_result ); 343 disk_result = max_state( disk_result, temp_result );
347 344
348 temp_result = get_status(dfree_inodes_percent, path->freeinodes_percent); 345 temp_result = get_status(dfree_inodes_percent, path->freeinodes_percent);
349 if (verbose >=3) printf("Freeinodes_percent result=%d\n", temp_result); 346 np_debug(3, "Freeinodes_percent result=%d\n", temp_result);
350 disk_result = max_state( disk_result, temp_result ); 347 disk_result = max_state( disk_result, temp_result );
351 348
352 result = max_state(result, disk_result); 349 result = max_state(result, disk_result);
@@ -381,10 +378,10 @@ main (int argc, char **argv)
381 TRUE, 0, 378 TRUE, 0,
382 TRUE, dtotal_units)); 379 TRUE, dtotal_units));
383 380
384 if (disk_result==STATE_OK && erronly && !verbose) 381 if (disk_result==STATE_OK && erronly && np_get_verbosity()<=0)
385 continue; 382 continue;
386 383
387 if (disk_result!=STATE_OK || verbose>=0) { 384 if (disk_result!=STATE_OK || np_get_verbosity()>=0) {
388 asprintf (&output, "%s %s %.0f %s (%.0f%%", 385 asprintf (&output, "%s %s %.0f %s (%.0f%%",
389 output, 386 output,
390 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 387 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
@@ -410,12 +407,11 @@ main (int argc, char **argv)
410 407
411 } 408 }
412 409
413 if (verbose > 2) 410 if (np_get_verbosity()>=3)
414 asprintf (&output, "%s%s", output, details); 411 asprintf (&output, "%s%s", output, details);
415 412
416 413
417 printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf); 414 np_die(result, "%s%s|%s", (erronly && result==STATE_OK) ? "" : preamble, output, perf);
418 return result;
419} 415}
420 416
421 417
@@ -635,10 +631,10 @@ process_arguments (int argc, char **argv)
635 np_add_name(&fs_exclude_list, optarg); 631 np_add_name(&fs_exclude_list, optarg);
636 break; 632 break;
637 case 'v': /* verbose */ 633 case 'v': /* verbose */
638 verbose++; 634 np_increase_verbosity(1);
639 break; 635 break;
640 case 'q': /* verbose */ 636 case 'q': /* verbose */
641 verbose--; 637 np_decrease_verbosity(1);
642 break; 638 break;
643 case 'e': 639 case 'e':
644 erronly = TRUE; 640 erronly = TRUE;
@@ -670,8 +666,7 @@ process_arguments (int argc, char **argv)
670 for (me = mount_list; me; me = me->me_next) { 666 for (me = mount_list; me; me = me->me_next) {
671 if (np_regex_match_mount_entry(me, &re)) { 667 if (np_regex_match_mount_entry(me, &re)) {
672 fnd = true; 668 fnd = true;
673 if (verbose > 3) 669 np_debug(4, "%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
674 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
675 670
676 /* add parameter if not found. overwrite thresholds if path has already been added */ 671 /* add parameter if not found. overwrite thresholds if path has already been added */
677 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) { 672 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {