check_disk.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /******************************************************************************
  2. *
  3. * Nagios check_disk plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999-2006 nagios-plugins team
  7. *
  8. * Last Modified: $Date$
  9. *
  10. * Description:
  11. *
  12. * This file contains the check_disk plugin
  13. *
  14. * License Information:
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. * $Id$
  31. *
  32. *****************************************************************************/
  33. const char *progname = "check_disk";
  34. const char *program_name = "check_disk"; /* Required for coreutils libs */
  35. const char *revision = "$Revision$";
  36. const char *copyright = "1999-2006";
  37. const char *email = "nagiosplug-devel@lists.sourceforge.net";
  38. #include "common.h"
  39. #if HAVE_INTTYPES_H
  40. # include <inttypes.h>
  41. #endif
  42. #include <assert.h>
  43. #include "popen.h"
  44. #include "utils.h"
  45. #include <stdarg.h>
  46. #include "fsusage.h"
  47. #include "mountlist.h"
  48. #if HAVE_LIMITS_H
  49. # include <limits.h>
  50. #endif
  51. #include "utils_disk.h"
  52. /* If nonzero, show inode information. */
  53. static int inode_format;
  54. /* If nonzero, show even filesystems with zero size or
  55. uninteresting types. */
  56. static int show_all_fs = 1;
  57. /* If nonzero, show only local filesystems. */
  58. static int show_local_fs = 0;
  59. /* If positive, the units to use when printing sizes;
  60. if negative, the human-readable base. */
  61. /* static int output_block_size; */
  62. /* If nonzero, invoke the `sync' system call before getting any usage data.
  63. Using this option can make df very slow, especially with many or very
  64. busy disks. Note that this may make a difference on some systems --
  65. SunOs4.1.3, for one. It is *not* necessary on Linux. */
  66. /* static int require_sync = 0; */
  67. /* Linked list of filesystem types to display.
  68. If `fs_select_list' is NULL, list all types.
  69. This table is generated dynamically from command-line options,
  70. rather than hardcoding into the program what it thinks are the
  71. valid filesystem types; let the user specify any filesystem type
  72. they want to, and if there are any filesystems of that type, they
  73. will be shown.
  74. Some filesystem types:
  75. 4.2 4.3 ufs nfs swap ignore io vm efs dbg */
  76. /* static struct parameter_list *fs_select_list; */
  77. /* Linked list of filesystem types to omit.
  78. If the list is empty, don't exclude any types. */
  79. static struct name_list *fs_exclude_list;
  80. static struct name_list *dp_exclude_list;
  81. static struct parameter_list *path_select_list;
  82. /* Linked list of mounted filesystems. */
  83. static struct mount_entry *mount_list;
  84. /* For long options that have no equivalent short option, use a
  85. non-character as a pseudo short option, starting with CHAR_MAX + 1. */
  86. enum
  87. {
  88. SYNC_OPTION = CHAR_MAX + 1,
  89. NO_SYNC_OPTION,
  90. BLOCK_SIZE_OPTION
  91. };
  92. #ifdef _AIX
  93. #pragma alloca
  94. #endif
  95. /* Linked list of mounted filesystems. */
  96. static struct mount_entry *mount_list;
  97. int process_arguments (int, char **);
  98. void print_path (const char *mypath);
  99. int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
  100. int check_disk (double usp, uintmax_t free_disk, double uisp);
  101. void print_help (void);
  102. void print_usage (void);
  103. uintmax_t w_df = 0;
  104. uintmax_t c_df = 0;
  105. double w_dfp = -1.0;
  106. double c_dfp = -1.0;
  107. double w_idfp = -1.0;
  108. double c_idfp = -1.0;
  109. char *path;
  110. char *exclude_device;
  111. char *units;
  112. uintmax_t mult = 1024 * 1024;
  113. int verbose = 0;
  114. int erronly = FALSE;
  115. int display_mntp = FALSE;
  116. int exact_match = FALSE;
  117. int
  118. main (int argc, char **argv)
  119. {
  120. double usp = -1.0, uisp = -1.0;
  121. int result = STATE_UNKNOWN;
  122. int disk_result = STATE_UNKNOWN;
  123. char file_system[MAX_INPUT_BUFFER];
  124. char *output;
  125. char *details;
  126. char *perf;
  127. uintmax_t psize;
  128. float free_space, free_space_pct, total_space, inode_space_pct;
  129. struct mount_entry *me;
  130. struct fs_usage fsp;
  131. struct parameter_list *temp_list, *path;
  132. struct name_list *seen = NULL;
  133. output = strdup (" - free space:");
  134. details = strdup ("");
  135. perf = strdup ("");
  136. setlocale (LC_ALL, "");
  137. bindtextdomain (PACKAGE, LOCALEDIR);
  138. textdomain (PACKAGE);
  139. mount_list = read_file_system_list (0);
  140. if (process_arguments (argc, argv) == ERROR)
  141. usage4 (_("Could not parse arguments"));
  142. /* If a list of paths has not been selected, find entire
  143. mount list and create list of paths
  144. */
  145. if (! path_select_list) {
  146. for (me = mount_list; me; me = me->me_next) {
  147. path = np_add_parameter(&path_select_list, me->me_mountdir);
  148. path->w_df = w_df;
  149. path->c_df = c_df;
  150. path->w_dfp = w_dfp;
  151. path->c_dfp = c_dfp;
  152. path->w_idfp = w_idfp;
  153. path->c_idfp = c_idfp;
  154. path->best_match = me;
  155. }
  156. } else {
  157. np_set_best_match(path_select_list, mount_list, exact_match);
  158. /* Error if no match found for specified paths */
  159. temp_list = path_select_list;
  160. while (temp_list) {
  161. if (! temp_list->best_match) {
  162. die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
  163. }
  164. temp_list = temp_list->name_next;
  165. }
  166. }
  167. /* Process for every path in list */
  168. for (path = path_select_list; path; path=path->name_next) {
  169. me = path->best_match;
  170. w_df = path->w_df;
  171. c_df = path->c_df;
  172. w_dfp = path->w_dfp;
  173. c_dfp = path->c_dfp;
  174. w_idfp = path->w_idfp;
  175. c_idfp = path->c_idfp;
  176. /* Filters */
  177. /* Remove filesystems already seen */
  178. if (np_seen_name(seen, me->me_mountdir)) {
  179. continue;
  180. } else {
  181. np_add_name(&seen, me->me_mountdir);
  182. }
  183. /* Skip remote filesystems if we're not interested in them */
  184. if (me->me_remote && show_local_fs) {
  185. continue;
  186. /* Skip pseudo fs's if we haven't asked for all fs's */
  187. } else if (me->me_dummy && !show_all_fs) {
  188. continue;
  189. /* Skip excluded fstypes */
  190. } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
  191. continue;
  192. /* Skip excluded fs's */
  193. } else if (dp_exclude_list &&
  194. (np_find_name (dp_exclude_list, me->me_devname) ||
  195. np_find_name (dp_exclude_list, me->me_mountdir))) {
  196. continue;
  197. }
  198. get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
  199. if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
  200. usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
  201. uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files;
  202. disk_result = check_disk (usp, fsp.fsu_bavail, uisp);
  203. result = max_state (disk_result, result);
  204. psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
  205. /* Moved this computation up here so we can add it
  206. * to perf */
  207. inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files;
  208. asprintf (&perf, "%s %s", perf,
  209. perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
  210. psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units,
  211. TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
  212. TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
  213. TRUE, inode_space_pct,
  214. TRUE, psize));
  215. if (disk_result==STATE_OK && erronly && !verbose)
  216. continue;
  217. free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult;
  218. free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
  219. total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
  220. if (disk_result!=STATE_OK || verbose>=0)
  221. asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"),
  222. output,
  223. (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
  224. free_space,
  225. units,
  226. free_space_pct,
  227. inode_space_pct);
  228. asprintf (&details, _("%s\n\
  229. %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
  230. details, free_space, total_space, units, free_space_pct, inode_space_pct,
  231. me->me_devname, me->me_type, me->me_mountdir,
  232. (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
  233. }
  234. }
  235. if (verbose > 2)
  236. asprintf (&output, "%s%s", output, details);
  237. printf ("DISK %s%s|%s\n", state_text (result), output, perf);
  238. return result;
  239. }
  240. /* process command-line arguments */
  241. int
  242. process_arguments (int argc, char **argv)
  243. {
  244. int c;
  245. struct parameter_list *se;
  246. struct parameter_list **pathtail = &path_select_list;
  247. struct parameter_list *temp_list;
  248. int result = OK;
  249. struct stat *stat_buf;
  250. unsigned long l;
  251. int option = 0;
  252. static struct option longopts[] = {
  253. {"timeout", required_argument, 0, 't'},
  254. {"warning", required_argument, 0, 'w'},
  255. {"critical", required_argument, 0, 'c'},
  256. {"iwarning", required_argument, 0, 'W'},
  257. /* Dang, -C is taken. We might want to reshuffle this. */
  258. {"icritical", required_argument, 0, 'K'},
  259. {"local", required_argument, 0, 'l'},
  260. {"kilobytes", required_argument, 0, 'k'},
  261. {"megabytes", required_argument, 0, 'm'},
  262. {"units", required_argument, 0, 'u'},
  263. {"path", required_argument, 0, 'p'},
  264. {"partition", required_argument, 0, 'p'},
  265. {"exclude_device", required_argument, 0, 'x'},
  266. {"exclude-type", required_argument, 0, 'X'},
  267. {"mountpoint", no_argument, 0, 'M'},
  268. {"errors-only", no_argument, 0, 'e'},
  269. {"exact-match", no_argument, 0, 'E'},
  270. {"verbose", no_argument, 0, 'v'},
  271. {"quiet", no_argument, 0, 'q'},
  272. {"clear", no_argument, 0, 'C'},
  273. {"version", no_argument, 0, 'V'},
  274. {"help", no_argument, 0, 'h'},
  275. {0, 0, 0, 0}
  276. };
  277. if (argc < 2)
  278. return ERROR;
  279. np_add_name(&fs_exclude_list, "iso9660");
  280. for (c = 1; c < argc; c++)
  281. if (strcmp ("-to", argv[c]) == 0)
  282. strcpy (argv[c], "-t");
  283. while (1) {
  284. c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklME", longopts, &option);
  285. if (c == -1 || c == EOF)
  286. break;
  287. switch (c) {
  288. case 't': /* timeout period */
  289. if (is_integer (optarg)) {
  290. timeout_interval = atoi (optarg);
  291. break;
  292. }
  293. else {
  294. usage2 (_("Timeout interval must be a positive integer"), optarg);
  295. }
  296. case 'w': /* warning threshold */
  297. if (is_intnonneg (optarg)) {
  298. w_df = atoi (optarg);
  299. break;
  300. }
  301. else if (strpbrk (optarg, ",:") &&
  302. strstr (optarg, "%") &&
  303. sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) {
  304. w_df = (uintmax_t)l;
  305. break;
  306. }
  307. else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) {
  308. break;
  309. }
  310. else {
  311. usage4 (_("Warning threshold must be integer or percentage!"));
  312. }
  313. case 'c': /* critical threshold */
  314. if (is_intnonneg (optarg)) {
  315. c_df = atoi (optarg);
  316. break;
  317. }
  318. else if (strpbrk (optarg, ",:") &&
  319. strstr (optarg, "%") &&
  320. sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) {
  321. c_df = (uintmax_t)l;
  322. break;
  323. }
  324. else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) {
  325. break;
  326. }
  327. else {
  328. usage4 (_("Critical threshold must be integer or percentage!"));
  329. }
  330. case 'W': /* warning inode threshold */
  331. if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_idfp) == 1) {
  332. break;
  333. }
  334. else {
  335. usage (_("Warning inode threshold must be percentage!\n"));
  336. }
  337. case 'K': /* kritical inode threshold */
  338. if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) {
  339. break;
  340. }
  341. else {
  342. usage (_("Critical inode threshold must be percentage!\n"));
  343. }
  344. case 'u':
  345. if (units)
  346. free(units);
  347. if (! strcmp (optarg, "bytes")) {
  348. mult = (uintmax_t)1;
  349. units = strdup ("B");
  350. } else if (! strcmp (optarg, "kB")) {
  351. mult = (uintmax_t)1024;
  352. units = strdup ("kB");
  353. } else if (! strcmp (optarg, "MB")) {
  354. mult = (uintmax_t)1024 * 1024;
  355. units = strdup ("MB");
  356. } else if (! strcmp (optarg, "GB")) {
  357. mult = (uintmax_t)1024 * 1024 * 1024;
  358. units = strdup ("GB");
  359. } else if (! strcmp (optarg, "TB")) {
  360. mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
  361. units = strdup ("TB");
  362. } else {
  363. die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
  364. }
  365. if (units == NULL)
  366. die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units");
  367. break;
  368. case 'k': /* display mountpoint */
  369. mult = 1024;
  370. if (units)
  371. free(units);
  372. units = strdup ("kB");
  373. break;
  374. case 'm': /* display mountpoint */
  375. mult = 1024 * 1024;
  376. if (units)
  377. free(units);
  378. units = strdup ("MB");
  379. break;
  380. case 'l':
  381. show_local_fs = 1;
  382. break;
  383. case 'p': /* select path */
  384. se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
  385. se->name = optarg;
  386. se->name_next = NULL;
  387. se->w_df = w_df;
  388. se->c_df = c_df;
  389. se->w_dfp = w_dfp;
  390. se->c_dfp = c_dfp;
  391. se->w_idfp = w_idfp;
  392. se->c_idfp = c_idfp;
  393. se->found = 0;
  394. se->found_len = 0;
  395. *pathtail = se;
  396. pathtail = &se->name_next;
  397. break;
  398. case 'x': /* exclude path or partition */
  399. np_add_name(&dp_exclude_list, optarg);
  400. break;
  401. case 'X': /* exclude file system type */
  402. np_add_name(&fs_exclude_list, optarg);
  403. break;
  404. case 'v': /* verbose */
  405. verbose++;
  406. break;
  407. case 'q': /* verbose */
  408. verbose--;
  409. break;
  410. case 'e':
  411. erronly = TRUE;
  412. break;
  413. case 'E':
  414. exact_match = TRUE;
  415. break;
  416. case 'M': /* display mountpoint */
  417. display_mntp = TRUE;
  418. break;
  419. case 'C':
  420. w_df = 0;
  421. c_df = 0;
  422. w_dfp = -1.0;
  423. c_dfp = -1.0;
  424. w_idfp = -1.0;
  425. c_idfp = -1.0;
  426. break;
  427. case 'V': /* version */
  428. print_revision (progname, revision);
  429. exit (STATE_OK);
  430. case 'h': /* help */
  431. print_help ();
  432. exit (STATE_OK);
  433. case '?': /* help */
  434. usage (_("Unknown argument"));
  435. }
  436. }
  437. /* Support for "check_disk warn crit [fs]" with thresholds at used level */
  438. c = optind;
  439. if (w_dfp < 0 && argc > c && is_intnonneg (argv[c]))
  440. w_dfp = (100.0 - atof (argv[c++]));
  441. if (c_dfp < 0 && argc > c && is_intnonneg (argv[c]))
  442. c_dfp = (100.0 - atof (argv[c++]));
  443. if (argc > c && path == NULL) {
  444. se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
  445. se->name = strdup (argv[c++]);
  446. se->name_next = NULL;
  447. se->w_df = w_df;
  448. se->c_df = c_df;
  449. se->w_dfp = w_dfp;
  450. se->c_dfp = c_dfp;
  451. se->w_idfp = w_idfp;
  452. se->c_idfp = c_idfp;
  453. se->found =0;
  454. se->found_len = 0;
  455. *pathtail = se;
  456. }
  457. if (path_select_list) {
  458. temp_list = path_select_list;
  459. stat_buf = malloc(sizeof *stat_buf);
  460. while (temp_list) {
  461. /* Stat each entry to check that dir exists */
  462. if (stat (temp_list->name, &stat_buf[0])) {
  463. printf("DISK %s - ", _("CRITICAL"));
  464. die (STATE_CRITICAL, _("%s does not exist\n"), temp_list->name);
  465. }
  466. if (validate_arguments (temp_list->w_df,
  467. temp_list->c_df,
  468. temp_list->w_dfp,
  469. temp_list->c_dfp,
  470. temp_list->w_idfp,
  471. temp_list->c_idfp,
  472. temp_list->name) == ERROR)
  473. result = ERROR;
  474. temp_list = temp_list->name_next;
  475. }
  476. free(stat_buf);
  477. return result;
  478. } else {
  479. return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL);
  480. }
  481. }
  482. void
  483. print_path (const char *mypath)
  484. {
  485. if (mypath == NULL)
  486. printf ("\n");
  487. else
  488. printf (_(" for %s\n"), mypath);
  489. return;
  490. }
  491. int
  492. validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath)
  493. {
  494. if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) {
  495. printf (_("INPUT ERROR: No thresholds specified"));
  496. print_path (mypath);
  497. return ERROR;
  498. }
  499. else if ((wp >= 0.0 || cp >= 0.0) &&
  500. (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) {
  501. printf (_("\
  502. INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"),
  503. cp, wp);
  504. print_path (mypath);
  505. return ERROR;
  506. }
  507. else if ((iwp >= 0.0 || icp >= 0.0) &&
  508. (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) {
  509. printf (_("\
  510. INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"),
  511. icp, iwp);
  512. print_path (mypath);
  513. return ERROR;
  514. }
  515. else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) {
  516. printf (_("\
  517. INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"),
  518. (unsigned long)c, (unsigned long)w);
  519. print_path (mypath);
  520. return ERROR;
  521. }
  522. if (units == NULL) {
  523. units = strdup ("MB");
  524. mult = (uintmax_t)1024 * 1024;
  525. }
  526. return OK;
  527. }
  528. int
  529. check_disk (double usp, uintmax_t free_disk, double uisp)
  530. {
  531. int result = STATE_UNKNOWN;
  532. /* check the percent used space against thresholds */
  533. if (usp >= 0.0 && c_dfp >=0.0 && usp >= (100.0 - c_dfp))
  534. result = STATE_CRITICAL;
  535. else if (uisp >= 0.0 && c_idfp >=0.0 && uisp >= (100.0 - c_idfp))
  536. result = STATE_CRITICAL;
  537. else if (c_df > 0 && free_disk <= c_df)
  538. result = STATE_CRITICAL;
  539. else if (usp >= 0.0 && w_dfp >=0.0 && usp >= (100.0 - w_dfp))
  540. result = STATE_WARNING;
  541. else if (uisp >= 0.0 && w_idfp >=0.0 && uisp >= (100.0 - w_idfp))
  542. result = STATE_WARNING;
  543. else if (w_df > 0 && free_disk <= w_df)
  544. result = STATE_WARNING;
  545. else if (usp >= 0.0)
  546. result = STATE_OK;
  547. return result;
  548. }
  549. void
  550. print_help (void)
  551. {
  552. print_revision (progname, revision);
  553. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  554. printf (COPYRIGHT, copyright, email);
  555. printf ("%s\n", _("This plugin checks the amount of used disk space on a mounted file system"));
  556. printf ("%s\n", _("and generates an alert if free space is less than one of the threshold values"));
  557. printf ("\n\n");
  558. print_usage ();
  559. printf (_(UT_HELP_VRSN));
  560. printf (" %s\n", "-w, --warning=INTEGER");
  561. printf (" %s\n", _("Exit with WARNING status if less than INTEGER units of disk are free"));
  562. printf (" %s\n", "-w, --warning=PERCENT%");
  563. printf (" %s\n", _("Exit with WARNING status if less than PERCENT of disk space is free"));
  564. printf (" %s\n", "-W, --iwarning=PERCENT%");
  565. printf (" %s\n", _("Exit with WARNING status if less than PERCENT of inode space is free"));
  566. printf (" %s\n", "-K, --icritical=PERCENT%");
  567. printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of inode space is free"));
  568. printf (" %s\n", "-c, --critical=INTEGER");
  569. printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER units of disk are free"));
  570. printf (" %s\n", "-c, --critical=PERCENT%");
  571. printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of disk space is free"));
  572. printf (" %s\n", "-C, --clear");
  573. printf (" %s\n", _("Clear thresholds"));
  574. printf (" %s\n", "-u, --units=STRING");
  575. printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
  576. printf (" %s\n", "-k, --kilobytes");
  577. printf (" %s\n", _("Same as '--units kB'"));
  578. printf (" %s\n", "-m, --megabytes");
  579. printf (" %s\n", _("Same as '--units MB'"));
  580. printf (" %s\n", "-l, --local");
  581. printf (" %s\n", _("Only check local filesystems"));
  582. printf (" %s\n", "-p, --path=PATH, --partition=PARTITION");
  583. printf (" %s\n", _("Path or partition (may be repeated)"));
  584. printf (" %s\n", "-x, --exclude_device=PATH <STRING>");
  585. printf (" %s\n", _("Ignore device (only works if -p unspecified)"));
  586. printf (" %s\n", _("-X, --exclude-type=TYPE <STRING>"));
  587. printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
  588. printf (" %s\n", "-m, --mountpoint");
  589. printf (" %s\n", _("Display the mountpoint instead of the partition"));
  590. printf (" %s\n", "-E, --exact-match");
  591. printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths"));
  592. printf (" %s\n", "-e, --errors-only");
  593. printf (" %s\n", _("Display only devices/mountpoints with errors"));
  594. printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
  595. printf (_(UT_VERBOSE));
  596. printf ("\n");
  597. printf ("%s\n", _("Examples:"));
  598. printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /");
  599. printf (" %s\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB"));
  600. printf (_(UT_SUPPORT));
  601. }
  602. void
  603. print_usage (void)
  604. {
  605. printf (_("Usage:"));
  606. printf (" %s -w limit -c limit [-p path | -x device] [-t timeout]", progname);
  607. printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q] [-E]\n");
  608. }