Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / contrib / check_inodes.pl
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 ##############################################################################
11 $filesystem = $ARGV[0];
12 $warnpercent = $ARGV[1];
13 $critpercent = $ARGV[2];
15 #------Find out what kind of syntax to expect
16 $systype=`uname`;
17 chomp($systype);
19 #------Make sure we got called with the right number of arguments
20 #------you could also put a check in here to make sure critical level is
21 #------greater than warning...but what the heck.
22 die "Usage: check_inodes filesystem warnpercent critpercent" unless @ARGV;
24 if ($#ARGV < 2) {
25   die "Usage: check_inodes filesystem warnpercent critpercent";
26 }#end if
28 #------This gets the data from the df command
29 $inputline = `df -i $filesystem|grep -v "Filesystem"`;
31 #------replaces all spaces with a single :, that way we can use split
32 $inputline =~ y/ /:/s;
34 #------different oses give back different sets of columns from the df -i
35 #------(at least mine do).  This way I can use this plugin on all my hosts
36 #------if neither of these work, add your own in, or if you've got one that
37 #------just flat out reports something different...well...perl is your friend.
38 SWITCH: {
39   if ($systype eq "Linux") {
40     ($fs,$inodes,$iused,$ifree,$ipercent,$mntpt) = split(/:/,$inputline); 
41     last SWITCH;
42   }#end if
43   if ($systype eq "AIX") {
44     ($fs,$blks,$free,$percentused,$iused,$ipercent,$mntpt) = split(/:/,$inputline); 
45     last SWITCH;
46   }#end if
47 }#end switch
49 #------First we check for critical, since that is, by definition and convention
50 #------going to exceed the warning threshold
51 $ipercent =~ y/%//ds;
53 if ($ipercent > $critpercent) {
54   print "CRITICAL: $filesystem inode use exceeds critical threshold $critpercent ($ipercent)";
55   exit 1;
56 }# end if
58 #------Next we check the warning threshold
59 if ($ipercent > $warnpercent) {
60   print "WARNING: $filesystem inode use exceeds warning threshold $warnpercent ($ipercent)";
61   exit 2;
62 }# end if
65 #------thanks to the magic of procedural programming, we figure if we got here,
66 #------everything MUST be fine.
67 print "$filesystem inode use within limits ($ipercent)";
68 exit 0;