check_disk.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. int walk_parameter_list (struct parameter_list *list, const char *name);
  102. void print_help (void);
  103. void print_usage (void);
  104. uintmax_t w_df = 0;
  105. uintmax_t c_df = 0;
  106. double w_dfp = -1.0;
  107. double c_dfp = -1.0;
  108. double w_idfp = -1.0;
  109. double c_idfp = -1.0;
  110. char *path;
  111. char *exclude_device;
  112. char *units;
  113. uintmax_t mult = 1024 * 1024;
  114. int verbose = 0;
  115. int erronly = FALSE;
  116. int display_mntp = 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;
  132. output = strdup (" - free space:");
  133. details = strdup ("");
  134. perf = strdup ("");
  135. setlocale (LC_ALL, "");
  136. bindtextdomain (PACKAGE, LOCALEDIR);
  137. textdomain (PACKAGE);
  138. mount_list = read_file_system_list (0);
  139. if (process_arguments (argc, argv) == ERROR)
  140. usage4 (_("Could not parse arguments"));
  141. /* if a list of paths has been selected, preseed the list with
  142. * the longest matching filesystem name by iterating across
  143. * the mountlist once ahead of time. this will allow a query on
  144. * "/var/log" to return information about "/var" if no "/var/log"
  145. * filesystem exists, etc. this is the default behavior already
  146. * with df-based checks, but for systems with their own space
  147. * checking routines, this should make them more consistent.
  148. */
  149. if(path_select_list){
  150. for (me = mount_list; me; me = me->me_next) {
  151. walk_parameter_list(path_select_list, me->me_mountdir);
  152. walk_parameter_list(path_select_list, me->me_devname);
  153. }
  154. /* now pretend we never saw anything, but keep found_len.
  155. * thus future searches will only match the best match */
  156. for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){
  157. temp_list->found=0;
  158. }
  159. }
  160. /* for every mount entry */
  161. for (me = mount_list; me; me = me->me_next) {
  162. /* if there's a list of paths to select, the current mount
  163. * entry matches in path or device name, get fs usage */
  164. if (path_select_list &&
  165. (walk_parameter_list (path_select_list, me->me_mountdir) ||
  166. walk_parameter_list (path_select_list, me->me_devname) ) ) {
  167. get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
  168. /* else if there's a list of paths/devices to select (but
  169. * we didn't match above) skip to the next mount entry */
  170. } else if (path_select_list) {
  171. continue;
  172. /* skip remote filesystems if we're not interested in them */
  173. } else if (me->me_remote && show_local_fs) {
  174. continue;
  175. /* skip pseudo fs's if we haven't asked for all fs's */
  176. } else if (me->me_dummy && !show_all_fs) {
  177. continue;
  178. /* skip excluded fstypes */
  179. } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
  180. continue;
  181. /* skip excluded fs's */
  182. } else if (dp_exclude_list &&
  183. (np_find_name (dp_exclude_list, me->me_devname) ||
  184. np_find_name (dp_exclude_list, me->me_mountdir))) {
  185. continue;
  186. /* otherwise, get fs usage */
  187. } else {
  188. get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
  189. }
  190. if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
  191. usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
  192. uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files;
  193. disk_result = check_disk (usp, fsp.fsu_bavail, uisp);
  194. result = max_state (disk_result, result);
  195. psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
  196. /* Moved this computation up here so we can add it
  197. * to perf */
  198. inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files;
  199. asprintf (&perf, "%s %s", perf,
  200. perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
  201. psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units,
  202. TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
  203. TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
  204. TRUE, inode_space_pct,
  205. TRUE, psize));
  206. if (disk_result==STATE_OK && erronly && !verbose)
  207. continue;
  208. free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult;
  209. free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
  210. total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
  211. if (disk_result!=STATE_OK || verbose>=0)
  212. asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"),
  213. output,
  214. (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
  215. free_space,
  216. units,
  217. free_space_pct,
  218. inode_space_pct);
  219. asprintf (&details, _("%s\n\
  220. %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
  221. details, free_space, total_space, units, free_space_pct, inode_space_pct,
  222. me->me_devname, me->me_type, me->me_mountdir,
  223. (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
  224. }
  225. }
  226. if (verbose > 2)
  227. asprintf (&output, "%s%s", output, details);
  228. /* Override result if paths specified and not found */
  229. temp_list = path_select_list;
  230. while (temp_list) {
  231. if (!temp_list->found) {
  232. asprintf (&output, _("%s [%s not found]"), output, temp_list->name);
  233. result = STATE_CRITICAL;
  234. }
  235. temp_list = temp_list->name_next;
  236. }
  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. {"verbose", no_argument, 0, 'v'},
  270. {"quiet", no_argument, 0, 'q'},
  271. {"clear", no_argument, 0, 'C'},
  272. {"version", no_argument, 0, 'V'},
  273. {"help", no_argument, 0, 'h'},
  274. {0, 0, 0, 0}
  275. };
  276. if (argc < 2)
  277. return ERROR;
  278. np_add_name(&fs_exclude_list, "iso9660");
  279. for (c = 1; c < argc; c++)
  280. if (strcmp ("-to", argv[c]) == 0)
  281. strcpy (argv[c], "-t");
  282. while (1) {
  283. c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option);
  284. if (c == -1 || c == EOF)
  285. break;
  286. switch (c) {
  287. case 't': /* timeout period */
  288. if (is_integer (optarg)) {
  289. timeout_interval = atoi (optarg);
  290. break;
  291. }
  292. else {
  293. usage2 (_("Timeout interval must be a positive integer"), optarg);
  294. }
  295. case 'w': /* warning threshold */
  296. if (is_intnonneg (optarg)) {
  297. w_df = atoi (optarg);
  298. break;
  299. }
  300. else if (strpbrk (optarg, ",:") &&
  301. strstr (optarg, "%") &&
  302. sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) {
  303. w_df = (uintmax_t)l;
  304. break;
  305. }
  306. else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) {
  307. break;
  308. }
  309. else {
  310. usage4 (_("Warning threshold must be integer or percentage!"));
  311. }
  312. case 'c': /* critical threshold */
  313. if (is_intnonneg (optarg)) {
  314. c_df = atoi (optarg);
  315. break;
  316. }
  317. else if (strpbrk (optarg, ",:") &&
  318. strstr (optarg, "%") &&
  319. sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) {
  320. c_df = (uintmax_t)l;
  321. break;
  322. }
  323. else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) {
  324. break;
  325. }
  326. else {
  327. usage4 (_("Critical threshold must be integer or percentage!"));
  328. }
  329. case 'W': /* warning inode threshold */
  330. if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_idfp) == 1) {
  331. break;
  332. }
  333. else {
  334. usage (_("Warning inode threshold must be percentage!\n"));
  335. }
  336. case 'K': /* kritical inode threshold */
  337. if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) {
  338. break;
  339. }
  340. else {
  341. usage (_("Critical inode threshold must be percentage!\n"));
  342. }
  343. case 'u':
  344. if (units)
  345. free(units);
  346. if (! strcmp (optarg, "bytes")) {
  347. mult = (uintmax_t)1;
  348. units = strdup ("B");
  349. } else if (! strcmp (optarg, "kB")) {
  350. mult = (uintmax_t)1024;
  351. units = strdup ("kB");
  352. } else if (! strcmp (optarg, "MB")) {
  353. mult = (uintmax_t)1024 * 1024;
  354. units = strdup ("MB");
  355. } else if (! strcmp (optarg, "GB")) {
  356. mult = (uintmax_t)1024 * 1024 * 1024;
  357. units = strdup ("GB");
  358. } else if (! strcmp (optarg, "TB")) {
  359. mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
  360. units = strdup ("TB");
  361. } else {
  362. die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
  363. }
  364. if (units == NULL)
  365. die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units");
  366. break;
  367. case 'k': /* display mountpoint */
  368. mult = 1024;
  369. if (units)
  370. free(units);
  371. units = strdup ("kB");
  372. break;
  373. case 'm': /* display mountpoint */
  374. mult = 1024 * 1024;
  375. if (units)
  376. free(units);
  377. units = strdup ("MB");
  378. break;
  379. case 'l':
  380. show_local_fs = 1;
  381. break;
  382. case 'p': /* select path */
  383. se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
  384. se->name = optarg;
  385. se->name_next = NULL;
  386. se->w_df = w_df;
  387. se->c_df = c_df;
  388. se->w_dfp = w_dfp;
  389. se->c_dfp = c_dfp;
  390. se->w_idfp = w_idfp;
  391. se->c_idfp = c_idfp;
  392. se->found = 0;
  393. se->found_len = 0;
  394. *pathtail = se;
  395. pathtail = &se->name_next;
  396. break;
  397. case 'x': /* exclude path or partition */
  398. np_add_name(&dp_exclude_list, optarg);
  399. break;
  400. case 'X': /* exclude file system type */
  401. np_add_name(&fs_exclude_list, optarg);
  402. break;
  403. case 'v': /* verbose */
  404. verbose++;
  405. break;
  406. case 'q': /* verbose */
  407. verbose--;
  408. break;
  409. case 'e':
  410. erronly = TRUE;
  411. break;
  412. case 'M': /* display mountpoint */
  413. display_mntp = TRUE;
  414. break;
  415. case 'C':
  416. w_df = 0;
  417. c_df = 0;
  418. w_dfp = -1.0;
  419. c_dfp = -1.0;
  420. w_idfp = -1.0;
  421. c_idfp = -1.0;
  422. break;
  423. case 'V': /* version */
  424. print_revision (progname, revision);
  425. exit (STATE_OK);
  426. case 'h': /* help */
  427. print_help ();
  428. exit (STATE_OK);
  429. case '?': /* help */
  430. usage (_("Unknown argument"));
  431. }
  432. }
  433. /* Support for "check_disk warn crit [fs]" with thresholds at used level */
  434. c = optind;
  435. if (w_dfp < 0 && argc > c && is_intnonneg (argv[c]))
  436. w_dfp = (100.0 - atof (argv[c++]));
  437. if (c_dfp < 0 && argc > c && is_intnonneg (argv[c]))
  438. c_dfp = (100.0 - atof (argv[c++]));
  439. if (argc > c && path == NULL) {
  440. se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
  441. se->name = strdup (argv[c++]);
  442. se->name_next = NULL;
  443. se->w_df = w_df;
  444. se->c_df = c_df;
  445. se->w_dfp = w_dfp;
  446. se->c_dfp = c_dfp;
  447. se->w_idfp = w_idfp;
  448. se->c_idfp = c_idfp;
  449. se->found =0;
  450. se->found_len = 0;
  451. *pathtail = se;
  452. }
  453. if (path_select_list) {
  454. temp_list = path_select_list;
  455. stat_buf = malloc(sizeof *stat_buf);
  456. while (temp_list) {
  457. /* Stat each entry to check that dir exists */
  458. if (stat (temp_list->name, &stat_buf[0])) {
  459. printf("DISK %s - ", _("CRITICAL"));
  460. die (STATE_CRITICAL, _("%s does not exist\n"), temp_list->name);
  461. }
  462. if (validate_arguments (temp_list->w_df,
  463. temp_list->c_df,
  464. temp_list->w_dfp,
  465. temp_list->c_dfp,
  466. temp_list->w_idfp,
  467. temp_list->c_idfp,
  468. temp_list->name) == ERROR)
  469. result = ERROR;
  470. temp_list = temp_list->name_next;
  471. }
  472. free(stat_buf);
  473. return result;
  474. } else {
  475. return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL);
  476. }
  477. }
  478. void
  479. print_path (const char *mypath)
  480. {
  481. if (mypath == NULL)
  482. printf ("\n");
  483. else
  484. printf (_(" for %s\n"), mypath);
  485. return;
  486. }
  487. int
  488. validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath)
  489. {
  490. if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) {
  491. printf (_("INPUT ERROR: No thresholds specified"));
  492. print_path (mypath);
  493. return ERROR;
  494. }
  495. else if ((wp >= 0.0 || cp >= 0.0) &&
  496. (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) {
  497. printf (_("\
  498. INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"),
  499. cp, wp);
  500. print_path (mypath);
  501. return ERROR;
  502. }
  503. else if ((iwp >= 0.0 || icp >= 0.0) &&
  504. (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) {
  505. printf (_("\
  506. INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"),
  507. icp, iwp);
  508. print_path (mypath);
  509. return ERROR;
  510. }
  511. else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) {
  512. printf (_("\
  513. INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"),
  514. (unsigned long)c, (unsigned long)w);
  515. print_path (mypath);
  516. return ERROR;
  517. }
  518. if (units == NULL) {
  519. units = strdup ("MB");
  520. mult = (uintmax_t)1024 * 1024;
  521. }
  522. return OK;
  523. }
  524. int
  525. check_disk (double usp, uintmax_t free_disk, double uisp)
  526. {
  527. int result = STATE_UNKNOWN;
  528. /* check the percent used space against thresholds */
  529. if (usp >= 0.0 && c_dfp >=0.0 && usp >= (100.0 - c_dfp))
  530. result = STATE_CRITICAL;
  531. else if (uisp >= 0.0 && c_idfp >=0.0 && uisp >= (100.0 - c_idfp))
  532. result = STATE_CRITICAL;
  533. else if (c_df > 0 && free_disk <= c_df)
  534. result = STATE_CRITICAL;
  535. else if (usp >= 0.0 && w_dfp >=0.0 && usp >= (100.0 - w_dfp))
  536. result = STATE_WARNING;
  537. else if (uisp >= 0.0 && w_idfp >=0.0 && uisp >= (100.0 - w_idfp))
  538. result = STATE_WARNING;
  539. else if (w_df > 0 && free_disk <= w_df)
  540. result = STATE_WARNING;
  541. else if (usp >= 0.0)
  542. result = STATE_OK;
  543. return result;
  544. }
  545. int
  546. walk_parameter_list (struct parameter_list *list, const char *name)
  547. {
  548. int name_len;
  549. name_len = strlen(name);
  550. while (list) {
  551. /* if the paths match up to the length of the mount path,
  552. * AND if the mount path name is longer than the longest
  553. * found match, we have a new winner */
  554. if (name_len >= list->found_len &&
  555. ! strncmp(list->name, name, name_len)) {
  556. list->found = 1;
  557. list->found_len = name_len;
  558. /* if required for parameter_lists that have not saved w_df, etc (eg exclude lists) */
  559. if (list->w_df) w_df = list->w_df;
  560. if (list->c_df) c_df = list->c_df;
  561. if (list->w_dfp>=0.0) w_dfp = list->w_dfp;
  562. if (list->c_dfp>=0.0) c_dfp = list->c_dfp;
  563. return TRUE;
  564. }
  565. list = list->name_next;
  566. }
  567. return FALSE;
  568. }
  569. void
  570. print_help (void)
  571. {
  572. print_revision (progname, revision);
  573. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  574. printf (COPYRIGHT, copyright, email);
  575. printf ("%s\n", _("This plugin checks the amount of used disk space on a mounted file system"));
  576. printf ("%s\n", _("and generates an alert if free space is less than one of the threshold values"));
  577. printf ("\n\n");
  578. print_usage ();
  579. printf (_(UT_HELP_VRSN));
  580. printf (" %s\n", "-w, --warning=INTEGER");
  581. printf (" %s\n", _("Exit with WARNING status if less than INTEGER units of disk are free"));
  582. printf (" %s\n", "-w, --warning=PERCENT%");
  583. printf (" %s\n", _("Exit with WARNING status if less than PERCENT of disk space is free"));
  584. printf (" %s\n", "-W, --iwarning=PERCENT%");
  585. printf (" %s\n", _("Exit with WARNING status if less than PERCENT of inode space is free"));
  586. printf (" %s\n", "-K, --icritical=PERCENT%");
  587. printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of inode space is free"));
  588. printf (" %s\n", "-c, --critical=INTEGER");
  589. printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER units of disk are free"));
  590. printf (" %s\n", "-c, --critical=PERCENT%");
  591. printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of disk space is free"));
  592. printf (" %s\n", "-C, --clear");
  593. printf (" %s\n", _("Clear thresholds"));
  594. printf (" %s\n", "-u, --units=STRING");
  595. printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
  596. printf (" %s\n", "-k, --kilobytes");
  597. printf (" %s\n", _("Same as '--units kB'"));
  598. printf (" %s\n", "-m, --megabytes");
  599. printf (" %s\n", _("Same as '--units MB'"));
  600. printf (" %s\n", "-l, --local");
  601. printf (" %s\n", _("Only check local filesystems"));
  602. printf (" %s\n", "-p, --path=PATH, --partition=PARTITION");
  603. printf (" %s\n", _("Path or partition (may be repeated)"));
  604. printf (" %s\n", "-x, --exclude_device=PATH <STRING>");
  605. printf (" %s\n", _("Ignore device (only works if -p unspecified)"));
  606. printf (" %s\n", _("-X, --exclude-type=TYPE <STRING>"));
  607. printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
  608. printf (" %s\n", "-m, --mountpoint");
  609. printf (" %s\n", _("Display the mountpoint instead of the partition"));
  610. printf (" %s\n", "-e, --errors-only");
  611. printf (" %s\n", _("Display only devices/mountpoints with errors"));
  612. printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
  613. printf (_(UT_VERBOSE));
  614. printf ("\n");
  615. printf ("%s\n", _("Examples:"));
  616. printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /");
  617. printf (" %s\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB"));
  618. printf (_(UT_SUPPORT));
  619. }
  620. void
  621. print_usage (void)
  622. {
  623. printf (_("Usage:"));
  624. printf (" %s -w limit -c limit [-p path | -x device] [-t timeout]", progname);
  625. printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q]\n");
  626. }