#!/opt/nagios/bin/perl # # ------------------------------------------------------------------------------ # check disk wrapper using a config file # # read in list of file systems and thresholds # if the file system is mounted append to list and run check_disk # # # Author: Kyle O'Donnell # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ------------------------------------------------------------------------------ # use strict; use Getopt::Long; use lib '/opt/nagios/libexec'; use utils qw(%ERRORS); my $PROGNAME = 'check_disk_cfgfile'; my $PROGVER = "1.3"; my $check_disk = "/opt/nagios/libexec/check_disk"; my ($config, $argwarn, $warn, $argcrit, $crit, @mount, $fs, $line, $tmplist, $list); ############################################## # prints the usage of the plugin sub usage { my $msg = shift; if (defined $msg) { print "$msg\n"; } print << "EOT"; $PROGNAME $PROGVER usage: -f file, --config= /path/to/config_file -w warning, --warn= percent free warning threshold -c critical, --crit= percent free critical threshold example: $PROGNAME -f /path/to/config_file -w 10% -c 5% example config: /path/to/disk,10%,5% /path/to/anotherdisk /yet/another/path,50%,20% the script uses the command line argument thresholds if not defined in config EOT exit($ERRORS{'UNKNOWN'}); } # get argument variables use vars qw($opt_C $opt_w $opt_c); GetOptions ( "f|file=s" => \$config, "w|warn=s" => \$argwarn, "c|crit=s" => \$argcrit ); usage() unless (($config) && ($argwarn) && ($argcrit)); @mount = `\`which mount\``; open(CONFIG, "$config") || die("cannot open $config\n"); while ($line = ) { chomp($line); if ($line !~ /^\//) { next; } ($fs, $warn, $crit) = split(/[,]+/, $line); if (grep(/$fs/, @mount)) { ($line !~ /%/) && (($warn = "$argwarn") && ($crit = "$argcrit")); $tmplist = "-w $warn -c $crit -p $fs"; $list = "$list" . " $tmplist"; } } close(CONFIG); if ($list !~ /\//) { print "OK - $config does not include accesible filesystems\n"; exit 0; } exec("$check_disk -e $list");