check_inodes.pl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/perl
  2. ##############################################################################
  3. # This plugin uses df to gather filesystem statistics and check the percent #
  4. # used of inodes. I've put a switch in here since i've got both aix and #
  5. # linux systems...adjust for your syntax's results. #
  6. # Note: the percentages passed in MUST NOT have % after them #
  7. # No warranty is either implied, nor expressed herein. #
  8. # #
  9. ##############################################################################
  10. $filesystem = $ARGV[0];
  11. $warnpercent = $ARGV[1];
  12. $critpercent = $ARGV[2];
  13. #------Find out what kind of syntax to expect
  14. $systype=`uname`;
  15. chomp($systype);
  16. #------Make sure we got called with the right number of arguments
  17. #------you could also put a check in here to make sure critical level is
  18. #------greater than warning...but what the heck.
  19. die "Usage: check_inodes filesystem warnpercent critpercent" unless @ARGV;
  20. if ($#ARGV < 2) {
  21. die "Usage: check_inodes filesystem warnpercent critpercent";
  22. }#end if
  23. #------This gets the data from the df command
  24. $inputline = `df -i $filesystem|grep -v "Filesystem"`;
  25. #------replaces all spaces with a single :, that way we can use split
  26. $inputline =~ y/ /:/s;
  27. #------different oses give back different sets of columns from the df -i
  28. #------(at least mine do). This way I can use this plugin on all my hosts
  29. #------if neither of these work, add your own in, or if you've got one that
  30. #------just flat out reports something different...well...perl is your friend.
  31. SWITCH: {
  32. if ($systype eq "Linux") {
  33. ($fs,$inodes,$iused,$ifree,$ipercent,$mntpt) = split(/:/,$inputline);
  34. last SWITCH;
  35. }#end if
  36. if ($systype eq "AIX") {
  37. ($fs,$blks,$free,$percentused,$iused,$ipercent,$mntpt) = split(/:/,$inputline);
  38. last SWITCH;
  39. }#end if
  40. }#end switch
  41. #------First we check for critical, since that is, by definition and convention
  42. #------going to exceed the warning threshold
  43. $ipercent =~ y/%//ds;
  44. if ($ipercent > $critpercent) {
  45. print "CRITICAL: $filesystem inode use exceeds critical threshold $critpercent ($ipercent)";
  46. exit 1;
  47. }# end if
  48. #------Next we check the warning threshold
  49. if ($ipercent > $warnpercent) {
  50. print "WARNING: $filesystem inode use exceeds warning threshold $warnpercent ($ipercent)";
  51. exit 2;
  52. }# end if
  53. #------thanks to the magic of procedural programming, we figure if we got here,
  54. #------everything MUST be fine.
  55. print "$filesystem inode use within limits ($ipercent)";
  56. exit 0;