check_disk.c 23 KB

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