check_nfs_stale 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <iso646.h>
  5. #include <errno.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #define VERSION_STRING "0.1"
  9. #define OK 0
  10. #define WARNING 1
  11. #define CRITICAL 2
  12. #define UNKNOWN 3
  13. static void usage(void)
  14. {
  15. printf("check_nfs_stale Version: %s\n", VERSION_STRING);
  16. puts(
  17. "Nagios plugin to check for stale NFS mounts\n"
  18. "Options:\n\n"
  19. " -p <mount> Mount point of NFS share\n"
  20. " -h Print help\n\n"
  21. "Usage: check_nfs_stale [-h] [-p mount_point]\n"
  22. "Please report bugs to <jonschipp@gmail.com>");
  23. exit(OK);
  24. }
  25. int main(int argc, char **argv) {
  26. struct stat file_stat;
  27. int ret, c;
  28. const char *mpoint = NULL;
  29. if ( argc == 1 ) {
  30. puts("Requires an argument, try ``-h''");
  31. exit(UNKNOWN);
  32. }
  33. while ((c = getopt (argc, argv, "hp:")) != -1)
  34. switch (c) {
  35. case 'h':
  36. usage();
  37. break;
  38. case 'p':
  39. mpoint = optarg;
  40. break;
  41. case '?':
  42. usage();
  43. break;
  44. }
  45. ret = stat(mpoint, &file_stat);
  46. if (ret == -1 && errno == ESTALE) {
  47. printf("%s is stale\n", mpoint);
  48. exit(CRITICAL);
  49. }
  50. else
  51. printf("%s is fine\n", mpoint);
  52. exit(OK);
  53. }