~ubuntu-branches/ubuntu/precise/nagios-plugins/precise-proposed

« back to all changes in this revision

Viewing changes to contrib/check_inodes.pl

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2004-06-15 15:37:48 UTC
  • Revision ID: james.westby@ubuntu.com-20040615153748-pq7702qdzghqfcns
Tags: upstream-1.3.1.0
ImportĀ upstreamĀ versionĀ 1.3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
11
$filesystem = $ARGV[0];
 
12
$warnpercent = $ARGV[1];
 
13
$critpercent = $ARGV[2];
 
14
 
 
15
#------Find out what kind of syntax to expect
 
16
$systype=`uname`;
 
17
chomp($systype);
 
18
 
 
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;
 
23
 
 
24
if ($#ARGV < 2) {
 
25
  die "Usage: check_inodes filesystem warnpercent critpercent";
 
26
}#end if
 
27
 
 
28
#------This gets the data from the df command
 
29
$inputline = `df -i $filesystem|grep -v "Filesystem"`;
 
30
 
 
31
#------replaces all spaces with a single :, that way we can use split
 
32
$inputline =~ y/ /:/s;
 
33
 
 
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
 
48
 
 
49
#------First we check for critical, since that is, by definition and convention
 
50
#------going to exceed the warning threshold
 
51
$ipercent =~ y/%//ds;
 
52
 
 
53
if ($ipercent > $critpercent) {
 
54
  print "CRITICAL: $filesystem inode use exceeds critical threshold $critpercent ($ipercent)";
 
55
  exit 1;
 
56
}# end if
 
57
 
 
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
 
63
 
 
64
 
 
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;
 
69