check_inodes-freebsd.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/perl
  2. # check_inodes.pl for FreeBSD
  3. # Designed on FreeBSD 4.6 (although this should not matter)
  4. # parses df output, splits, and then takes variables
  5. # df.pl -f mountpoint -w warningnumber -c critical number
  6. # USE NUMBERS AND NOT PERCENTS FOR wanring and critical values
  7. # -h is help
  8. # -v is version
  9. # Mountpoints:
  10. # like / or /usr or /var (whatever you mount drives NOT the device names)
  11. # Andrew Ryder - 20020804 - atr@mrcoffee.org
  12. use strict;
  13. use Getopt::Long;
  14. use vars qw($opt_V $opt_h $opt_w $opt_c $opt_f $verbose $PROGNAME);
  15. use lib "/usr/local/libexec/nagios" ;
  16. use utils qw($TIMEOUT %ERRORS &print_revision &support);
  17. my $df = "/bin/df";
  18. my $grep = "/usr/bin/grep";
  19. $PROGNAME="df.pl";
  20. sub print_help ();
  21. sub print_usage ();
  22. $ENV{'PATH'}='';
  23. $ENV{'BASH_ENV'}='';
  24. $ENV{'ENV'}='';
  25. Getopt::Long::Configure('bundling');
  26. GetOptions
  27. ("V" => \$opt_V, "version" => \$opt_V,
  28. "h" => \$opt_h, "help" => \$opt_h,
  29. "w=s" => \$opt_w, "warning=s" => \$opt_w,
  30. "c=s" => \$opt_c, "critical=s" => \$opt_c,
  31. "f=s" => \$opt_f, "filesystem=s" => \$opt_f);
  32. if ($opt_V) {
  33. print_revision($PROGNAME,'$Revision$ ');
  34. exit $ERRORS{'OK'};
  35. }
  36. if ($opt_h) {
  37. print_help();
  38. exit $ERRORS{'OK'};
  39. }
  40. ($opt_w) || ($opt_w = shift) || ($opt_w = 50);
  41. my $warning = $1 if ($opt_w =~ /([0-9]+)/);
  42. ($opt_c) || ($opt_c = shift) || ($opt_c = 75);
  43. my $critical = $1 if ($opt_c =~ /([0-9]+)/);
  44. if ($opt_c < $opt_w) {
  45. print "Critical offset should be larger than warning offset\n";
  46. print_usage();
  47. exit $ERRORS{"UNKNOWN"};
  48. }
  49. ($opt_f) || ($opt_f = "/");
  50. unless (-e $df) {
  51. print "UNKNOWN: $df is not where df is\n";
  52. exit $ERRORS{'UNKNOWN'};
  53. }
  54. unless (-e $grep) {
  55. print "UNKNOWN: $grep is not where grep is\n";
  56. exit $ERRORS{'UNKNOWN'};
  57. }
  58. unless (-d $opt_f) {
  59. print "UNKNOWN: $opt_f is not a mount point\n";
  60. exit $ERRORS{'UNKNOWN'};
  61. }
  62. my $state = $ERRORS{'UNKNOWN'};
  63. my $answer;
  64. open(DF, "$df -i $opt_f| $grep -v Filesystem |");
  65. while (<DF>) {
  66. my ($fs,$onek,$used,$avail,$capacity,$iused,$ifree,$ipercent,$mounted) = split;
  67. $ipercent =~ s/%//s;
  68. if ($ipercent > $opt_w) {
  69. $state = $ERRORS{'WARNING'};
  70. $answer = "WARNING: $ipercent percent inodes free on $opt_f\n";
  71. } elsif ($ipercent > $opt_w) {
  72. $state = $ERRORS{'CRITCAL'};
  73. $answer = "CRITICAL: $ipercent percent inodes free on $opt_f\n";
  74. } elsif ($ipercent < $opt_w) {
  75. $state = $ERRORS{'OK'};
  76. $answer = "OK: $ipercent percent inodes free on $opt_f\n";
  77. }
  78. }
  79. close(DF);
  80. print "$answer";
  81. exit $state;
  82. sub print_usage () {
  83. print "Usage: $PROGNAME <filesystem> [-w <warn>] [-c <crit>]\n";
  84. print "Example: $PROGNAME /dev/ad0s1a -w 50 -c 75\n";
  85. }
  86. sub print_help () {
  87. print_revision($PROGNAME,'$Revision$');
  88. print "Copyright (c) 2002 Andrew Ryder\n";
  89. print "\n";
  90. print_usage();
  91. print "\n";
  92. print "<warn> = Inode Percent at which a warning message is returned. Defaults to 50.\n";
  93. print "<crit> = Inode Percent at which a critical message is returned..\n Defaults to 75.\n\n";
  94. support();
  95. }